Compare commits

...
Author SHA1 Message Date
gdlbo 63a3a677fe Update preferences_other.xml 2024-03-21 21:39:28 +03:00
gdlbo 889f806fb9 Update UserApiParser.smali 2024-03-21 21:38:08 +03:00
gdlbo 3faa58ce68 idk 2024-03-21 21:33:12 +03:00
gdlbo 41f0bf4169 init 2024-03-21 21:01:09 +03:00
10 changed files with 121 additions and 127 deletions
@@ -1,7 +1,10 @@
package ru.vtosters.hooks; package ru.vtosters.hooks;
import android.util.Log; import android.util.Log;
import android.util.SparseArray;
import com.vk.core.network.Network; 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 com.vtosters.lite.R;
import okhttp3.Call; import okhttp3.Call;
import okhttp3.Callback; import okhttp3.Callback;
@@ -10,8 +13,6 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import ru.vtosters.hooks.other.Preferences; 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 ru.vtosters.lite.utils.AndroidUtils;
import java.io.IOException; import java.io.IOException;
@@ -146,16 +147,36 @@ public class OnlineFormatterHook {
return json; return json;
} }
public static JSONArray onlineHookList(JSONArray jsonArr) { public static SparseArray<User> onlineHookList(String str) {
if (!getBoolValue("onlinefix", false) || Preferences.serverFeaturesDisable()) return jsonArr; JSONArray jSONArray;
try { try {
JsonInjectors.setOnlineInfoUsers(jsonArr); jSONArray = new JSONObject(str).getJSONArray("response");
} catch (Exception e) { } catch (JSONException e) {
Log.e("onlineHookProfiles", e.getMessage()); throw new RuntimeException(e);
}
SparseArray<User> 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) { public static JSONObject onlineHookProfiles(JSONObject json) {
@@ -188,19 +209,19 @@ public class OnlineFormatterHook {
try { try {
JsonInjectors.setOnlineInfoUsers(json.optJSONObject("read_requests").optJSONArray("items")); JsonInjectors.setOnlineInfoUsers(json.optJSONObject("read_requests").optJSONArray("items"));
} catch (Exception e) { } catch (Exception e) {
Log.e("onlineHookItems", e.getMessage()); Log.e("onlineHookItemsRec", e.getMessage());
} }
try { try {
JsonInjectors.setOnlineInfoUsers(json.optJSONObject("recommendations").optJSONArray("items")); JsonInjectors.setOnlineInfoUsers(json.optJSONObject("recommendations").optJSONArray("items"));
} catch (Exception e) { } catch (Exception e) {
Log.e("onlineHookItems", e.getMessage()); Log.e("onlineHookItemsRec", e.getMessage());
} }
try { try {
JsonInjectors.setOnlineInfoUsers(json.optJSONArray("profiles")); JsonInjectors.setOnlineInfoUsers(json.optJSONArray("profiles"));
} catch (Exception e) { } catch (Exception e) {
Log.e("onlineHookItems", e.getMessage()); Log.e("onlineHookItemsRec", e.getMessage());
} }
return json; return json;
@@ -9,24 +9,24 @@ import static ru.vtosters.lite.foaf.FoafBase.getBypassedOnlineInfo;
public class OnlineBypass { public class OnlineBypass {
public static JSONObject setOnlineInfo(JSONObject json) throws JSONException { public static JSONObject setOnlineInfo(JSONObject json) throws JSONException {
var id = json.optInt("id"); int id = json.optInt("id");
if (id == AccountManagerUtils.getUserId()) { if (id == AccountManagerUtils.getUserId()) {
return json; return json;
} }
var onlineinfo = json.optJSONObject("online_info"); JSONObject onlineinfo = json.optJSONObject("online_info");
if (onlineinfo != null && !onlineinfo.optBoolean("visible") && !Preferences.serverFeaturesDisable()) { if (onlineinfo != null && !onlineinfo.optBoolean("visible") && !Preferences.serverFeaturesDisable()) {
var bypassed = getBypassedOnlineInfo(id); var bypassed = getBypassedOnlineInfo(id);
if (bypassed.optInt("last_seen", 0) != 0) { if (bypassed.optInt("last_seen", 0) != 0) {
json.remove("online_info"); json.remove("online_info");
var online_info = new JSONObject() JSONObject online_info = new JSONObject()
.put("visible", true) .put("visible", true)
.put("last_seen", bypassed.optInt("last_seen")) .put("last_seen", bypassed.optInt("last_seen"))
.put("is_online", bypassed.optBoolean("is_online")) .put("is_online", bypassed.optBoolean("is_online"))
.put("app_id", bypassed.optInt("app_id")) .put("app_id", bypassed.optInt("app_id"))
.put("is_mobile", bypassed.optBoolean("is_mobile")); .put("is_mobile", bypassed.optBoolean("is_mobile"));
var last_seen = new JSONObject() JSONObject last_seen = new JSONObject()
.put("platform", bypassed.optInt("platform")) .put("platform", bypassed.optInt("platform"))
.put("time", bypassed.optInt("last_seen")); .put("time", bypassed.optInt("last_seen"));
@@ -37,51 +37,95 @@ public class OnlineBypass {
return json; return json;
} }
public static JSONArray setOnlineInfoUsers(JSONArray profiles) throws JSONException { public static JSONArray setOnlineInfoUsers(JSONArray profiles) {
if (profiles == null || profiles.length() == 0 || Preferences.serverFeaturesDisable()) return profiles; if (shouldReturnProfiles(profiles)) return profiles;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
var curVkId = AccountManagerUtils.getUserId(); int curVkId = AccountManagerUtils.getUserId();
for (int i = 0; i < profiles.length(); i++) { for (int i = 0; i < profiles.length(); i++) {
JSONObject profile = profiles.getJSONObject(i); JSONObject profile = getProfile(profiles, i);
int id = profile.optInt("id", -1); int id = profile.optInt("id", -1);
JSONObject onlinfo = profile.optJSONObject("online_info"); JSONObject onlinfo = profile.optJSONObject("online_info");
if (id == curVkId || id < 0 || onlinfo == null || onlinfo.optBoolean("visible")) {
continue; if (shouldSkipProfile(id, curVkId, onlinfo)) continue;
}
sb.append(id); sb.append(id).append(",");
sb.append(",");
}
var ids = sb.toString();
if (!ids.isEmpty()) {
ids = ids.substring(0, ids.length() - 1);
} else {
return profiles;
} }
String ids = prepareIds(sb);
if (ids.isEmpty()) return profiles;
JSONObject bypassedObj = getBypassedOnlineInfo(ids); JSONObject bypassedObj = getBypassedOnlineInfo(ids);
for (int i = 0; i < profiles.length(); i++) { for (int i = 0; i < profiles.length(); i++) {
JSONObject profile = profiles.getJSONObject(i); JSONObject profile = getProfile(profiles, i);
int id = profile.optInt("id"); int id = profile.optInt("id");
JSONObject bypassed = bypassedObj.optJSONObject(Integer.toString(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("visible", true)
.put("last_seen", bypassed.optInt("last_seen")) .put("last_seen", bypassed.optInt("last_seen"))
.put("is_online", bypassed.optBoolean("is_online")) .put("is_online", bypassed.optBoolean("is_online"))
.put("app_id", bypassed.optInt("app_id")) .put("app_id", bypassed.optInt("app_id"))
.put("is_mobile", bypassed.optBoolean("is_mobile")); .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("platform", bypassed.optInt("platform"))
.put("time", bypassed.optInt("last_seen")); .put("time", bypassed.optInt("last_seen"));
} catch (JSONException e) {
profile.put("last_seen", last_seen).put("online_info", online_info); 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);
}
} }
} }
+1 -1
View File
@@ -11,7 +11,7 @@
<com.vtosters.lite.ui.MaterialSwitchPreference <com.vtosters.lite.ui.MaterialSwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="batchmessages" android:key="batchmessages"
android:summary="Поможет исправить показ онлайна в чатах, но возможны проблемы с загрузкой сообщений в целом" android:summary="Поможет исправить скорость загрузки сообщений, но работает нестабильно"
android:title="Альтернативная загрузка сообщений"/> android:title="Альтернативная загрузка сообщений"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/vtverify"> <PreferenceCategory android:title="@string/vtverify">
@@ -82,10 +82,6 @@
move-result-object p1 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" const-string v0, "items"
.line 3 .line 3
@@ -50,10 +50,6 @@
move-result-object p1 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" const-string v0, "items"
.line 2 .line 2
@@ -50,9 +50,6 @@
move-result-object p1 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" const-string v0, "items"
.line 2 .line 2
@@ -50,10 +50,6 @@
move-result-object p1 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" const-string v0, "items"
.line 2 .line 2
@@ -60,6 +60,10 @@
move-result-object p1 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, "JSONObject(response).getJSONObject(\"response\")" const-string v0, "JSONObject(response).getJSONObject(\"response\")"
invoke-static {p1, v0}, Lkotlin/jvm/internal/Intrinsics;->a(Ljava/lang/Object;Ljava/lang/String;)V invoke-static {p1, v0}, Lkotlin/jvm/internal/Intrinsics;->a(Ljava/lang/Object;Ljava/lang/String;)V
@@ -76,6 +80,10 @@
move-object/from16 v0, p1 move-object/from16 v0, p1
invoke-static {v0}, Lru/vtosters/hooks/OnlineFormatterHook;->onlineHookProfiles(Lorg/json/JSONObject;)Lorg/json/JSONObject;
move-result-object v0
.line 3 .line 3
new-instance v1, Lcom/vk/im/engine/models/ProfilesSimpleInfo; new-instance v1, Lcom/vk/im/engine/models/ProfilesSimpleInfo;
@@ -164,6 +164,10 @@
invoke-static {v0}, Lru/vtosters/hooks/RenameHook;->injectIntoJson(Lorg/json/JSONObject;)V invoke-static {v0}, Lru/vtosters/hooks/RenameHook;->injectIntoJson(Lorg/json/JSONObject;)V
invoke-static {v0}, Lru/vtosters/hooks/OnlineFormatterHook;->onlineHook(Lorg/json/JSONObject;)Lorg/json/JSONObject;
move-result-object v0
const-string v2, "" const-string v2, ""
.line 1 .line 1
@@ -52,79 +52,11 @@
} }
.end annotation .end annotation
.line 2 invoke-static {p1}, Lru/vtosters/hooks/OnlineFormatterHook;->onlineHookList(Ljava/lang/String;)Landroid/util/SparseArray;
:try_start_0
new-instance v0, Lorg/json/JSONObject;
invoke-direct {v0, p1}, Lorg/json/JSONObject;-><init>(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;-><init>(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 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;-><init>(Ljava/lang/Throwable;)V
throw v0
.end method .end method
.method public bridge synthetic a(Ljava/lang/String;)Ljava/lang/Object; .method public bridge synthetic a(Ljava/lang/String;)Ljava/lang/Object;