Skip to content

Commit 85b9d6a

Browse files
committed
Fix Seen tick button for View Once for audios
1 parent 0ee662c commit 85b9d6a

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

app/src/main/java/com/wmods/wppenhacer/xposed/core/WppCore.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@ public class WppCore {
5959
private static Object mActionUser;
6060
private static SQLiteDatabase mWaDatabase;
6161
public static BaseClient client;
62-
private static boolean isBridgeInitialized;
62+
private static Object mCachedMessageStore;
6363

6464

6565
public static void Initialize(ClassLoader loader) throws Exception {
6666
privPrefs = Utils.getApplication().getSharedPreferences("WaGlobal", Context.MODE_PRIVATE);
6767

68-
6968
// init UserJID
7069
var mSendReadClass = XposedHelpers.findClass("com.whatsapp.jobqueue.job.SendReadReceiptJob", loader);
7170
var subClass = ReflectionUtils.findConstructorUsingFilter(mSendReadClass, (constructor) -> constructor.getParameterCount() == 8).getParameterTypes()[0];
@@ -86,13 +85,24 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
8685
}
8786
});
8887

88+
// ActionUser
8989
var actionUser = Unobfuscator.loadActionUser(loader);
9090
XposedBridge.hookAllConstructors(actionUser, new XC_MethodHook() {
9191
@Override
9292
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
9393
mActionUser = param.thisObject;
9494
}
9595
});
96+
97+
// CachedMessageStore
98+
var cachedMessageStore = Unobfuscator.loadCachedMessageStore(loader);
99+
XposedBridge.hookAllConstructors(cachedMessageStore, new XC_MethodHook() {
100+
@Override
101+
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
102+
mCachedMessageStore = param.thisObject;
103+
}
104+
});
105+
96106
// Load wa database
97107
loadWADatabase();
98108
initBridge(Utils.getApplication());
@@ -135,7 +145,6 @@ private static boolean tryConnectBridge(BaseClient baseClient) throws Exception
135145
CompletableFuture<Boolean> canLoadFuture = baseClient.connect();
136146
Boolean canLoad = canLoadFuture.get();
137147
if (!canLoad) throw new Exception();
138-
isBridgeInitialized = true;
139148
} catch (Exception e) {
140149
return false;
141150
}
@@ -258,6 +267,17 @@ public static String getWppContactName(Object userJid) {
258267
return name == null ? "" : name;
259268
}
260269

270+
public static Object getFMessageFromKey(Object messageKey) {
271+
if (messageKey == null) return null;
272+
try {
273+
var methodResult = ReflectionUtils.findMethodUsingFilter(mCachedMessageStore.getClass(), (method) -> method.getParameterCount() == 1 && FMessageWpp.Key.TYPE.isAssignableFrom(method.getParameterTypes()[0]));
274+
return ReflectionUtils.callMethod(methodResult, mCachedMessageStore, messageKey);
275+
} catch (Exception e) {
276+
XposedBridge.log(e);
277+
return null;
278+
}
279+
}
280+
261281

262282
public static Object createUserJid(String rawjid) {
263283
var genInstance = XposedHelpers.newInstance(mGenJidClass);
@@ -356,7 +376,8 @@ public static Activity getCurrentConversation() {
356376
// for tablet UI, they're using HomeActivity instead of Conversation
357377
// TODO: Add more checks for ConversationFragment
358378
Class<?> home = XposedHelpers.findClass("com.whatsapp.HomeActivity", mCurrentActivity.getClassLoader());
359-
if (mCurrentActivity.getResources().getConfiguration().smallestScreenWidthDp >= 600 && home.isInstance(mCurrentActivity)) return mCurrentActivity;
379+
if (mCurrentActivity.getResources().getConfiguration().smallestScreenWidthDp >= 600 && home.isInstance(mCurrentActivity))
380+
return mCurrentActivity;
360381
return null;
361382
}
362383

app/src/main/java/com/wmods/wppenhacer/xposed/core/devkit/Unobfuscator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,4 +1770,12 @@ public static synchronized Method loadStateChangeMethod(ClassLoader classLoader)
17701770
return UnobfuscatorCache.getInstance().getMethod(classLoader, () -> findFirstMethodUsingStrings(classLoader, StringMatchType.Contains, "presencestatemanager/startTransitionToUnavailable/new-state"));
17711771
}
17721772

1773+
public static synchronized Class loadCachedMessageStore(ClassLoader loader) throws Exception {
1774+
return UnobfuscatorCache.getInstance().getClass(loader, () -> {
1775+
var cacheMsClass = findFirstClassUsingStrings(loader, StringMatchType.Contains, "CachedMessageStore/getMessage/key");
1776+
if (cacheMsClass == null)
1777+
throw new RuntimeException("CachedMessageStore class not found");
1778+
return cacheMsClass;
1779+
});
1780+
}
17731781
}

app/src/main/java/com/wmods/wppenhacer/xposed/features/general/SeenTick.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,38 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
297297
var messageField = ReflectionUtils.getFieldByExtendType(menuMethod.getDeclaringClass(), classThreadMessage);
298298
var messageObject = XposedHelpers.getObjectField(param.thisObject, messageField.getName());
299299
sendBlueTickMedia(messageObject, true);
300-
Toast.makeText(Utils.getApplication(), ResId.string.sending_read_blue_tick, Toast.LENGTH_SHORT).show();
300+
Utils.showToast(Utils.getApplication().getString(ResId.string.sending_read_blue_tick), Toast.LENGTH_SHORT);
301301
return true;
302302
});
303303
}
304304

305305
}
306306
});
307+
308+
XposedHelpers.findAndHookMethod("com.whatsapp.messaging.ViewOnceViewerActivity", classLoader, "onCreateOptionsMenu", classLoader.loadClass("android.view.Menu"),
309+
new XC_MethodHook() {
310+
@Override
311+
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
312+
Menu menu = (Menu) param.args[0];
313+
MenuItem item = menu.add(0, 0, 0, ResId.string.send_blue_tick).setIcon(Utils.getID("ic_notif_mark_read", "drawable"));
314+
if (ticktype == 1) item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
315+
item.setOnMenuItemClickListener(item1 -> {
316+
CompletableFuture.runAsync(() -> {
317+
var keyClass = FMessageWpp.Key.TYPE;
318+
var fieldType = ReflectionUtils.getFieldByType(param.thisObject.getClass(), keyClass);
319+
var keyMessage = ReflectionUtils.getField(fieldType, param.thisObject);
320+
var fMessage = WppCore.getFMessageFromKey(keyMessage);
321+
if (fMessage == null) return;
322+
sendBlueTickMedia(fMessage, true);
323+
Utils.showToast(Utils.getApplication().getString(ResId.string.sending_read_blue_tick), Toast.LENGTH_SHORT);
324+
});
325+
return true;
326+
});
327+
328+
}
329+
});
330+
331+
307332
}
308333

309334
private void hookOnSendMessages() throws Exception {

0 commit comments

Comments
 (0)