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 @@Chat Instance | +Name | +{#Chat Instance | #}First seen | Last seen | Username | @@ -65,10 +73,19 @@
---|---|---|---|---|---|
- {{ 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 @@
- |