Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63a3a677fe | ||
|
|
889f806fb9 | ||
|
|
3faa58ce68 | ||
|
|
41f0bf4169 |
@@ -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<User> 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<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) {
|
||||
@@ -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;
|
||||
|
||||
@@ -9,24 +9,24 @@ import static ru.vtosters.lite.foaf.FoafBase.getBypassedOnlineInfo;
|
||||
|
||||
public class OnlineBypass {
|
||||
public static JSONObject setOnlineInfo(JSONObject json) throws JSONException {
|
||||
var id = json.optInt("id");
|
||||
int id = json.optInt("id");
|
||||
if (id == AccountManagerUtils.getUserId()) {
|
||||
return json;
|
||||
}
|
||||
var onlineinfo = json.optJSONObject("online_info");
|
||||
JSONObject onlineinfo = json.optJSONObject("online_info");
|
||||
if (onlineinfo != null && !onlineinfo.optBoolean("visible") && !Preferences.serverFeaturesDisable()) {
|
||||
var bypassed = getBypassedOnlineInfo(id);
|
||||
if (bypassed.optInt("last_seen", 0) != 0) {
|
||||
json.remove("online_info");
|
||||
|
||||
var online_info = new JSONObject()
|
||||
JSONObject online_info = 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"));
|
||||
|
||||
var last_seen = new JSONObject()
|
||||
JSONObject last_seen = new JSONObject()
|
||||
.put("platform", bypassed.optInt("platform"))
|
||||
.put("time", bypassed.optInt("last_seen"));
|
||||
|
||||
@@ -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"));
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return profiles;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<com.vtosters.lite.ui.MaterialSwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="batchmessages"
|
||||
android:summary="Поможет исправить показ онлайна в чатах, но возможны проблемы с загрузкой сообщений в целом"
|
||||
android:summary="Поможет исправить скорость загрузки сообщений, но работает нестабильно"
|
||||
android:title="Альтернативная загрузка сообщений"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/vtverify">
|
||||
|
||||
@@ -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
|
||||
|
||||
-4
@@ -50,10 +50,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 2
|
||||
|
||||
-3
@@ -50,9 +50,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 2
|
||||
|
||||
-4
@@ -50,10 +50,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 2
|
||||
|
||||
@@ -60,6 +60,10 @@
|
||||
|
||||
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\")"
|
||||
|
||||
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
|
||||
|
||||
invoke-static {v0}, Lru/vtosters/hooks/OnlineFormatterHook;->onlineHookProfiles(Lorg/json/JSONObject;)Lorg/json/JSONObject;
|
||||
|
||||
move-result-object v0
|
||||
|
||||
.line 3
|
||||
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/OnlineFormatterHook;->onlineHook(Lorg/json/JSONObject;)Lorg/json/JSONObject;
|
||||
|
||||
move-result-object v0
|
||||
|
||||
const-string v2, ""
|
||||
|
||||
.line 1
|
||||
|
||||
@@ -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;-><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
|
||||
|
||||
: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
|
||||
|
||||
.method public bridge synthetic a(Ljava/lang/String;)Ljava/lang/Object;
|
||||
|
||||
Reference in New Issue
Block a user