From 789210bcba5cd8ccfac9c3fe60ab41c8304bf88e Mon Sep 17 00:00:00 2001 From: terrtia Date: Mon, 6 Nov 2023 14:08:23 +0100 Subject: [PATCH] chg: [chats] improve UI + fix importer --- bin/lib/chats_viewer.py | 12 +- bin/lib/objects/ChatSubChannels.py | 4 +- bin/lib/objects/abstract_chat_object.py | 14 +-- bin/lib/objects/abstract_object.py | 2 + var/www/blueprints/chats_explorer.py | 14 +-- .../chats_explorer/SubChannelMessages.html | 41 ++++-- .../chats_explorer/chat_instance.html | 16 ++- .../templates/chats_explorer/chat_viewer.html | 119 +++++++++++++++++- 8 files changed, 179 insertions(+), 43 deletions(-) diff --git a/bin/lib/chats_viewer.py b/bin/lib/chats_viewer.py index 8c777707..ef02e0c8 100755 --- a/bin/lib/chats_viewer.py +++ b/bin/lib/chats_viewer.py @@ -265,6 +265,11 @@ def get_subchannels_meta_from_global_id(subchannels): meta.append(subchannel.get_meta({'nb_messages'})) return meta +def get_chat_meta_from_global_id(chat_global_id): + _, instance_uuid, chat_id = chat_global_id.split(':', 2) + chat = Chats.Chat(chat_id, instance_uuid) + return chat.get_meta() + def api_get_chat_service_instance(chat_instance_uuid): chat_instance = ChatServiceInstance(chat_instance_uuid) if not chat_instance.exists(): @@ -277,15 +282,18 @@ def api_get_chat(chat_id, chat_instance_uuid): return {"status": "error", "reason": "Unknown chat"}, 404 meta = chat.get_meta({'img', 'subchannels', 'username'}) if meta['subchannels']: - print(meta['subchannels']) meta['subchannels'] = get_subchannels_meta_from_global_id(meta['subchannels']) + else: + meta['messages'], meta['tags_messages'] = chat.get_messages() return meta, 200 def api_get_subchannel(chat_id, chat_instance_uuid): subchannel = ChatSubChannels.ChatSubChannel(chat_id, chat_instance_uuid) if not subchannel.exists(): return {"status": "error", "reason": "Unknown chat"}, 404 - meta = subchannel.get_meta({'img', 'nb_messages'}) + meta = subchannel.get_meta({'chat', 'img', 'nb_messages'}) + if meta['chat']: + meta['chat'] = get_chat_meta_from_global_id(meta['chat']) meta['messages'], meta['tags_messages'] = subchannel.get_messages() return meta, 200 diff --git a/bin/lib/objects/ChatSubChannels.py b/bin/lib/objects/ChatSubChannels.py index 15521196..8d73524a 100755 --- a/bin/lib/objects/ChatSubChannels.py +++ b/bin/lib/objects/ChatSubChannels.py @@ -80,8 +80,10 @@ class ChatSubChannel(AbstractChatObject): meta = self._get_meta(options=options) meta['tags'] = self.get_tags(r_list=True) meta['name'] = self.get_name() + if 'chat' in options: + meta['chat'] = self.get_chat() if 'img' in options: - meta['sub'] = self.get_img() + meta['img'] = self.get_img() if 'nb_messages': meta['nb_messages'] = self.get_nb_messages() return meta diff --git a/bin/lib/objects/abstract_chat_object.py b/bin/lib/objects/abstract_chat_object.py index be8c1397..465bb9e4 100755 --- a/bin/lib/objects/abstract_chat_object.py +++ b/bin/lib/objects/abstract_chat_object.py @@ -63,16 +63,15 @@ class AbstractChatObject(AbstractSubtypeObject, ABC): def get_chat(self): # require ail object TODO ## if self.type != 'chat': parent = self.get_parent() - obj_type, _ = parent.split(':', 1) - if obj_type == 'chat': - return parent + if parent: + obj_type, _ = parent.split(':', 1) + if obj_type == 'chat': + return parent def get_subchannels(self): subchannels = [] if self.type == 'chat': # category ??? - print(self.get_childrens()) for obj_global_id in self.get_childrens(): - print(obj_global_id) obj_type, _ = obj_global_id.split(':', 1) if obj_type == 'chat-subchannel': subchannels.append(obj_global_id) @@ -125,12 +124,11 @@ class AbstractChatObject(AbstractSubtypeObject, ABC): def get_message_meta(self, message, parent=True, mess_datetime=None): # TODO handle file message obj = Message(message[9:]) mess_dict = obj.get_meta(options={'content', 'link', 'parent', 'user-account'}) - print(mess_dict) + # print(mess_dict) if mess_dict.get('parent') and parent: mess_dict['reply_to'] = self.get_message_meta(mess_dict['parent'], parent=False) if mess_dict.get('user-account'): _, user_account_subtype, user_account_id = mess_dict['user-account'].split(':', 3) - print(mess_dict['user-account']) user_account = UserAccount(user_account_id, user_account_subtype) mess_dict['user-account'] = {} mess_dict['user-account']['type'] = user_account.get_type() @@ -224,8 +222,6 @@ class AbstractChatObjects(ABC): return r_object.zcard(f'{self.type}_all:{subtype}') def get_ids_by_subtype(self, subtype): - print(subtype) - print(f'{self.type}_all:{subtype}') return r_object.zrange(f'{self.type}_all:{subtype}', 0, -1) def get_all_id_iterator_iter(self, subtype): diff --git a/bin/lib/objects/abstract_object.py b/bin/lib/objects/abstract_object.py index 808e7547..cac9d58c 100755 --- a/bin/lib/objects/abstract_object.py +++ b/bin/lib/objects/abstract_object.py @@ -298,6 +298,7 @@ class AbstractObject(ABC): obj_subtype = '' obj_global_id = f'{obj_type}:{obj_subtype}:{obj_id}' r_object.hset(f'meta:{self.type}:{self.get_subtype(r_str=True)}:{self.id}', 'parent', obj_global_id) + r_object.sadd(f'child:{obj_global_id}', self.get_global_id()) def add_children(self, obj_type=None, obj_subtype=None, obj_id=None, obj_global_id=None): # TODO # REMOVE ITEM DUP if not obj_global_id: @@ -305,6 +306,7 @@ class AbstractObject(ABC): obj_subtype = '' obj_global_id = f'{obj_type}:{obj_subtype}:{obj_id}' r_object.sadd(f'child:{self.type}:{self.get_subtype(r_str=True)}:{self.id}', obj_global_id) + r_object.hset(f'meta:{obj_global_id}', 'parent', self.get_global_id()) ## others objects ## def add_obj_children(self, parent_global_id, son_global_id): diff --git a/var/www/blueprints/chats_explorer.py b/var/www/blueprints/chats_explorer.py index ff180a32..2f122a77 100644 --- a/var/www/blueprints/chats_explorer.py +++ b/var/www/blueprints/chats_explorer.py @@ -80,7 +80,7 @@ def chats_explorer_chat(): return create_json_response(chat[0], chat[1]) else: chat = chat[0] - return render_template('chat_viewer.html', chat=chat) + return render_template('chat_viewer.html', chat=chat, bootstrap_label=bootstrap_label) @chats_explorer.route("/chats/explorer/subchannel", methods=['GET']) @login_required @@ -95,18 +95,6 @@ def objects_subchannel_messages(): subchannel = subchannel[0] return render_template('SubChannelMessages.html', subchannel=subchannel) -@chats_explorer.route("/chats/explorer/subchannel", methods=['GET']) -@login_required -@login_read_only -def objects_message(): - message_id = request.args.get('id') - message = chats_viewer.api_get_message(message_id) - if message[1] != 200: - return create_json_response(message[0], message[1]) - else: - message = message[0] - return render_template('ChatMessage.html', message=message) - ############################################################################################# ############################################################################################# ############################################################################################# diff --git a/var/www/templates/chats_explorer/SubChannelMessages.html b/var/www/templates/chats_explorer/SubChannelMessages.html index 846e9cbd..3d7bf5fb 100644 --- a/var/www/templates/chats_explorer/SubChannelMessages.html +++ b/var/www/templates/chats_explorer/SubChannelMessages.html @@ -32,6 +32,13 @@ flex-direction: row-reverse; margin-left: auto } + .divider:after, + .divider:before { + content: ""; + flex: 1; + height: 2px; + background: #eee; + } @@ -47,7 +54,7 @@
-

{{ subchannel["id"] }} :

+

{% if subchannel['chat']['name'] %}{{ subchannel['chat']['name'] }} {% else %} {{ subchannel['chat']['id'] }}{% endif %} - {% if subchannel['username'] %}{{ subchannel["username"] }} {% else %} {{ subchannel['name'] }}{% endif %} :

{{ subchannel["id"] }}
  • @@ -55,7 +62,8 @@ - + +{# #} @@ -65,10 +73,19 @@ + + - - {% for chat in chat_instance["chats"] %} - + - - + + {% endfor %} diff --git a/var/www/templates/chats_explorer/chat_viewer.html b/var/www/templates/chats_explorer/chat_viewer.html index 97059d95..cde2e9bb 100644 --- a/var/www/templates/chats_explorer/chat_viewer.html +++ b/var/www/templates/chats_explorer/chat_viewer.html @@ -17,6 +17,25 @@ + + @@ -32,11 +51,11 @@
    -

    {{ chat["username"] }} {{ chat["id"] }} :

    +

    {% if chat['username'] %}{{ chat["username"] }} {% else %} {{ chat['name'] }}{% endif %} :

    {{ chat["id"] }}
    Chat InstanceNameChat InstanceFirst seen Last seen Username
    - {{ subchannel["subtype"] }} +{# {{ subchannel["subtype"] }}#} + {{ subchannel['name'] }} + + {% if subchannel['first_seen'] %} + {{ subchannel['first_seen'][0:4] }}-{{ subchannel['first_seen'][4:6] }}-{{ subchannel['first_seen'][6:8] }} + {% endif %} + + {% if subchannel['last_seen'] %} + {{ subchannel['last_seen'][0:4] }}-{{ subchannel['last_seen'][4:6] }}-{{ subchannel['last_seen'][6:8] }} + {% endif %} {{ subchannel['first_seen'] }}{{ subchannel['last_seen'] }} {% if 'username' in subchannel %} {{ subchannel['username'] }} @@ -108,8 +125,8 @@ - {% for tag in mess_tags %} - {{ tag }} {{ mess_tags[tag] }} + {% for tag in subchannel['tags_messages'] %} + {{ tag }} {{ subchannel['tags_messages'][tag] }} {% endfor %}
    @@ -121,10 +138,16 @@
    -
    +
    {% for date in subchannel['messages'] %} -

    {{ date }}

    + +
    +

    + {{ date }} +

    +
    + {% for mess in subchannel['messages'][date] %}
    diff --git a/var/www/templates/chats_explorer/chat_instance.html b/var/www/templates/chats_explorer/chat_instance.html index 5ddbc136..9a32d71d 100644 --- a/var/www/templates/chats_explorer/chat_instance.html +++ b/var/www/templates/chats_explorer/chat_instance.html @@ -75,11 +75,21 @@
    + {{ chat['id'] }} + {{ chat['name'] }} {{ chat['id'] }}{{ chat['first_seen'] }}{{ chat['last_seen'] }} + {% if chat['first_seen'] %} + {{ chat['first_seen'][0:4] }}-{{ chat['first_seen'][4:6] }}-{{ chat['first_seen'][6:8] }} + {% endif %} + + {% if chat['last_seen'] %} + {{ chat['last_seen'][0:4] }}-{{ chat['last_seen'][4:6] }}-{{ chat['last_seen'][6:8] }} + {% endif %} + {{ chat['nb_subchannels'] }}
    - + @@ -51,8 +70,16 @@ - - + + @@ -63,6 +90,10 @@ + {% for tag in chat['tags_messages'] %} + {{ tag }} {{ chat['tags_messages'][tag] }} + {% endfor %} + {% if chat['subchannels'] %}

    Sub-Channels:

    Icon Name {{ chat['name'] }} {{ chat['id'] }}{{ chat['first_seen'] }}{{ chat['last_seen'] }} + {% if chat['first_seen'] %} + {{ chat['first_seen'][0:4] }}-{{ chat['first_seen'][4:6] }}-{{ chat['first_seen'][6:8] }} + {% endif %} + + {% if chat['last_seen'] %} + {{ chat['last_seen'][0:4] }}-{{ chat['last_seen'][4:6] }}-{{ chat['last_seen'][6:8] }} + {% endif %} + {{ chat['nb_subchannels'] }}
    @@ -84,8 +115,16 @@ - - + + {% endfor %} @@ -94,6 +133,74 @@ {% endif %} + {% if chat['messages'] %} + +
    +
    + + {% for date in chat['messages'] %} + +
    +

    + {{ date }} +

    +
    + + {% for mess in chat['messages'][date] %} + +
    +
    + {{ mess['user-account']['id'] }} +
    {{ mess['hour'] }}
    +
    +
    +
    + {% if mess['user-account']['username'] %} + {{ mess['user-account']['username']['id'] }} + {% else %} + {{ mess['user-account']['id'] }} + {% endif %} +
    + {% if mess['reply_to'] %} +
    +
    + {% if mess['reply_to']['user-account']['username'] %} + {{ mess['reply_to']['user-account']['username']['id'] }} + {% else %} + {{ mess['reply_to']['user-account']['id'] }} + {% endif %} +
    +
    {{ mess['reply_to']['content'] }}
    + {% for tag in mess['reply_to']['tags'] %} + {{ tag }} + {% endfor %} +
    {{ mess['reply_to']['date'] }}
    + {#
    #} + {# #} + {# #} + {#
    #} +
    + {% endif %} +
    {{ mess['content'] }}
    + {% for tag in mess['tags'] %} + {{ tag }} + {% endfor %} +
    + + +
    +
    +
    + + {% endfor %} +
    + {% endfor %} + +
    +
    + + {% endif %} +
    {{ meta['name'] }} {{ meta['id'] }}{{ meta['first_seen'] }}{{ meta['last_seen'] }} + {% 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'] }}