Skip to content

Commit

Permalink
sepinf-inc#2294: always calls fillAccountAvatar and fillAccountWithCo…
Browse files Browse the repository at this point in the history
…ntactData in getUserAccount()
  • Loading branch information
aberenguel committed Oct 10, 2024
1 parent 12f6b5c commit 61e5dcd
Showing 1 changed file with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -806,18 +806,12 @@ private void parseEmbeddedWhatsAppAccount(WAAccount account, ParseContext contex
}
}

private void fillAccountWithContactData(WAAccount account, ParseContext context, ContentHandler handler) {
private void fillAccountWithContactData(WAAccount account, IItemSearcher searcher, String dbPath) {
if (account == null || account.getWaName() != null) {
return;
}
IItemSearcher searcher = context.get(IItemSearcher.class);
ItemInfo itemInfo = context.get(ItemInfo.class);
String filePath = null;
if (itemInfo != null) {
filePath = Paths.get(itemInfo.getPath()).getParent().resolveSibling("databases").resolve("wa.db").toString().replace("\\", "/");
}
try {
WAContactsDirectory contacts = getWAContactsDirectoryForPath(filePath, searcher, ExtractorAndroidFactory.class);
WAContactsDirectory contacts = getWAContactsDirectoryForPath(dbPath, searcher, ExtractorAndroidFactory.class);
WAContact c = contacts.getContact(account.getFullId());
if (c != null) {
account.setWaName(c.getDisplayName());
Expand All @@ -828,16 +822,11 @@ private void fillAccountWithContactData(WAAccount account, ParseContext context,
}
}

private void fillAccountAvatar(WAAccount account, ParseContext context, ContentHandler handler) {
private void fillAccountAvatar(WAAccount account, IItemSearcher searcher, String dbPath) {
if (account == null || account.getAvatar() != null || account.getAvatarPath() != null) {
return;
}
IItemSearcher searcher = context.get(IItemSearcher.class);
ItemInfo itemInfo = context.get(ItemInfo.class);
String filePath = null;
if (itemInfo != null) {
filePath = Paths.get(itemInfo.getPath()).getParent().resolveSibling("files").resolve("me.jpg").toString().replace("\\", "/");
}
String filePath = Paths.get(dbPath).getParent().resolveSibling("files").resolve("me.jpg").toString().replace("\\", "/");

String query = BasicProps.PATH + ":\"" + searcher.escapeQuery(filePath) + "\""; //$NON-NLS-1$ //$NON-NLS-2$
List<IItemReader> result = searcher.search(query);
Expand Down Expand Up @@ -905,6 +894,12 @@ private WAAccount getUserAccount(IItemSearcher searcher, String dbPath, boolean
}
}
}

if (isAndroid) {
fillAccountAvatar(account, searcher, dbPath);
fillAccountWithContactData(account, searcher, dbPath);
}

return account;
}

Expand Down Expand Up @@ -1260,8 +1255,8 @@ private void parseWhatsAppContacts(InputStream stream, ContentHandler handler, M
}

if (isAndroid) {
fillAccountAvatar(account, context, handler);
fillAccountWithContactData(account, context, handler);
fillAccountAvatar(account, searcher, dbPath);
fillAccountWithContactData(account, searcher, dbPath);
parseEmbeddedWhatsAppAccount(account, context, handler);
}

Expand Down

0 comments on commit 61e5dcd

Please sign in to comment.