Skip to content

Commit 9c0448a

Browse files
committed
refactor: Improve UserJid to handle both LID and JID
This commit refactors the `UserJid` class to correctly handle both LID (Lid-based JID) and standard JID inputs. The constructor now differentiates between the two formats, ensuring the correct `lid` and `jid` objects are resolved. The `isPresent()` method has been replaced with `isNull()` for better clarity, and the changes have been propagated across the codebase to adapt to the new logic.
1 parent 673acb9 commit 9c0448a

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
import java.io.File;
3232
import java.lang.reflect.Field;
33-
import java.lang.reflect.InvocationTargetException;
3433
import java.lang.reflect.Method;
3534
import java.lang.reflect.Modifier;
3635
import java.util.Arrays;
@@ -353,7 +352,7 @@ public static int getDefaultTheme() {
353352
@NonNull
354353
public static String getContactName(FMessageWpp.UserJid userJid) {
355354
loadWADatabase();
356-
if (mWaDatabase == null || !userJid.isPresent()) return "";
355+
if (mWaDatabase == null || userJid.isNull()) return "";
357356
String name = getSContactName(userJid, false);
358357
if (!TextUtils.isEmpty(name)) return name;
359358
return getWppContactName(userJid);
@@ -382,7 +381,7 @@ public static String getSContactName(FMessageWpp.UserJid userJid, boolean saveOn
382381
@NonNull
383382
public static String getWppContactName(FMessageWpp.UserJid userJid) {
384383
loadWADatabase();
385-
if (mWaDatabase == null || !userJid.isPresent()) return "";
384+
if (mWaDatabase == null || userJid.isNull()) return "";
386385
String name = null;
387386
var rawJid = userJid.getRawString();
388387
var cursor2 = mWaDatabase.query("wa_vnames", new String[]{"verified_name"}, "jid = ?", new String[]{rawJid}, null, null, null);

app/src/main/java/com/wmods/wppenhacer/xposed/core/components/FMessageWpp.java

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,19 +243,26 @@ public static class UserJid {
243243

244244
public Object lid;
245245

246-
public UserJid(@Nullable Object lid, @Nullable Object jid) {
247-
this.lid = lid;
248-
this.jid = jid;
249-
}
250-
251246
public UserJid(@Nullable String rawjid) {
252-
this.lid = WppCore.createUserJid(rawjid);
253-
this.jid = WppCore.resolveJidFromLid(this.lid);
247+
if (rawjid == null) return;
248+
if (checkValidLID(rawjid)) {
249+
this.lid = WppCore.createUserJid(rawjid);
250+
this.jid = WppCore.resolveJidFromLid(this.lid);
251+
} else {
252+
this.jid = WppCore.createUserJid(rawjid);
253+
this.lid = WppCore.resolveLidFromJid(this.jid);
254+
}
254255
}
255256

256-
public UserJid(@Nullable Object lid) {
257-
this.lid = lid;
258-
this.jid = WppCore.resolveJidFromLid(lid);
257+
public UserJid(@Nullable Object lidOrJid) {
258+
if (lidOrJid == null) return;
259+
if (checkValidLID((String) XposedHelpers.callMethod(lidOrJid, "getRawString"))) {
260+
this.lid = lidOrJid;
261+
this.jid = WppCore.resolveJidFromLid(this.lid);
262+
} else {
263+
this.jid = lidOrJid;
264+
this.lid = WppCore.resolveLidFromJid(this.jid);
265+
}
259266
}
260267

261268
@Nullable
@@ -310,8 +317,16 @@ public boolean isGroup() {
310317
}
311318

312319

313-
public boolean isPresent() {
314-
return this.jid != null && this.lid != null;
320+
public boolean isNull() {
321+
return this.jid == null || this.lid == null;
322+
}
323+
324+
private static boolean checkValidLID(@NonNull String lid) {
325+
if (lid.contains("@lid")) {
326+
String id = lid.split("@")[0];
327+
return lid.length() > 14;
328+
}
329+
return false;
315330
}
316331

317332
@NonNull

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.lang.reflect.Field;
2121
import java.text.DateFormat;
22-
import java.util.Arrays;
2322
import java.util.Date;
2423
import java.util.HashMap;
2524
import java.util.HashSet;
@@ -242,7 +241,7 @@ private void showToast(FMessageWpp fMessage) {
242241
name = jidAuthor.getStripJID();
243242
}
244243
String message;
245-
if (jidAuthor.isGroup() && !fMessage.getUserJid().isPresent()) {
244+
if (jidAuthor.isGroup() && fMessage.getUserJid().isNull()) {
246245
var participantJid = fMessage.getUserJid();
247246
String participantName = WppCore.getContactName(participantJid);
248247
if (TextUtils.isEmpty(participantName)) {

app/src/main/java/com/wmods/wppenhacer/xposed/features/privacy/CustomPrivacy.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.wmods.wppenhacer.xposed.core.WppCore;
2323
import com.wmods.wppenhacer.xposed.core.components.AlertDialogWpp;
2424
import com.wmods.wppenhacer.xposed.core.components.FMessageWpp;
25-
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
2625
import com.wmods.wppenhacer.xposed.features.others.MenuHome;
2726
import com.wmods.wppenhacer.xposed.utils.DesignUtils;
2827
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;
@@ -31,7 +30,6 @@
3130

3231
import org.json.JSONObject;
3332

34-
import java.lang.reflect.Field;
3533
import java.lang.reflect.Method;
3634
import java.util.ArrayList;
3735
import java.util.Objects;
@@ -216,7 +214,7 @@ private void showCustomPrivacyList(Activity activity, Class<?> contactClass, Cla
216214

217215
private void showPrivacyDialog(Activity activity, boolean isChat) {
218216
var userJid = getUserJid(activity, isChat);
219-
if (!userJid.isPresent()) return;
217+
if (userJid.isNull()) return;
220218
AlertDialogWpp builder = createPrivacyDialog(activity, userJid.getStripJID());
221219
builder.show();
222220
}

app/src/main/java/com/wmods/wppenhacer/xposed/features/privacy/HideSeen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
5353
}
5454
var lid = (String) XposedHelpers.getObjectField(srj, "jid");
5555
var userJid = new FMessageWpp.UserJid(lid);
56-
if (!userJid.isPresent()) return;
56+
if (userJid.isNull()) return;
5757
var privacy = CustomPrivacy.getJSON(userJid.getStripJID());
5858

5959
var customHideRead = privacy.optBoolean("HideSeen", hideread);

0 commit comments

Comments
 (0)