improved online hooks

This commit is contained in:
spiky-s
2022-08-18 22:13:11 +03:00
committed by gdlbo
parent f9657af36c
commit 341a368656
2 changed files with 120 additions and 16 deletions
@@ -1,6 +1,8 @@
package ru.vtosters.lite.hooks;
import static ru.vtosters.lite.foaf.FoafBase.getLastSeen;
import static ru.vtosters.lite.foaf.FoafBase.getBypassedOnlineInfo;
import static ru.vtosters.lite.hooks.OnlineFormatterHook.onlineHookProfiles;
import static ru.vtosters.lite.hooks.DateHook.getLocale;
import static ru.vtosters.lite.utils.AndroidUtils.getDefaultPrefs;
import static ru.vtosters.lite.utils.Base64Utils.decode;
@@ -271,29 +273,82 @@ public class JsonInjectors {
public static JSONObject setOnlineInfo(JSONObject json) throws ParseException, IOException, JSONException {
var id = json.optInt("id");
if (id == AccountManagerUtils.getUserId()) {
return json;
}
var onlineinfo = json.optJSONObject("online_info");
var time = getLastSeen(0L, id);
if (onlineinfo != null && !onlineinfo.optBoolean("visible")) {
var bypassed = getBypassedOnlineInfo(id);
if (bypassed.optInt("last_seen", 0) != 0) {
json.remove("online_info");
if (time != 0L && onlineinfo != null && !onlineinfo.optBoolean("is_online") && id != AccountManagerUtils.getUserId()) {
json.remove("online_info");
var 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 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", bypassed.optInt("platform"))
.put("time", bypassed.optInt("last_seen"));
var last_seen = new JSONObject()
.put("platform", 4)
.put("time", time);
json.put("last_seen", last_seen).put("online_info", online_info);
json.put("last_seen", last_seen).put("online_info", online_info);
}
}
return json;
}
public static JSONArray setOnlineInfoUsers(JSONArray profiles) throws ParseException, IOException, JSONException {
if (profiles == null || profiles.length() == 0) return profiles;
StringBuilder sb = new StringBuilder();
var curVkId = AccountManagerUtils.getUserId();
for (int i=0; i < profiles.length(); i++) {
JSONObject profile = profiles.getJSONObject(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.length() > 0) {
ids = ids.substring(0, ids.length() - 1);
} else {
return profiles;
}
JSONObject bypassedObj = getBypassedOnlineInfo(ids);
for (int i=0; i < profiles.length(); i++) {
JSONObject profile = profiles.getJSONObject(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()
.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()
.put("platform", bypassed.optInt("platform"))
.put("time", bypassed.optInt("last_seen"));
profile.put("last_seen", last_seen).put("online_info", online_info);
}
return profiles;
}
public static JSONObject storiesads(JSONObject json, boolean isDeleteFix) throws JSONException {
if (!adsstories()) {
return json;
@@ -612,8 +667,8 @@ public class JsonInjectors {
return null;
}
public static JSONObject friends(JSONObject json) throws JSONException {
JSONObject catalog = json;
public static JSONObject friends(JSONObject json) throws JSONException, ParseException, IOException {
JSONObject catalog = onlineHookProfiles(json);
boolean sectionexecute = true;
boolean hasBirthday = false;
@@ -1,6 +1,7 @@
package ru.vtosters.lite.hooks;
import static ru.vtosters.lite.hooks.JsonInjectors.setOnlineInfo;
import static ru.vtosters.lite.hooks.JsonInjectors.setOnlineInfoUsers;
import static ru.vtosters.lite.net.Request.makeRequest;
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
import static ru.vtosters.lite.utils.AndroidUtils.getString;
@@ -10,6 +11,8 @@ import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import static ru.vtosters.lite.utils.Preferences.getPrefsFromFile;
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -177,5 +180,51 @@ public class OnlineFormatterHook {
setOnlineInfo(json);
return json;
}
public static JSONObject onlineHookProfiles(JSONObject json) throws ParseException, IOException, JSONException {
if (!getBoolValue("onlinefix", false)) return json;
Log.d("test", json.toString());
try {
setOnlineInfoUsers(json.optJSONArray("profiles"));
} catch (Exception e) {
Log.e("onlineHookProfiles", e.getMessage());
}
return json;
}
public static JSONObject onlineHookItems(JSONObject json) throws ParseException, IOException, JSONException {
if (!getBoolValue("onlinefix", false)) return json;
try {
setOnlineInfoUsers(json.optJSONArray("items"));
} catch (Exception e) {
Log.e("onlineHookItems", e.getMessage());
}
return json;
}
public static JSONObject onlineHookRequestsAndRecommendations(JSONObject json) throws ParseException, IOException, JSONException {
if (!getBoolValue("onlinefix", false)) return json;
try {
setOnlineInfoUsers(json.optJSONObject("read_requests").optJSONArray("items"));
} catch (Exception e) {
Log.e("onlineHookItems", e.getMessage());
}
try {
setOnlineInfoUsers(json.optJSONObject("recommendations").optJSONArray("items"));
} catch (Exception e) {
Log.e("onlineHookItems", e.getMessage());
}
try {
setOnlineInfoUsers(json.optJSONArray("profiles"));
} catch (Exception e) {
Log.e("onlineHookItems", e.getMessage());
}
return json;
}
}