Skip to content

Commit

Permalink
Update Anti-Recall
Browse files Browse the repository at this point in the history
  • Loading branch information
Nep-Timeline committed Jul 10, 2023
1 parent a6c2d8d commit e07a49d
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "nep.timeline.re_telegram"
minSdk 26
targetSdk 33
versionCode 1
versionName "1.3"
versionCode 2
versionName "2.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/nep/timeline/re_telegram/HookInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class HookInit implements IXposedHookLoadPackage, IXposedHookZygoteInit,
"nekox.messenger");
private static String MODULE_PATH = null;
public static final boolean DEBUG_MODE = true;
public static final boolean LITE_MODE = true;

public final List<String> getHookPackages()
{
Expand Down
90 changes: 77 additions & 13 deletions app/src/main/java/nep/timeline/re_telegram/features/AntiRecall.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

public class AntiRecall {
private static final List<DeletedMessageInfo> deletedMessagesIds = new ArrayList<>();
private static final List<DeletedMessageInfo> needProcessing = new ArrayList<>();

public static List<DeletedMessageInfo> getDeletedMessagesIds() {
return deletedMessagesIds;
Expand All @@ -45,6 +46,18 @@ public static boolean messageIsDeleted(int messageId) {
return deleted; // deletedMessagesIds.contains(messageId);
}

public static boolean findInNeedProcess(int messageId) {
boolean deleted = false;
for (DeletedMessageInfo deletedMessagesId : needProcessing) {
if (deletedMessagesId.getSelectedAccount() == UserConfig.getSelectedAccount() && deletedMessagesId.getMessageIds().contains(messageId))
{
deleted = true;
break;
}
}
return deleted; // deletedMessagesIds.contains(messageId);
}

public static void insertDeletedMessage(ArrayList<Integer> messageIds) {
boolean needInit = true;
DeletedMessageInfo info = null;
Expand All @@ -67,6 +80,49 @@ public static void insertDeletedMessage(ArrayList<Integer> messageIds) {
Utils.saveDeletedMessages();
}

public static void insertDeletedMessage(DeletedMessageInfo messageInfo) {
boolean needInit = true;
DeletedMessageInfo info = null;
for (DeletedMessageInfo deletedMessagesId : deletedMessagesIds) {
if (deletedMessagesId.getSelectedAccount() == messageInfo.getSelectedAccount())
{
info = deletedMessagesId;
needInit = false;
break;
}
}
if (needInit)
deletedMessagesIds.add(new DeletedMessageInfo(messageInfo.getSelectedAccount(), messageInfo.getMessageIds()));
else
{
for (Integer messageId : messageInfo.getMessageIds())
if (!info.getMessageIds().contains(messageId)) // No duplication
info.insertMessageIds(messageInfo.getMessageIds());
}
Utils.saveDeletedMessages();
}

public static void insertNeedProcessDeletedMessage(ArrayList<Integer> messageIds) {
boolean needInit = true;
DeletedMessageInfo info = null;
for (DeletedMessageInfo deletedMessagesId : needProcessing) {
if (deletedMessagesId.getSelectedAccount() == UserConfig.getSelectedAccount())
{
info = deletedMessagesId;
needInit = false;
break;
}
}
if (needInit)
needProcessing.add(new DeletedMessageInfo(UserConfig.getSelectedAccount(), messageIds));
else
{
for (Integer messageId : messageIds)
if (!info.getMessageIds().contains(messageId)) // No duplication
info.insertMessageIds(messageIds);
}
}

public static void insertDeletedMessageFromSaveFile(int selectedAccount, ArrayList<Integer> messageIds) {
boolean needInit = true;
DeletedMessageInfo info = null;
Expand Down Expand Up @@ -188,22 +244,27 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (updates != null && !updates.isEmpty()) {
ArrayList<Object> newUpdates = new ArrayList<>();

for (Object item : updates)
if (!item.getClass().equals(TL_updateDeleteChannelMessages) && !item.getClass().equals(TL_updateDeleteMessages))// && !item.getClass().equals(TL_updateDeleteScheduledMessages))
for (Object item : updates) {
if (!HookInit.LITE_MODE)
{
if (!item.getClass().equals(TL_updateDeleteChannelMessages) && !item.getClass().equals(TL_updateDeleteMessages))// && !item.getClass().equals(TL_updateDeleteScheduledMessages))
newUpdates.add(item);
}
else
newUpdates.add(item);
else {
//if (item.getClass().equals(TL_updateDeleteScheduledMessages))
// AntiRecall.insertDeletedMessage(new TLRPC.TL_updateDeleteScheduledMessages(item).getMessages());

//if (item.getClass().equals(TL_updateDeleteChannelMessages))
// AntiRecall.insertDeletedMessage(new TLRPC.TL_updateDeleteChannelMessages(item).getMessages());
//if (item.getClass().equals(TL_updateDeleteScheduledMessages))
// AntiRecall.insertDeletedMessage(new TLRPC.TL_updateDeleteScheduledMessages(item).getMessages());

//if (item.getClass().equals(TL_updateDeleteMessages))
// AntiRecall.insertDeletedMessage(new TLRPC.TL_updateDeleteMessages(item).getMessages());
if (item.getClass().equals(TL_updateDeleteChannelMessages))
AntiRecall.insertNeedProcessDeletedMessage(new TLRPC.TL_updateDeleteChannelMessages(item).getMessages());

if (HookInit.DEBUG_MODE)
Utils.log("Protected message! event: " + item.getClass());
}
if (item.getClass().equals(TL_updateDeleteMessages))
AntiRecall.insertNeedProcessDeletedMessage(new TLRPC.TL_updateDeleteMessages(item).getMessages());

if (HookInit.DEBUG_MODE)
Utils.log("Protected message! event: " + item.getClass());
}

param.args[0] = newUpdates;
}
Expand Down Expand Up @@ -238,11 +299,14 @@ public static void initNotification(XC_LoadPackage.LoadPackageParam lpparam) thr
XposedBridge.hookMethod(markMessagesAsDeletedMethod, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
param.setResult(null);
if (param.args[1] instanceof ArrayList)
{
ArrayList<Integer> list = Utils.castList(param.args[1], Integer.class);
list.removeIf(AntiRecall::findInNeedProcess);
param.args[1] = list;
insertDeletedMessage(list);
needProcessing.forEach(AntiRecall::insertDeletedMessage);
needProcessing.clear();
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package nep.timeline.re_telegram.structs;

import java.util.ArrayList;
import java.util.List;

public class DeletedMessageInfo {
private final int selectedAccount;
private final List<Integer> messageIds;
private final ArrayList<Integer> messageIds;

public DeletedMessageInfo(int selectedAccount, List<Integer> messageIds)
public DeletedMessageInfo(int selectedAccount, ArrayList<Integer> messageIds)
{
this.selectedAccount = selectedAccount;
this.messageIds = messageIds;
Expand All @@ -24,7 +23,7 @@ public int getSelectedAccount() {
return this.selectedAccount;
}

public List<Integer> getMessageIds() {
public ArrayList<Integer> getMessageIds() {
return this.messageIds;
}

Expand Down
30 changes: 30 additions & 0 deletions app/src/main/java/nep/timeline/re_telegram/utils/MethodUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,34 @@ public static Object invokeMethodOfClass(Object instance, Class<?> clazz, String
return null;
}
}

public static Object invokeMethodOfClass(Object clazz, Method method, Object... args) {
try
{
if (!method.isAccessible())
method.setAccessible(true);

return method.invoke(clazz, args);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}

public static Object invokeMethodOfClass(Object instance, Class<?> clazz, Method method, Object... args) {
try
{
if (!method.isAccessible())
method.setAccessible(true);

return method.invoke(instance, args);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
}

0 comments on commit e07a49d

Please sign in to comment.