Skip to content

Commit

Permalink
'#2036: Basic support to WA channels.
Browse files Browse the repository at this point in the history
  • Loading branch information
wladimirleite committed Jan 4, 2024
1 parent a023f3c commit 262aa2a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ public class Chat {
private final WAContact remote;
private String subject;
private List<Message> messages = new ArrayList<>();
private String title = null;
private boolean groupChat = false;
private boolean deleted = false;
private String title;
private boolean isGroupChat;
private boolean isChannelChat;
private boolean isDeleted;

private String recoveredFrom = null;
private String recoveredFrom;

private Set<WAContact> groupmembers = new HashSet<>();
private Set<WAContact> groupMembers = new HashSet<>();

public Chat(WAContact remote) {
this.remote = remote;
Expand Down Expand Up @@ -81,19 +82,36 @@ public void setMessages(List<Message> messages) {
}

public boolean isGroupChat() {
return groupChat;
return isGroupChat;
}

public void setGroupChat(boolean groupChat) {
this.groupChat = groupChat;
public void setGroupChat(boolean isGroupChat) {
this.isGroupChat = isGroupChat;
}

public boolean isChannelChat() {
return isChannelChat;
}

public void setChannelChat(boolean isChannelChat) {
this.isChannelChat = isChannelChat;
}

public boolean isGroupOrChannelChat() {
return isGroupChat || isChannelChat;
}

public String getTitle() {
if (title == null) {
if (isGroupChat()) {
title = "WhatsApp Group"; //$NON-NLS-1$ //$NON-NLS-2$
if (isChannelChat()) {
title = "WhatsApp Channel";
if (getSubject() != null && !getSubject().isBlank()) {
title += " - " + getSubject().strip();
}
} else if (isGroupChat()) {
title = "WhatsApp Group";
if (getSubject() != null && !getSubject().isBlank()) {
title += " - " + getSubject().strip(); //$NON-NLS-1$
title += " - " + getSubject().strip();
}
} else {
title = "WhatsApp Chat"; //$NON-NLS-1$
Expand Down Expand Up @@ -124,19 +142,19 @@ public void setRecoveredFrom(String recoveredFrom) {
this.recoveredFrom = recoveredFrom;
}

public Set<WAContact> getGroupmembers() {
return groupmembers;
public Set<WAContact> getGroupMembers() {
return groupMembers;
}

public void setGroupmembers(Set<WAContact> groupmembers) {
this.groupmembers = groupmembers;
public void setGroupMembers(Set<WAContact> groupmembers) {
this.groupMembers = groupmembers;
}

public void setDeleted(boolean deleted) {
this.deleted = deleted;
public void setDeleted(boolean isDeleted) {
this.isDeleted = isDeleted;
}

public boolean isDeleted() {
return deleted;
return isDeleted;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected void setGroupMembers(Chat c, Connection conn, String SELECT_GROUP_MEMB
// adds all contacts that sent at least one message
for (Message m : c.getMessages()) {
if (m.getRemoteResource() != null)
c.getGroupmembers().add(contacts.getContact(m.getRemoteResource()));
c.getGroupMembers().add(contacts.getContact(m.getRemoteResource()));
}
if (SELECT_GROUP_MEMBERS == null) {
return;
Expand All @@ -63,7 +63,7 @@ protected void setGroupMembers(Chat c, Connection conn, String SELECT_GROUP_MEMB
while (rs.next()) {
String memberId = rs.getString("member");
if (!memberId.trim().isEmpty()) {
c.getGroupmembers().add(contacts.getContact(memberId));
c.getGroupMembers().add(contacts.getContact(memberId));
}
}

Expand Down Expand Up @@ -108,7 +108,7 @@ protected List<Chat> cleanChatList(List<Chat> list) {
List<Chat> cleanedList = new ArrayList<>();
for (Chat c : list) {
String remote = c.getRemote() != null ? c.getRemote().getId() : null;
if (!c.getMessages().isEmpty() || !c.getGroupmembers().isEmpty()
if (!c.getMessages().isEmpty() || !c.getGroupMembers().isEmpty()
|| (c.getSubject() != null && !c.getSubject().isBlank())
|| (remote != null && !(remote = remote.strip()).isEmpty() && !remote.equals("0"))) {
cleanedList.add(c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ protected List<Chat> extractChatList() throws WAExtractorException {
Chat c = new Chat(remote);
c.setId(rs.getLong("id"));
c.setSubject(Util.getUTF8String(rs, "subject")); //$NON-NLS-1$
c.setGroupChat(contactId.endsWith("g.us")); //$NON-NLS-1$
c.setGroupChat(contactId.endsWith("@g.us"));
c.setChannelChat(contactId.endsWith("@newsletter"));
if (!(contactId.endsWith("@status") || contactId.endsWith("@broadcast"))) { //$NON-NLS-1$ //$NON-NLS-2$
list.add(c);
idToChat.put(c.getId(), c);
Expand Down Expand Up @@ -337,7 +338,7 @@ private void extractMessages(Connection conn, Map<Long, Chat> idToChat) throws S

m.setId(rs.getLong("id")); //$NON-NLS-1$
String remoteResource = rs.getString("remoteResource");
if (remoteResource == null || remoteResource.isEmpty() || !c.isGroupChat()) {
if (remoteResource == null || remoteResource.isEmpty() || !c.isGroupOrChannelChat()) {
remoteResource = c.getRemote().getFullId();
}
m.setRemoteResource(remoteResource); // $NON-NLS-1$
Expand Down Expand Up @@ -491,7 +492,7 @@ private List<Message> extractQuoteMessages(Connection conn, Chat c) throws SQLEx

m.setId(rs.getLong("id")); //$NON-NLS-1$
String remoteResource = rs.getString("remoteResource");
if (remoteResource == null || remoteResource.isEmpty() || !c.isGroupChat()) {
if (remoteResource == null || remoteResource.isEmpty() || !c.isGroupOrChannelChat()) {
remoteResource = c.getRemote().getFullId();
}
m.setRemoteResource(remoteResource); // $NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public byte[] generateNextChatHtml(Chat c, WAContactsDirectory contactsDirectory
+ thisDate + "</div></div>"); //$NON-NLS-1$
lastDate = thisDate;
}
printMessage(out, m, c.isGroupChat(), contactsDirectory, account);
printMessage(out, m, c.isGroupOrChannelChat(), contactsDirectory, account);
lastId = m.getUniqueId();
if (currentMsg != c.getMessages().size() && bout.size() >= minChatSplitSize) {
out.println("<div class=\"linha\"><div class=\"date\">" //$NON-NLS-1$
Expand All @@ -250,7 +250,7 @@ public byte[] generateNextChatHtml(Chat c, WAContactsDirectory contactsDirectory
return EmojiUtil.replaceByImages(chatBytes.toByteArray());
}

private synchronized void printMessage(PrintWriter out, Message message, boolean group,
private synchronized void printMessage(PrintWriter out, Message message, boolean isGroupOrChannel,
WAContactsDirectory contactsDirectory,
WAAccount account) {

Expand Down Expand Up @@ -342,7 +342,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
case MESSAGES_NOW_ENCRYPTED:
out.println("<div class=\"systemmessage\">"); //$NON-NLS-1$
out.print(lockedIcon);
if (group) {
if (isGroupOrChannel) {
out.println(Messages.getString("WhatsAppReport.GroupNowEncrypted")); //$NON-NLS-1$
} else {
out.println(Messages.getString("WhatsAppReport.ChatNowEncrypted")); //$NON-NLS-1$
Expand All @@ -355,7 +355,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
} else {
isFromSpecial = true;
out.println(bubbleFromSpecial);
if (!name.isEmpty() && group) {
if (!name.isEmpty() && isGroupOrChannel) {
out.println("<span class=\"name_call\">" + name + "</span><br>");
}
}
Expand All @@ -368,7 +368,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
} else {
isFromSpecial = true;
out.println(bubbleFromSpecial);
if (!name.isEmpty() && group) {
if (!name.isEmpty() && isGroupOrChannel) {
out.println("<span class=\"name_call\">" + name + "</span><br>");
}
}
Expand All @@ -381,7 +381,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
} else {
isFromSpecial = true;
out.println(bubbleFromSpecial);
if (!name.isEmpty() && group) {
if (!name.isEmpty() && isGroupOrChannel) {
out.println("<span class=\"name_call\">" + name + "</span><br>");
}
}
Expand All @@ -394,7 +394,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
} else {
isFromSpecial = true;
out.println(bubbleFromSpecial);
if (!name.isEmpty() && group) {
if (!name.isEmpty() && isGroupOrChannel) {
out.println("<span class=\"name_call\">" + name + "</span><br>");
}
}
Expand All @@ -407,7 +407,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
} else {
isFromSpecial = true;
out.println(bubbleFromSpecial);
if (!name.isEmpty() && group) {
if (!name.isEmpty() && isGroupOrChannel) {
out.println("<span class=\"name_call\">" + name + "</span><br>");
}
}
Expand All @@ -420,7 +420,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
} else {
isFromSpecial = true;
out.println(bubbleFromSpecial);
if (!name.isEmpty() && group) {
if (!name.isEmpty() && isGroupOrChannel) {
out.println("<span class=\"name_call\">" + name + "</span><br>");
}
}
Expand All @@ -433,7 +433,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
} else {
isFromSpecial = true;
out.println(bubbleFromSpecial);
if (!name.isEmpty() && group) {
if (!name.isEmpty() && isGroupOrChannel) {
out.println("<span class=\"name_call\">" + name + "</span><br>");
}
}
Expand All @@ -446,7 +446,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
} else {
isFromSpecial = true;
out.println(bubbleFromSpecial);
if (!name.isEmpty() && group) {
if (!name.isEmpty() && isGroupOrChannel) {
out.println("<span class=\"name_call\">" + name + "</span><br>");
}
}
Expand All @@ -459,7 +459,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
} else {
isFromSpecial = true;
out.println(bubbleFromSpecial);
if (!name.isEmpty() && group) {
if (!name.isEmpty() && isGroupOrChannel) {
out.println("<span class=\"name_call\">" + name + "</span><br>");
}
}
Expand All @@ -476,7 +476,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
} else {
isFromSpecial = true;
out.println(bubbleFromSpecial);
if (!name.isEmpty() && group) {
if (!name.isEmpty() && isGroupOrChannel) {
out.println("<span class=\"name_call\">" + name + "</span><br>");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private void createReport(List<Chat> chatList, IItemSearcher searcher, WAContact
chatMetadata.add(ExtraProperties.PARTICIPANTS, local);
}
if (c.isGroupChat()) {
for (WAContact member : c.getGroupmembers()) {
for (WAContact member : c.getGroupMembers()) {
chatMetadata.add(ExtraProperties.PARTICIPANTS, formatContact(member, cache));
}
// string formatted as {creator's phone number}-{creation time}@g.us
Expand Down Expand Up @@ -884,7 +884,7 @@ private String formatContact(WAContact contact, Map<String, String> cache) {
}

private void fillGroupRecipients(Metadata meta, Chat c, String from, Map<String, String> cache) {
for (WAContact member : c.getGroupmembers()) {
for (WAContact member : c.getGroupMembers()) {
String gmb = formatContact(member, cache);
if (!gmb.equals(from)) {
meta.add(org.apache.tika.metadata.Message.MESSAGE_TO, gmb);
Expand Down

0 comments on commit 262aa2a

Please sign in to comment.