Skip to content

Commit

Permalink
sepinf-inc#2286: support for group admins in WhatsAppParser
Browse files Browse the repository at this point in the history
  • Loading branch information
aberenguel committed Aug 9, 2024
1 parent da35073 commit a81646c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Chat {
private String recoveredFrom;

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

public Chat(WAContact remote) {
this.remote = remote;
Expand Down Expand Up @@ -143,6 +144,10 @@ public Set<WAContact> getGroupMembers() {
return groupMembers;
}

public Set<WAContact> getGroupAdmins() {
return groupAdmins;
}

public void setGroupMembers(Set<WAContact> groupmembers) {
this.groupMembers = groupmembers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ protected void setGroupMembers(Chat c, Connection conn, String SELECT_GROUP_MEMB
String memberId = rs.getString("member");
if (memberId != null && !memberId.trim().isEmpty()) {
c.getGroupMembers().add(contacts.getContact(memberId));
if (rs.getBoolean("admin")) {
c.getGroupAdmins().add(contacts.getContact(memberId));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public class ExtractorAndroid extends Extractor {
private boolean hasMediaCaptionCol = false;
private boolean hasSubjectCol = false;
private boolean hasMediaDurationCol = false;
private boolean hasGroupParticiantsTable = true;
private boolean hasGroupParticipantsTable = true;
private boolean hasGroupParticipantUserTable = true;
private boolean hasForwardedCol = false;
private boolean hasQuoteCol = false;
private SQLException parsingException = null;
Expand Down Expand Up @@ -147,7 +148,8 @@ protected List<Chat> extractChatList() throws WAExtractorException {
hasSortTimestamp = databaseHasSortTimestamp(conn);
hasChatView = databaseHasChatView(conn);
hasThumbTable = SQLite3DBParser.containsTable("message_thumbnails", conn); //$NON-NLS-1$
hasGroupParticiantsTable = SQLite3DBParser.containsTable("group_participants", conn); //$NON-NLS-1$
hasGroupParticipantsTable = SQLite3DBParser.containsTable("group_participants", conn); //$NON-NLS-1$
hasGroupParticipantUserTable = SQLite3DBParser.containsTable("group_participant_user", conn); //$NON-NLS-1$
hasEditVersionCol = SQLite3DBParser.checkIfColumnExists(conn, "messages", "edit_version"); //$NON-NLS-1$ //$NON-NLS-2$
hasMediaCaptionCol = SQLite3DBParser.checkIfColumnExists(conn, "messages", "media_caption"); //$NON-NLS-1$ //$NON-NLS-2$
hasMediaDurationCol = SQLite3DBParser.checkIfColumnExists(conn, "messages", "media_duration"); //$NON-NLS-1$ //$NON-NLS-2$
Expand Down Expand Up @@ -217,7 +219,9 @@ protected List<Chat> extractChatList() throws WAExtractorException {
undeletedMessagesTable, hasThumbTable, hasEditVersionCol, firstTry));
if (c.isGroupChat()) {
try {
setGroupMembers(c, conn, hasGroupParticiantsTable ? SELECT_GROUP_MEMBERS : null);
String query = hasGroupParticipantUserTable ? SELECT_GROUP_MEMBERS_2
: hasGroupParticipantsTable ? SELECT_GROUP_MEMBERS : null;
setGroupMembers(c, conn, query);
} catch (SQLException ex) {
if (firstTry || !isSqliteCorruptException(ex)) {
throw ex;
Expand Down Expand Up @@ -781,7 +785,10 @@ private static String getMessagesQueryQuote(boolean hasThumbTable, boolean hasEd
+ "WHERE remoteId=? and status!=-1 ORDER BY timestamp"; //$NON-NLS-1$

// to address a field must use ` instead of '
private static final String SELECT_GROUP_MEMBERS = "select gjid as 'group', jid as member FROM group_participants where `group`=?"; //$NON-NLS-1$
private static final String SELECT_GROUP_MEMBERS = "select gjid as 'group', jid as member, admin FROM group_participants where `group`=?"; //$NON-NLS-1$

static final String SELECT_GROUP_MEMBERS_2 = "select g._id as group_id, g.raw_string as group_name, u._id as user_id, u.raw_string as member, gp.rank > 0 as admin "
+ "FROM group_participant_user gp inner join jid g on g._id=gp.group_jid_row_id inner join jid u on u._id=gp.user_jid_row_id where u.server='s.whatsapp.net' and u.type=0 and group_name=?"; //$NON-NLS-1$

private static final String SELECT_QUOTES_NO_THUMBS_TABLE = "SELECT mq._id AS id, mq.key_remote_jid "
+ "as remoteId, mq.remote_resource AS remoteResource, mq.status, mq.data, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected List<Chat> extractChatList() throws WAExtractorException {
for (Chat c : list) {
Collections.sort(c.getMessages());
if (c.isGroupChat()) {
setGroupMembers(c, conn, SELECT_GROUP_MEMBERS);
setGroupMembers(c, conn, ExtractorAndroid.SELECT_GROUP_MEMBERS_2);
}
}

Expand Down Expand Up @@ -1093,7 +1093,4 @@ private static String getSelectBlockedQuery(Connection conn) throws SQLException
+ " left join chat chat1 on chat1.jid_row_id = log.jid_row_id"
+ " left join chat chat2 on chat2.jid_row_id = log.group_jid_row_id";

private static final String SELECT_GROUP_MEMBERS = "select g._id as group_id, g.raw_string as group_name, u._id as user_id, u.raw_string as member "
+ "FROM group_participant_user gp inner join jid g on g._id=gp.group_jid_row_id inner join jid u on u._id=gp.user_jid_row_id where u.server='s.whatsapp.net' and u.type=0 and group_name=?"; //$NON-NLS-1$

}
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ public void extractPushNames() {

private static final String SELECT_PUSH_NAMES = "select ZJID as jid, ZPUSHNAME as pushname from ZWAPROFILEPUSHNAME";

private static final String SELECT_GROUP_MEMBERS = "select CS.ZCONTACTJID as `group`, ZMEMBERJID as member from ZWAGROUPMEMBER GM "
private static final String SELECT_GROUP_MEMBERS = "select CS.ZCONTACTJID as `group`, ZMEMBERJID as member, ZISADMIN as admin from ZWAGROUPMEMBER GM "
+ "inner join ZWACHATSESSION CS on GM.ZCHATSESSION=CS.Z_PK where `group`=?";

private static final String SELECT_MESSAGES_USER = "SELECT ZWAMESSAGE.Z_PK AS id, ZCHATSESSION " //$NON-NLS-1$
Expand Down

0 comments on commit a81646c

Please sign in to comment.