Skip to content

Commit

Permalink
sepinf-inc#2286: avoid the own chat as participant in Telegram channels
Browse files Browse the repository at this point in the history
  • Loading branch information
aberenguel committed Aug 9, 2024
1 parent 9dfaebc commit c8801ee
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,19 @@ private void generateChat(Chat c, Contact account, Extractor e, IItemSearcher se
if (c.isGroupOrChannel()) {
ChatGroup cg = (ChatGroup) c;
for (long id : cg.getAdmins()) {
addParticipantFields(chatMetadata, e, ExtraProperties.COMMUNICATION_ADMINS, id);
addParticipantFields(chatMetadata, e, ExtraProperties.PARTICIPANTS, id);
addParticipantFields(chatMetadata, c, e, ExtraProperties.COMMUNICATION_ADMINS, id);
addParticipantFields(chatMetadata, c, e, ExtraProperties.PARTICIPANTS, id);
}
for (long id : cg.getMembers()) {
addParticipantFields(chatMetadata, e, ExtraProperties.PARTICIPANTS, id);
addParticipantFields(chatMetadata, c, e, ExtraProperties.PARTICIPANTS, id);
}
int participantsCount = cg.getParticipantsCount();
if (participantsCount > 0) {
chatMetadata.add(ExtraProperties.PARTICIPANTS + "Count", String.valueOf(participantsCount));
}
} else {
addParticipantFields(chatMetadata, e, ExtraProperties.PARTICIPANTS, c.getId());
addParticipantFields(chatMetadata, e, ExtraProperties.PARTICIPANTS, e.getUserAccount().getId());
addParticipantFields(chatMetadata, c, e, ExtraProperties.PARTICIPANTS, c.getId());
addParticipantFields(chatMetadata, c, e, ExtraProperties.PARTICIPANTS, e.getUserAccount().getId());
}

if (c.isChannel()) {
Expand Down Expand Up @@ -249,7 +249,12 @@ private void generateChat(Chat c, Contact account, Extractor e, IItemSearcher se
}
}

private void addParticipantFields(Metadata chatMetadata, Extractor e, String field, long id) {
private void addParticipantFields(Metadata chatMetadata, Chat c, Extractor e, String field, long id) {

// avoid the own chat as participant (happens in Channels)
if (c.getId() == id && c.isGroupOrChannel())
return;

Contact contact = e.getContact(id);
chatMetadata.add(field, contact.toString());
chatMetadata.add(field + ":ID", Long.toString(id));
Expand Down

0 comments on commit c8801ee

Please sign in to comment.