From 3ecd3fd023ea17aab444e0b4dd364f0464876686 Mon Sep 17 00:00:00 2001 From: terrtia Date: Tue, 26 Mar 2024 16:45:42 +0100 Subject: [PATCH] chg: [user-account] show chats + subchannels --- bin/lib/chats_viewer.py | 19 ++++++ bin/lib/objects/Chats.py | 1 + bin/lib/objects/abstract_chat_object.py | 3 + .../chats_explorer/basic_card_chat.html | 63 ++++++++++++++++++- .../chats_explorer/user_account.html | 48 +++----------- 5 files changed, 93 insertions(+), 41 deletions(-) diff --git a/bin/lib/chats_viewer.py b/bin/lib/chats_viewer.py index 1f4a0084..79fbd477 100755 --- a/bin/lib/chats_viewer.py +++ b/bin/lib/chats_viewer.py @@ -379,6 +379,23 @@ def get_nb_messages_iterator(filters={}): nb_messages += chat.get_nb_messages() return nb_messages +def get_user_account_chats_meta(user_id, chats, subchannels): + meta = [] + for chat_g_id in chats: + c_subtype, c_id = chat_g_id.split(':', 1) + chat = Chats.Chat(c_id, c_subtype) + chat_meta = chat.get_meta(options={'icon', 'info', 'nb_participants', 'tags_safe', 'username'}) + chat_meta['nb_messages'] = len(chat.get_user_messages(user_id)) + chat_meta['subchannels'] = [] + for subchannel_gid in chat.get_subchannels(): + if subchannel_gid[16:] in subchannels: + _, s_subtype, s_id = subchannel_gid.split(':', 2) + subchannel = ChatSubChannels.ChatSubChannel(s_id, s_subtype) + subchannel_meta = subchannel.get_meta(options={'created_at'}) + subchannel_meta['nb_messages'] = len(subchannel.get_user_messages(user_id)) + chat_meta['subchannels'].append(subchannel_meta) + meta.append(chat_meta) + return meta #### FIX #### @@ -514,6 +531,8 @@ def api_get_user_account(user_id, instance_uuid, translation_target=None): if not user_account.exists(): return {"status": "error", "reason": "Unknown user-account"}, 404 meta = user_account.get_meta({'chats', 'icon', 'info', 'subchannels', 'threads', 'translation', 'username', 'username_meta'}, translation_target=translation_target) + if meta['chats']: + meta['chats'] = get_user_account_chats_meta(user_id, meta['chats'], meta['subchannels']) return meta, 200 def api_chat_messages(subtype, chat_id): diff --git a/bin/lib/objects/Chats.py b/bin/lib/objects/Chats.py index 0e6dadd0..e883f4a7 100755 --- a/bin/lib/objects/Chats.py +++ b/bin/lib/objects/Chats.py @@ -75,6 +75,7 @@ def get_meta(self, options=set(), translation_target=None): meta['name'] = self.get_name() meta['tags'] = self.get_tags(r_list=True) if 'icon' in options: + meta['svg_icon'] = self.get_svg_icon() meta['icon'] = self.get_icon() meta['img'] = meta['icon'] if 'info' in options: diff --git a/bin/lib/objects/abstract_chat_object.py b/bin/lib/objects/abstract_chat_object.py index ef90b3db..76641857 100755 --- a/bin/lib/objects/abstract_chat_object.py +++ b/bin/lib/objects/abstract_chat_object.py @@ -307,6 +307,9 @@ def get_participants(self): def get_nb_participants(self): return self.get_nb_correlation('user-account') + def get_user_messages(self, user_id): + return self.get_correlation_iter('user-account', self.subtype, user_id, 'message') + # TODO move me to abstract subtype class AbstractChatObjects(ABC): def __init__(self, type): diff --git a/var/www/templates/chats_explorer/basic_card_chat.html b/var/www/templates/chats_explorer/basic_card_chat.html index 6598a472..bc4273bb 100644 --- a/var/www/templates/chats_explorer/basic_card_chat.html +++ b/var/www/templates/chats_explorer/basic_card_chat.html @@ -13,7 +13,7 @@

{{ meta["svg_icon"]["icon"] }} - {% if meta['username'] %}{{ meta["username"]["id"] }} {% else %} {{ meta['name'] }}{% endif %} : + {% if meta['username'] %}{{ meta["username"]["id"] }} {% else %} {{ meta['name'] }}{% endif %} : {{ meta['id'] }}

@@ -46,22 +46,79 @@

- - + + {{meta["nb_subchannels"]}}   {{meta["nb_participants"]}} + + + + + + {{meta["nb_messages"]}}   + +
+ {{ meta['info'] }} +
+
{% for tag in meta['tags'] %} {{ tag }} {% endfor %}
+ {% if meta['subchannels'] %} + + + + + + + + + + + + + {% for meta_s in meta["subchannels"] %} + + + + + + + + + {% endfor %} + +
NameIDCreated atFirst SeenLast Seen + + +
+ {{ meta_s['name'] }} + {% if meta_s['translation_name'] %} +
{{ meta_s['translation_name'] }}
+ {% endif %} +
{{ meta_s['id'] }}{{ meta_s['created_at'] }} + {% if meta_s['first_seen'] %} + {{ meta_s['first_seen'][0:4] }}-{{ meta_s['first_seen'][4:6] }}-{{ meta_s['first_seen'][6:8] }} + {% endif %} + + {% if meta_s['last_seen'] %} + {{ meta_s['last_seen'][0:4] }}-{{ meta_s['last_seen'][4:6] }}-{{ meta_s['last_seen'][6:8] }} + {% endif %} + + {{ meta_s['nb_messages'] }} +
+ + {% endif %} +

{% include 'objects/block_object_footer_small.html' %} \ No newline at end of file diff --git a/var/www/templates/chats_explorer/user_account.html b/var/www/templates/chats_explorer/user_account.html index 308f5959..49a3380b 100644 --- a/var/www/templates/chats_explorer/user_account.html +++ b/var/www/templates/chats_explorer/user_account.html @@ -38,44 +38,16 @@ {% include 'chats_explorer/block_translation.html' %} {% endwith %} - -{# {% if meta['subchannels'] %}#} -{#

Sub-Channels:

#} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# {% for meta in meta["subchannels"] %}#} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# {% endfor %}#} -{# #} -{#
#} -{# {{ meta['id'] }}#} -{# {{ meta['name'] }}{{ meta['id'] }}{{ meta['created_at'] }}#} -{# {% if meta['first_seen'] %}#} -{# {{ meta['first_seen'][0:4] }}-{{ meta['first_seen'][4:6] }}-{{ meta['first_seen'][6:8] }}#} -{# {% endif %}#} -{# #} -{# {% if meta['last_seen'] %}#} -{# {{ meta['last_seen'][0:4] }}-{{ meta['last_seen'][4:6] }}-{{ meta['last_seen'][6:8] }}#} -{# {% endif %}#} -{# {{ meta['nb_messages'] }}
#} -{##} -{# {% endif %}#} + {% if meta['chats'] %} +

User Chats:

+ {% for meta_chats in meta['chats'] %} +
+ {% with meta=meta_chats %} + {% include 'chats_explorer/basic_card_chat.html' %} + {% endwith %} +
+ {% endfor %} + {% endif %}