Skip to content

Commit

Permalink
chg: [chat participants] show the numbers of messages by participant …
Browse files Browse the repository at this point in the history
…in a chat
  • Loading branch information
Terrtia committed Feb 27, 2025
1 parent 19c1d16 commit ff6a42f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bin/lib/chats_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,9 @@ def api_get_chat_participants(chat_type, chat_subtype, chat_id):
chat_participants = []
for participant in meta['participants']:
user_account = UsersAccount.UserAccount(participant['id'], participant['subtype'])
chat_participants.append(user_account.get_meta({'icon', 'info', 'username'}))
user_account_meta = user_account.get_meta({'icon', 'info', 'username'})
user_account_meta['nb_messages'] = user_account.get_nb_messages_by_chat_obj(chat_obj)
chat_participants.append(user_account_meta)
meta['participants'] = chat_participants
return meta, 200

Expand Down
7 changes: 7 additions & 0 deletions bin/lib/objects/UsersAccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ def get_messages_by_chat_obj(self, chat_obj):
messages.append(f'message:{mess}')
return messages

def get_nb_messages_by_chat_obj(self, chat_obj):
messages = self.get_correlation_iter_obj(chat_obj, 'message')
if messages:
return len(messages)
else:
return 0

def get_meta(self, options=set(), translation_target=None): # TODO Username timeline
meta = self._get_meta(options=options)
meta['id'] = self.id
Expand Down

0 comments on commit ff6a42f

Please sign in to comment.