11package com .wmods .wppenhacer .xposed .features .privacy ;
22
3+ import android .text .TextUtils ;
4+ import android .util .Pair ;
5+
36import androidx .annotation .NonNull ;
47
58import com .wmods .wppenhacer .xposed .core .Feature ;
1316import org .luckypray .dexkit .query .enums .StringMatchType ;
1417
1518import java .lang .reflect .Method ;
19+ import java .util .List ;
1620import java .util .Objects ;
1721import java .util .Set ;
1822
@@ -27,6 +31,19 @@ public HideSeen(ClassLoader loader, XSharedPreferences preferences) {
2731 super (loader , preferences );
2832 }
2933
34+ protected static FMessageWpp .Key getKeyMessage (XC_MethodHook .MethodHookParam param , Object userJidObject , List <Pair <Integer , Class <? extends String >>> strings ) {
35+ var keyObject = ReflectionUtils .getArg (param .args , FMessageWpp .Key .TYPE , 0 );
36+ if (keyObject == null ) {
37+ if (strings .size () < 2 )
38+ return null ;
39+ var idMessage = (String ) param .args [strings .get (0 ).first ];
40+ var userJid = new FMessageWpp .UserJid (userJidObject );
41+ return new FMessageWpp .Key (idMessage , userJid , false );
42+ } else {
43+ return new FMessageWpp .Key (keyObject );
44+ }
45+ }
46+
3047 @ Override
3148 public void doHook () throws Exception {
3249
@@ -52,16 +69,10 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
5269 return ;
5370 }
5471 var lid = (String ) XposedHelpers .getObjectField (sendReadReceiptJob , "jid" );
55- logDebug (lid );
56- FMessageWpp .UserJid userJid = null ;
57- try {
58- userJid = new FMessageWpp .UserJid (lid );
59- if (userJid .isNull ()) return ;
60- } catch (Throwable e ) {
61- // WhatsApp crashes when attempting to create UserJid from MeJid or LidMeJid
62- // and this issue can be ignored since we don't need to hide something from ourself
72+ if (TextUtils .isEmpty (lid ) || lid .contains ("lid_me" ) || lid .contains ("status_me" ))
6373 return ;
64- }
74+ FMessageWpp .UserJid userJid = new FMessageWpp .UserJid (lid );
75+ if (userJid .isNull ()) return ;
6576 var privacy = CustomPrivacy .getJSON (userJid .getPhoneNumber ());
6677
6778 var customHideRead = privacy .optBoolean ("HideSeen" , hideread );
@@ -95,23 +106,25 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
95106
96107
97108 Method ReceiptMethod = Unobfuscator .loadReceiptMethod (classLoader );
98- logDebug (Unobfuscator .getMethodDescriptor (ReceiptMethod ));
109+ logDebug ("ReceiptMethod" , Unobfuscator .getMethodDescriptor (ReceiptMethod ));
99110
100111 XposedBridge .hookMethod (ReceiptMethod , new XC_MethodHook () {
101112 @ Override
102113 protected void beforeHookedMethod (MethodHookParam param ) throws Throwable {
103114 if (WppCore .getCurrentConversation () != WppCore .getCurrentActivity ()) return ;
104- var keyObject = ReflectionUtils .getArg (param .args , FMessageWpp .Key .TYPE , 0 );
105- var keyMessage = new FMessageWpp .Key (keyObject );
115+ var userJidObject = ReflectionUtils .getArg (param .args , Unobfuscator .findFirstClassUsingName (classLoader , StringMatchType .EndsWith , "jid.Jid" ), 0 );
116+ if (userJidObject == null ) return ;
117+ var strings = ReflectionUtils .findClassesOfType (((Method ) param .method ).getParameterTypes (), String .class );
118+ FMessageWpp .Key keyMessage = getKeyMessage (param , userJidObject , strings );
119+ if (keyMessage == null )
120+ return ;
106121 var fmessage = keyMessage .getFMessage ();
107122 if (fmessage != null ) {
108123 if (MessageHistory .getInstance ().getHideSeenMessage (keyMessage .remoteJid .getUserRawString (), keyMessage .messageID , fmessage .isViewOnce () ? MessageHistory .MessageType .VIEW_ONCE_TYPE : MessageHistory .MessageType .MESSAGE_TYPE ) != null ) {
109124 return ;
110125 }
111126 }
112- var userJid = ReflectionUtils .getArg (param .args , Unobfuscator .findFirstClassUsingName (classLoader , StringMatchType .EndsWith , "jid.Jid" ), 0 );
113- if (userJid == null ) return ;
114- var msgTypeIdx = ReflectionUtils .findIndexOfType (((Method ) param .method ).getParameterTypes (), String .class );
127+ var msgTypeIdx = strings .get (strings .size () - 1 ).first ;
115128 if (!Objects .equals ("read" , param .args [msgTypeIdx ])) return ;
116129 var privacy = CustomPrivacy .getJSON (keyMessage .remoteJid .getPhoneNumber ());
117130 var customHideRead = privacy .optBoolean ("HideSeen" , hideread );
0 commit comments