Skip to content

Commit

Permalink
sepinf-inc#2286: WhatsApp issues in internal parser
Browse files Browse the repository at this point in the history
  • Loading branch information
aberenguel committed Oct 9, 2024
1 parent 044434f commit 7911646
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ private ConversationUtils() {

public static String buidPartyString(String name, String id, String phone, String username, String source) {
StringBuilder sb = new StringBuilder();

if (StringUtils.equals(name, phone)) {
name = null;
}

if (name != null) {
sb.append(name);
}
Expand All @@ -30,9 +35,11 @@ public static String buidPartyString(String name, String id, String phone, Strin
}
sb.append("(");
boolean needToSeparate = false;
if ("WhatsApp".equalsIgnoreCase(source)) {
String phoneFromId = StringUtils.substringBeforeLast(id, "@");
sb.append("+").append(StringUtils.firstNonBlank(phone, phoneFromId));
if (StringUtils.startsWithIgnoreCase(source, "WhatsApp")) {
if ("unknownAccount".equalsIgnoreCase(id)) {
return id;
}
sb.append(StringUtils.firstNonBlank(id, phone));
} else {
if (id != null) {
sb.append("ID:").append(id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package iped.parsers.whatsapp;

import org.apache.commons.lang3.StringUtils;

public class WAContact {

protected static final String waSuffix = "@s.whatsapp.net";
Expand Down Expand Up @@ -89,17 +91,7 @@ public void setNickName(String nickName) {
}

public String getName() {
if (displayName != null && !displayName.isBlank())
return displayName;
else if (waName != null && !waName.isBlank())
return waName;
else if (givenName != null && !givenName.isBlank())
return givenName;
else if (nickName != null && !nickName.isBlank())
return nickName;
else
return id;

return StringUtils.firstNonBlank(displayName, waName, givenName, nickName, id);
}

public String getTitle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.commons.codec.binary.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.tika.config.Field;
import org.apache.tika.exception.TikaException;
Expand Down Expand Up @@ -331,18 +332,18 @@ private void createReport(List<Chat> chatList, IItemSearcher searcher, WAContact

if (c.isGroupOrChannelChat()) {
for (WAContact member : c.getGroupMembers()) {
addParticipantFields(chatMetadata, ExtraProperties.CONVERSATION_PARTICIPANTS, member, cache);
addParticipantFields(chatMetadata, ExtraProperties.CONVERSATION_PARTICIPANTS, member);
}
for (WAContact admin : c.getGroupAdmins()) {
addParticipantFields(chatMetadata, ExtraProperties.CONVERSATION_ADMINS, admin, cache);
addParticipantFields(chatMetadata, ExtraProperties.CONVERSATION_ADMINS, admin);
}
chatMetadata.set(ExtraProperties.CONVERSATION_TYPE, c.isGroupChat() ? ConversationUtils.TYPE_GROUP : ConversationUtils.TYPE_BROADCAST);
} else {
if (c.getRemote() != null) {
addParticipantFields(chatMetadata, ExtraProperties.CONVERSATION_PARTICIPANTS, c.getRemote(), cache);
addParticipantFields(chatMetadata, ExtraProperties.CONVERSATION_PARTICIPANTS, c.getRemote());
}
if (account != null) {
addParticipantFields(chatMetadata, ExtraProperties.CONVERSATION_PARTICIPANTS, account, cache);
addParticipantFields(chatMetadata, ExtraProperties.CONVERSATION_PARTICIPANTS, account);
}
chatMetadata.set(ExtraProperties.CONVERSATION_TYPE, ConversationUtils.TYPE_PRIVATE);
}
Expand All @@ -351,7 +352,7 @@ private void createReport(List<Chat> chatList, IItemSearcher searcher, WAContact
chatMetadata.set(ExtraProperties.CONVERSATION_ID, c.getRemote() != null ? c.getRemote().getFullId() : c.getPrintId());
chatMetadata.set(ExtraProperties.CONVERSATION_NAME, c.getRemote() != null ? c.getRemote().getName() : "<NA>");
if (account != null) {
chatMetadata.set(ExtraProperties.CONVERSATION_ACCOUNT, account.getFullId());
addParticipantFields(chatMetadata, ExtraProperties.CONVERSATION_ACCOUNT, account);
}
chatMetadata.set(ExtraProperties.CONVERSATION_MESSAGES_COUNT, messagesCount);

Expand All @@ -374,8 +375,8 @@ private void createReport(List<Chat> chatList, IItemSearcher searcher, WAContact

}

private void addParticipantFields(Metadata chatMetadata, String field, WAContact member, HashMap<String, String> cache) {
chatMetadata.add(field, formatContact(member, cache));
private void addParticipantFields(Metadata chatMetadata, String field, WAContact member) {
chatMetadata.add(field, ConversationUtils.buidPartyString(member.getName(), member.getFullId(), member.getId(), null, "WhatsApp"));
chatMetadata.add(field + ExtraProperties.CONVERSATION_SUFFIX_ID, member.getFullId());
chatMetadata.add(field + ExtraProperties.CONVERSATION_SUFFIX_PHONE, member.getId());
}
Expand Down

0 comments on commit 7911646

Please sign in to comment.