Skip to content

Commit

Permalink
'#1880: Use a single constant for WA "@s.whatsapp.net" suffix.
Browse files Browse the repository at this point in the history
  • Loading branch information
wladimirleite committed Oct 4, 2023
1 parent 26b4049 commit bfb0997
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected List<Chat> extractChatList() throws WAExtractorException {

for (Chat c : undeletedChats) {
String remoteId = c.getRemote().getId();
remoteId += c.isGroupChat() ? "@g.us" : "@s.whatsapp.net"; //$NON-NLS-1$ //$NON-NLS-2$
remoteId += c.isGroupChat() ? "@g.us" : WAContact.waSuffix;
if (!activeChats.contains(remoteId)) {
list.add(c);
if (firstTry && c.isDeleted()) {
Expand Down Expand Up @@ -337,7 +337,7 @@ private List<Message> extractMessages(Connection conn, WAContact remote, boolean
boolean recoverDeleted = undeleteTable != null && !undeletedMessages.isEmpty();

String id = remote.getId();
id += isGroupChat ? "@g.us" : "@s.whatsapp.net"; //$NON-NLS-1$ //$NON-NLS-2$
id += isGroupChat ? "@g.us" : WAContact.waSuffix;

Set<MessageWrapperForDuplicateRemoval> activeMessages = new HashSet<>();
Map<Long, Message> activeMessageIds = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class ReportGenerator {
private static final String lockedIcon = "<img class=\"lock\"/>";
private static final String locationIcon = "<img class=\"location\"/>";
private static final String forwardedIcon = "<img class=\"fwd\"/>";
private static final String waSuffix = "@s.whatsapp.net";

public ReportGenerator() {
}
Expand Down Expand Up @@ -427,7 +426,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
if (!number.isEmpty()) {
if (name.isEmpty()) {
name = number;
} else if (!number.equals(name) && !number.equals(name + waSuffix)) {
} else if (!number.equals(name) && !number.equals(name + WAContact.waSuffix)) {
name += " (" + number + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
}
Expand Down Expand Up @@ -675,8 +674,8 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
if (contact != null) {
name = contact.getName();
}
if (number.endsWith(waSuffix)) {
number = number.substring(0, number.length() - waSuffix.length());
if (number.endsWith(WAContact.waSuffix)) {
number = number.substring(0, number.length() - WAContact.waSuffix.length());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

public class WAAccount extends WAContact {

private static final String idSuffix = "@s.whatsapp.net"; //$NON-NLS-1$

private boolean isUnknown = false;

public WAAccount(String id) {
Expand All @@ -47,8 +45,8 @@ public static WAAccount getFromAndroidXml(InputStream is) {
if (value == null || value.isBlank())
return null;
}
if (!value.endsWith(idSuffix))
value += idSuffix;
if (!value.endsWith(waSuffix))
value += waSuffix;

WAAccount account = new WAAccount(value);

Expand Down Expand Up @@ -80,8 +78,8 @@ public static WAAccount getFromIOSPlist(InputStream is) {
return null;
}
String strVal = value.toString();
if (!strVal.endsWith(idSuffix))
strVal += idSuffix;
if (!strVal.endsWith(waSuffix))
strVal += waSuffix;

WAAccount account = new WAAccount(strVal);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public class WAContact {

protected static final String waSuffix = "@s.whatsapp.net";

private final String id;

private final String suffix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public void extractContactList() throws WAExtractorException {

while (rs.next()) {
String id = getString(rs, "ZWHATSAPPID");
if (!id.endsWith("@s.whatsapp.net")) {
id += "@s.whatsapp.net";
if (!id.endsWith(WAContact.waSuffix)) {
id += WAContact.waSuffix;
}
WAContact c = directory.getContact(id);
c.setDisplayName(getString(rs, "ZHIGHLIGHTEDNAME")); //$NON-NLS-1$
Expand All @@ -82,8 +82,8 @@ public void extractContactList() throws WAExtractorException {
if (undeletedContactsTable != null) {
for (var row : undeletedContactsTable.getTableRows()) {
var id = row.getTextValue("ZWHATSAPPID");
if (!id.endsWith("@s.whatsapp.net")) {
id += "@s.whatsapp.net";
if (!id.endsWith(WAContact.waSuffix)) {
id += WAContact.waSuffix;
}
if (! directory.hasContact(id)) { // only recover contact if it does not exist already
WAContact c = directory.getContact(id);
Expand Down

0 comments on commit bfb0997

Please sign in to comment.