From 8756cd1f2005e8171941b9b3c7e651813cde1f35 Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Sat, 23 Jul 2022 21:36:37 +0300 Subject: [PATCH] foaf online --- .../java/ru/vtosters/lite/foaf/FoafBase.java | 31 +++++++--- .../ru/vtosters/lite/hooks/JsonInjectors.java | 61 ++++++++++--------- .../lite/hooks/OnlineFormatterHook.java | 18 ++++++ .../ru/vtosters/lite/utils/Preferences.java | 4 +- smali/res/xml/preferences_activity.xml | 12 ++++ smali/res/xml/preferences_messages.xml | 6 -- .../com/vk/dto/user/UserProfile.smali | 6 ++ .../internal/api_parsers/UserApiParser.smali | 6 ++ .../lite/api/execute/GetFullUserProfile.smali | 6 ++ 9 files changed, 105 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/ru/vtosters/lite/foaf/FoafBase.java b/app/src/main/java/ru/vtosters/lite/foaf/FoafBase.java index f2af90bbf..d690cd700 100644 --- a/app/src/main/java/ru/vtosters/lite/foaf/FoafBase.java +++ b/app/src/main/java/ru/vtosters/lite/foaf/FoafBase.java @@ -9,23 +9,26 @@ import static ru.vtosters.lite.utils.Proxy.getApi; import android.app.ProgressDialog; import android.content.Context; +import android.util.Log; import androidx.exifinterface.media.ExifInterface; import com.vk.core.dialogs.alert.VkAlertDialog; +import com.vk.core.network.Network; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import java.util.TimeZone; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; +import okhttp3.Headers; import okhttp3.OkHttpClient; import ru.vtosters.lite.net.Request; -import ru.vtosters.lite.utils.Preferences; public class FoafBase{ private static final Pattern FOAF_REGEX = Pattern.compile(""); @@ -34,16 +37,30 @@ public class FoafBase{ private static final OkHttpClient client = new OkHttpClient(); public static long getLastSeen(long origtime, int id) throws ParseException, IOException{ - if (!Preferences.foaf()) return origtime; + var request = new okhttp3.Request.a() + .b(getLink(id)) + .a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8")).a(); + + String response = null; + + try { + response = client.a(request).execute().a().g(); + } catch (IOException e) { + Log.e("FoafBase", e.getMessage()); + } + + Matcher matcher = FOAF_REGEX_LAST_SEEN.matcher(response); - Matcher matcher = FOAF_REGEX_LAST_SEEN.matcher( - client.a( - new okhttp3.Request.a().a(getLink(id)).b().a() - ).execute().a().g()); if (!matcher.find()) { return origtime; } - return new SimpleDateFormat("yyyy-MM-dd'T'kk:mm:ss", Locale.getDefault()).parse(matcher.group(1)).getTime() / 1000; + + var tz = TimeZone.getDefault(); + var smf = new SimpleDateFormat("yyyy-MM-dd'T'kk:mm:ss", Locale.getDefault()); + + smf.setTimeZone(tz); + + return smf.parse(matcher.group(1)).getTime() / 1000; } private static String getLink(int i){ diff --git a/app/src/main/java/ru/vtosters/lite/hooks/JsonInjectors.java b/app/src/main/java/ru/vtosters/lite/hooks/JsonInjectors.java index 04b6aafc8..4b278e713 100644 --- a/app/src/main/java/ru/vtosters/lite/hooks/JsonInjectors.java +++ b/app/src/main/java/ru/vtosters/lite/hooks/JsonInjectors.java @@ -43,10 +43,10 @@ import okhttp3.Request; import ru.vtosters.lite.utils.Globals; import ru.vtosters.lite.utils.Newsfeed; -public class JsonInjectors { +public class JsonInjectors{ private static final OkHttpClient mClient = new OkHttpClient(); - public static JSONObject profileButton(JSONObject orig) throws JSONException { + public static JSONObject profileButton(JSONObject orig) throws JSONException{ if (haveDonateButton()) return orig; var pic = "https://sun1-18.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png"; @@ -65,7 +65,7 @@ public class JsonInjectors { + text_color + decode("In0=")); } - public static JSONObject convBar(JSONObject orig) throws JSONException { + public static JSONObject convBar(JSONObject orig) throws JSONException{ var peerid = Objects.requireNonNull(orig.optJSONObject("peer")).optInt("id"); var pic = "https://image.pngaaa.com/641/326641-middle.png"; // can be null @@ -107,7 +107,7 @@ public class JsonInjectors { + decode("fQ==")); } - public static JSONObject menu(JSONObject orig) throws JSONException { + public static JSONObject menu(JSONObject orig) throws JSONException{ var Special = orig.optJSONArray("special"); var Main = orig.getJSONArray("main"); var Other = orig.optJSONArray("other"); @@ -119,7 +119,7 @@ public class JsonInjectors { return orig; } - public static JSONObject superapp(JSONObject json) throws JSONException { + public static JSONObject superapp(JSONObject json) throws JSONException{ var superApps = Globals.getPreferences().getString("superapp_items", "menu,promo,miniapps,vkpay_slim,greeting,holiday,weather,sport,games,informer,food,event,music,vk_run").split(","); if (superApps.length == 0) return json; @@ -148,7 +148,7 @@ public class JsonInjectors { return json.putOpt("items", newItems); } - public static JSONObject musiclink(JSONObject json) { + public static JSONObject musiclink(JSONObject json){ var oldItems = json.optJSONArray("links"); if (oldItems != null) { @@ -161,31 +161,32 @@ public class JsonInjectors { return json; } - public static JSONObject onlineinfo(JSONObject json) throws ParseException, IOException, JSONException { + public static JSONObject setOnlineInfo(JSONObject json) throws ParseException, IOException, JSONException{ var id = json.optInt("id"); var onlineinfo = json.optJSONObject("online_info"); var time = getLastSeen(0L, id); - if (time == 0L) { - return json; + if (time != 0L && onlineinfo != null && !onlineinfo.optBoolean("is_online")) { + json.remove("online_info"); + + var online_info = new JSONObject() + .put("visible", true) + .put("last_seen", time) + .put("is_online", false) + .put("app_id", 0) + .put("is_mobile", false); + + var last_seen = new JSONObject() + .put("platform", 4) + .put("time", time); + + json.put("last_seen", last_seen).put("online_info", online_info); } - onlineinfo.put("last_seen", time); - onlineinfo.put("visible", true); - onlineinfo.put("app_id", 0); - onlineinfo.put("is_online", false); - onlineinfo.put("is_mobile", false); - onlineinfo.remove("status"); - - var last_seen = new JSONObject(); - last_seen.put("time", time); - last_seen.put("platform", 0); - json.put("last_seen", last_seen); - return json; } - public static JSONObject storiesads(JSONObject json, boolean isDeleteFix) throws JSONException { + public static JSONObject storiesads(JSONObject json, boolean isDeleteFix) throws JSONException{ if (!adsstories()) { return json; } @@ -219,7 +220,7 @@ public class JsonInjectors { return json; } - private static void parseStoriesItem(JSONObject item) throws JSONException { + private static void parseStoriesItem(JSONObject item) throws JSONException{ var stories = item.optJSONArray("stories"); var newStories = new JSONArray(); @@ -239,7 +240,7 @@ public class JsonInjectors { item.put("stories", newStories); } - public static Boolean isAds(JSONObject list, String type) throws JSONException { + public static Boolean isAds(JSONObject list, String type) throws JSONException{ if (list == null || type == null || !ads()) return false; if (list.has("ads") @@ -265,7 +266,7 @@ public class JsonInjectors { return false; } - public static JSONArray newsfeedlist(JSONArray items) throws JSONException { + public static JSONArray newsfeedlist(JSONArray items) throws JSONException{ for (int j = 0; j < items.length(); j++) { var list = items.optJSONObject(j); var name = list.optString("id"); @@ -279,7 +280,7 @@ public class JsonInjectors { return items; } - public static JSONArray newsfeedadtest(JSONArray items) throws JSONException { + public static JSONArray newsfeedadtest(JSONArray items) throws JSONException{ if (!getBoolValue("newadblock", true)) return items; var newItems = new JSONArray(); @@ -349,7 +350,7 @@ public class JsonInjectors { return newItems; } - public static JSONObject music(JSONObject json) throws JSONException { + public static JSONObject music(JSONObject json) throws JSONException{ var catalog = json.optJSONObject("catalog"); JSONArray oldItems = null; @@ -417,7 +418,7 @@ public class JsonInjectors { return json; } - public static JSONObject fetchCatalogId(String section) { + public static JSONObject fetchCatalogId(String section){ if (section == null) return null; var request = new Request.a() @@ -443,7 +444,7 @@ public class JsonInjectors { return null; } - public static JSONObject friends(JSONObject json) throws JSONException { + public static JSONObject friends(JSONObject json) throws JSONException{ JSONObject catalog = json; boolean sectionexecute = true; boolean hasBirthday = false; @@ -510,7 +511,7 @@ public class JsonInjectors { } - public static boolean haveDonateButton() { + public static boolean haveDonateButton(){ int randomshower = new Random().nextInt(6); return hasVerification() || randomshower != 1; diff --git a/app/src/main/java/ru/vtosters/lite/hooks/OnlineFormatterHook.java b/app/src/main/java/ru/vtosters/lite/hooks/OnlineFormatterHook.java index fd25f87db..3663f3e9a 100644 --- a/app/src/main/java/ru/vtosters/lite/hooks/OnlineFormatterHook.java +++ b/app/src/main/java/ru/vtosters/lite/hooks/OnlineFormatterHook.java @@ -1,6 +1,8 @@ package ru.vtosters.lite.hooks; +import static ru.vtosters.lite.hooks.JsonInjectors.setOnlineInfo; import static ru.vtosters.lite.net.Request.makeRequest; import static ru.vtosters.lite.utils.Globals.getString; +import static ru.vtosters.lite.utils.Globals.getUserId; import static ru.vtosters.lite.utils.Globals.getUserToken; import static ru.vtosters.lite.utils.Globals.sendToast; import static ru.vtosters.lite.utils.Preferences.dev; @@ -8,10 +10,15 @@ import static ru.vtosters.lite.utils.Preferences.getBoolValue; import static ru.vtosters.lite.utils.Preferences.getPrefsFromFile; import static ru.vtosters.lite.utils.Proxy.getApi; +import android.util.Log; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import java.io.IOException; +import java.text.ParseException; + public class OnlineFormatterHook{ private static String AppName; @@ -159,5 +166,16 @@ public class OnlineFormatterHook{ return getString("custom_online") + " " + appname; } + + public static JSONObject onlineHook(JSONObject json, boolean isGlobalHook) throws ParseException, IOException, JSONException{ + if (!getBoolValue("onlinefix", false)) return json; + + if (isGlobalHook && !getBoolValue("globalUsersOnline", false)) { + return json; + } + + setOnlineInfo(json); + return json; + } } diff --git a/app/src/main/java/ru/vtosters/lite/utils/Preferences.java b/app/src/main/java/ru/vtosters/lite/utils/Preferences.java index 4c361ad89..3e398899f 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/Preferences.java +++ b/app/src/main/java/ru/vtosters/lite/utils/Preferences.java @@ -158,8 +158,8 @@ public class Preferences{ return getBoolValue("calls", false); } - public static boolean convUsersOnline(){ - return getBoolValue("convUsersOnline", false); + public static boolean globalUsersOnline(){ + return getBoolValue("globalUsersOnline", false); } public static boolean dev(){ diff --git a/smali/res/xml/preferences_activity.xml b/smali/res/xml/preferences_activity.xml index 1ffa69fc5..448be0dbf 100644 --- a/smali/res/xml/preferences_activity.xml +++ b/smali/res/xml/preferences_activity.xml @@ -91,6 +91,18 @@ android:key="listen_v" android:title="Отключить статус прослушивания" /> + + + + - \ No newline at end of file diff --git a/smali/smali_classes2/com/vk/dto/user/UserProfile.smali b/smali/smali_classes2/com/vk/dto/user/UserProfile.smali index 98426b373..7dfa04af8 100644 --- a/smali/smali_classes2/com/vk/dto/user/UserProfile.smali +++ b/smali/smali_classes2/com/vk/dto/user/UserProfile.smali @@ -2928,6 +2928,12 @@ .method public static d(Lorg/json/JSONObject;)Lcom/vk/dto/user/OnlineInfo; .locals 12 + const v2, 0x1 + + invoke-static {p0, v2}, Lru/vtosters/lite/hooks/OnlineFormatterHook;->onlineHook(Lorg/json/JSONObject;Z)Lorg/json/JSONObject; + + move-result-object p0 + .line 1 sget-object v0, Lcom/vk/dto/user/VisibleStatus;->e:Lcom/vk/dto/user/VisibleStatus; diff --git a/smali/smali_classes3/com/vk/im/engine/internal/api_parsers/UserApiParser.smali b/smali/smali_classes3/com/vk/im/engine/internal/api_parsers/UserApiParser.smali index c1055a60c..7a94125d3 100644 --- a/smali/smali_classes3/com/vk/im/engine/internal/api_parsers/UserApiParser.smali +++ b/smali/smali_classes3/com/vk/im/engine/internal/api_parsers/UserApiParser.smali @@ -666,6 +666,12 @@ .method private final d(Lorg/json/JSONObject;)Lcom/vk/dto/user/OnlineInfo; .locals 7 + const v2, 0x1 + + invoke-static {p1, v2}, Lru/vtosters/lite/hooks/OnlineFormatterHook;->onlineHook(Lorg/json/JSONObject;Z)Lorg/json/JSONObject; + + move-result-object p1 + const-string v0, "online_info" .line 1 diff --git a/smali/smali_classes4/com/vtosters/lite/api/execute/GetFullUserProfile.smali b/smali/smali_classes4/com/vtosters/lite/api/execute/GetFullUserProfile.smali index e550ea0b6..378c2f794 100644 --- a/smali/smali_classes4/com/vtosters/lite/api/execute/GetFullUserProfile.smali +++ b/smali/smali_classes4/com/vtosters/lite/api/execute/GetFullUserProfile.smali @@ -133,6 +133,12 @@ move-object/from16 v1, p2 + const v2, 0x0 + + invoke-static {v1, v2}, Lru/vtosters/lite/hooks/OnlineFormatterHook;->onlineHook(Lorg/json/JSONObject;Z)Lorg/json/JSONObject; + + move-result-object v1 + .line 2 iget-object v2, v0, Lcom/vtosters/lite/api/ExtendedUserProfile;->a:Lcom/vk/dto/user/UserProfile;