diff --git a/app/src/main/java/ru/vtosters/hooks/OnlineFormatterHook.java b/app/src/main/java/ru/vtosters/hooks/OnlineFormatterHook.java index 082bd8ca8..7e1fc3c70 100644 --- a/app/src/main/java/ru/vtosters/hooks/OnlineFormatterHook.java +++ b/app/src/main/java/ru/vtosters/hooks/OnlineFormatterHook.java @@ -1,7 +1,10 @@ package ru.vtosters.hooks; import android.util.Log; +import android.util.SparseArray; import com.vk.core.network.Network; +import com.vk.im.engine.internal.api_parsers.UserApiParser; +import com.vk.im.engine.models.users.User; import com.vtosters.lite.R; import okhttp3.Call; import okhttp3.Callback; @@ -10,8 +13,6 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import ru.vtosters.hooks.other.Preferences; -import ru.vtosters.lite.proxy.ProxyUtils; -import ru.vtosters.lite.utils.AccountManagerUtils; import ru.vtosters.lite.utils.AndroidUtils; import java.io.IOException; @@ -146,16 +147,36 @@ public class OnlineFormatterHook { return json; } - public static JSONArray onlineHookList(JSONArray jsonArr) { - if (!getBoolValue("onlinefix", false) || Preferences.serverFeaturesDisable()) return jsonArr; - + public static SparseArray onlineHookList(String str) { + JSONArray jSONArray; try { - JsonInjectors.setOnlineInfoUsers(jsonArr); - } catch (Exception e) { - Log.e("onlineHookProfiles", e.getMessage()); + jSONArray = new JSONObject(str).getJSONArray("response"); + } catch (JSONException e) { + throw new RuntimeException(e); + } + SparseArray sparseArray = new SparseArray<>(jSONArray.length()); + int length = jSONArray.length(); + + if (getBoolValue("onlinefix", false) || !Preferences.serverFeaturesDisable()) { + try { + jSONArray = JsonInjectors.setOnlineInfoUsers(jSONArray); + } catch (JSONException e) { + throw new RuntimeException(e); + } } - return jsonArr; + for (int i = 0; i < length; i++) { + JSONObject jSONObject; + try { + jSONObject = jSONArray.getJSONObject(i); + } catch (JSONException e) { + throw new RuntimeException(e); + } + User b = UserApiParser.b(jSONObject); + sparseArray.put(b.getId(), b); + } + + return sparseArray; } public static JSONObject onlineHookProfiles(JSONObject json) { @@ -188,19 +209,19 @@ public class OnlineFormatterHook { try { JsonInjectors.setOnlineInfoUsers(json.optJSONObject("read_requests").optJSONArray("items")); } catch (Exception e) { - Log.e("onlineHookItems", e.getMessage()); + Log.e("onlineHookItemsRec", e.getMessage()); } try { JsonInjectors.setOnlineInfoUsers(json.optJSONObject("recommendations").optJSONArray("items")); } catch (Exception e) { - Log.e("onlineHookItems", e.getMessage()); + Log.e("onlineHookItemsRec", e.getMessage()); } try { JsonInjectors.setOnlineInfoUsers(json.optJSONArray("profiles")); } catch (Exception e) { - Log.e("onlineHookItems", e.getMessage()); + Log.e("onlineHookItemsRec", e.getMessage()); } return json; diff --git a/app/src/main/java/ru/vtosters/lite/utils/OnlineBypass.java b/app/src/main/java/ru/vtosters/lite/utils/OnlineBypass.java index b07306477..e7a4cf32c 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/OnlineBypass.java +++ b/app/src/main/java/ru/vtosters/lite/utils/OnlineBypass.java @@ -37,51 +37,95 @@ public class OnlineBypass { return json; } - public static JSONArray setOnlineInfoUsers(JSONArray profiles) throws JSONException { - if (profiles == null || profiles.length() == 0 || Preferences.serverFeaturesDisable()) return profiles; + public static JSONArray setOnlineInfoUsers(JSONArray profiles) { + if (shouldReturnProfiles(profiles)) return profiles; + StringBuilder sb = new StringBuilder(); - var curVkId = AccountManagerUtils.getUserId(); + int curVkId = AccountManagerUtils.getUserId(); + for (int i = 0; i < profiles.length(); i++) { - JSONObject profile = profiles.getJSONObject(i); + JSONObject profile = getProfile(profiles, i); int id = profile.optInt("id", -1); JSONObject onlinfo = profile.optJSONObject("online_info"); - if (id == curVkId || id < 0 || onlinfo == null || onlinfo.optBoolean("visible")) { - continue; - } - sb.append(id); - sb.append(","); - } - var ids = sb.toString(); - if (!ids.isEmpty()) { - ids = ids.substring(0, ids.length() - 1); - } else { - return profiles; + + if (shouldSkipProfile(id, curVkId, onlinfo)) continue; + + sb.append(id).append(","); } + String ids = prepareIds(sb); + if (ids.isEmpty()) return profiles; + JSONObject bypassedObj = getBypassedOnlineInfo(ids); for (int i = 0; i < profiles.length(); i++) { - JSONObject profile = profiles.getJSONObject(i); + JSONObject profile = getProfile(profiles, i); int id = profile.optInt("id"); JSONObject bypassed = bypassedObj.optJSONObject(Integer.toString(id)); - if (bypassed == null) { - continue; - } - profile.remove("online_info"); - var online_info = new JSONObject() + if (bypassed == null) continue; + + JSONObject online_info = createOnlineInfo(bypassed); + JSONObject last_seen = createLastSeen(bypassed); + + updateProfile(profile, online_info, last_seen); + } + + return profiles; + } + + private static boolean shouldReturnProfiles(JSONArray profiles) { + return profiles == null || profiles.length() == 0 || Preferences.serverFeaturesDisable(); + } + + private static JSONObject getProfile(JSONArray profiles, int i) { + try { + return profiles.getJSONObject(i); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } + + private static boolean shouldSkipProfile(int id, int curVkId, JSONObject onlinfo) { + return id == curVkId || id < 0 || onlinfo == null || onlinfo.optBoolean("visible"); + } + + private static String prepareIds(StringBuilder sb) { + String ids = sb.toString(); + if (!ids.isEmpty()) { + ids = ids.substring(0, ids.length() - 1); + } + return ids; + } + + private static JSONObject createOnlineInfo(JSONObject bypassed) { + try { + return new JSONObject() .put("visible", true) .put("last_seen", bypassed.optInt("last_seen")) .put("is_online", bypassed.optBoolean("is_online")) .put("app_id", bypassed.optInt("app_id")) .put("is_mobile", bypassed.optBoolean("is_mobile")); + } catch (JSONException e) { + throw new RuntimeException(e); + } + } - var last_seen = new JSONObject() + private static JSONObject createLastSeen(JSONObject bypassed) { + try { + return new JSONObject() .put("platform", bypassed.optInt("platform")) .put("time", bypassed.optInt("last_seen")); - - profile.put("last_seen", last_seen).put("online_info", online_info); + } catch (JSONException e) { + throw new RuntimeException(e); } + } - return profiles; + private static void updateProfile(JSONObject profile, JSONObject online_info, JSONObject last_seen) { + try { + profile.remove("online_info"); + profile.put("last_seen", last_seen).put("online_info", online_info); + } catch (JSONException e) { + throw new RuntimeException(e); + } } } diff --git a/smali/smali_classes2/com/vk/api/account/AccountGetBanned.smali b/smali/smali_classes2/com/vk/api/account/AccountGetBanned.smali index fa89b7098..cffef1108 100644 --- a/smali/smali_classes2/com/vk/api/account/AccountGetBanned.smali +++ b/smali/smali_classes2/com/vk/api/account/AccountGetBanned.smali @@ -82,10 +82,6 @@ move-result-object p1 - invoke-static {p1}, Lru/vtosters/hooks/OnlineFormatterHook;->onlineHookProfiles(Lorg/json/JSONObject;)Lorg/json/JSONObject; - - move-result-object p1 - const-string v0, "items" .line 3 diff --git a/smali/smali_classes3/com/vk/im/engine/internal/api_commands/messages/MessagesGetConversationsApiCmd$a.smali b/smali/smali_classes3/com/vk/im/engine/internal/api_commands/messages/MessagesGetConversationsApiCmd$a.smali index 8853b8621..68b866047 100644 --- a/smali/smali_classes3/com/vk/im/engine/internal/api_commands/messages/MessagesGetConversationsApiCmd$a.smali +++ b/smali/smali_classes3/com/vk/im/engine/internal/api_commands/messages/MessagesGetConversationsApiCmd$a.smali @@ -51,6 +51,7 @@ move-result-object p1 invoke-static {p1}, Lru/vtosters/hooks/OnlineFormatterHook;->onlineHookProfiles(Lorg/json/JSONObject;)Lorg/json/JSONObject; + move-result-object p1 const-string v0, "items" diff --git a/smali/smali_classes3/com/vk/im/engine/internal/f/h/UsersGetByIdApiCmd$b.smali b/smali/smali_classes3/com/vk/im/engine/internal/f/h/UsersGetByIdApiCmd$b.smali index 94188a29e..1ecb3ba6b 100644 --- a/smali/smali_classes3/com/vk/im/engine/internal/f/h/UsersGetByIdApiCmd$b.smali +++ b/smali/smali_classes3/com/vk/im/engine/internal/f/h/UsersGetByIdApiCmd$b.smali @@ -52,79 +52,11 @@ } .end annotation - .line 2 - :try_start_0 - new-instance v0, Lorg/json/JSONObject; + invoke-static {p1}, Lru/vtosters/hooks/OnlineFormatterHook;->onlineHookList(Ljava/lang/String;)Landroid/util/SparseArray; - invoke-direct {v0, p1}, Lorg/json/JSONObject;->(Ljava/lang/String;)V + move-result-object v0 - const-string p1, "response" - - invoke-virtual {v0, p1}, Lorg/json/JSONObject;->getJSONArray(Ljava/lang/String;)Lorg/json/JSONArray; - - move-result-object p1 - - invoke-static {p1}, Lru/vtosters/hooks/OnlineFormatterHook;->onlineHookList(Lorg/json/JSONArray;)Lorg/json/JSONArray; - - move-result-object p1 - - .line 3 - new-instance v0, Landroid/util/SparseArray; - - invoke-virtual {p1}, Lorg/json/JSONArray;->length()I - - move-result v1 - - invoke-direct {v0, v1}, Landroid/util/SparseArray;->(I)V - - const/4 v1, 0x0 - - .line 4 - invoke-virtual {p1}, Lorg/json/JSONArray;->length()I - - move-result v2 - - :goto_0 - if-ge v1, v2, :cond_0 - - .line 5 - invoke-virtual {p1, v1}, Lorg/json/JSONArray;->getJSONObject(I)Lorg/json/JSONObject; - - move-result-object v3 - - const-string v4, "ja.getJSONObject(i)" - - invoke-static {v3, v4}, Lkotlin/jvm/internal/Intrinsics;->a(Ljava/lang/Object;Ljava/lang/String;)V - - invoke-static {v3}, Lcom/vk/im/engine/internal/api_parsers/UserApiParser;->b(Lorg/json/JSONObject;)Lcom/vk/im/engine/models/users/User; - - move-result-object v3 - - .line 6 - invoke-virtual {v3}, Lcom/vk/im/engine/models/users/User;->getId()I - - move-result v4 - - invoke-virtual {v0, v4, v3}, Landroid/util/SparseArray;->put(ILjava/lang/Object;)V - :try_end_0 - .catch Lorg/json/JSONException; {:try_start_0 .. :try_end_0} :catch_0 - - add-int/lit8 v1, v1, 0x1 - - goto :goto_0 - - :cond_0 return-object v0 - - :catch_0 - move-exception p1 - - .line 7 - new-instance v0, Lcom/vk/api/sdk/exceptions/VKApiIllegalResponseException; - - invoke-direct {v0, p1}, Lcom/vk/api/sdk/exceptions/VKApiIllegalResponseException;->(Ljava/lang/Throwable;)V - - throw v0 .end method .method public bridge synthetic a(Ljava/lang/String;)Ljava/lang/Object;