diff --git a/bin/lib/chats_viewer.py b/bin/lib/chats_viewer.py index c4acb96c..3584a04f 100755 --- a/bin/lib/chats_viewer.py +++ b/bin/lib/chats_viewer.py @@ -417,6 +417,18 @@ def get_nb_messages_iterator(filters={}): nb_messages += chat.get_nb_messages() return nb_messages +def get_chat_object_messages_forward_meta(c_messages): + temp_chats = {} + for date in c_messages: + for meta in c_messages[date]: + if 'forwarded_from' in meta: + if meta['forwarded_from'] not in temp_chats: + chat = get_obj_chat_from_global_id(meta['forwarded_from']) + temp_chats[meta['forwarded_from']] = chat.get_meta({'icon'}) + else: + meta['forwarded_from'] = temp_chats[meta['forwarded_from']] + return c_messages + def get_user_account_chats_meta(user_id, chats, subchannels): meta = [] for chat_g_id in chats: @@ -683,6 +695,7 @@ def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, pa translation_target = None if messages: meta['messages'], meta['pagination'], meta['tags_messages'] = chat.get_messages(translation_target=translation_target, nb=nb, page=page) + meta['messages'] = get_chat_object_messages_forward_meta(meta['messages']) return meta, 200 def api_get_nb_message_by_week(chat_type, chat_instance_uuid, chat_id): @@ -728,6 +741,7 @@ def api_get_subchannel(chat_id, chat_instance_uuid, translation_target=None, nb= if meta.get('username'): meta['username'] = get_username_meta_from_global_id(meta['username']) meta['messages'], meta['pagination'], meta['tags_messages'] = subchannel.get_messages(translation_target=translation_target, nb=nb, page=page) + meta['messages'] = get_chat_object_messages_forward_meta(meta['messages']) return meta, 200 def api_get_thread(thread_id, thread_instance_uuid, translation_target=None, nb=-1, page=-1): @@ -739,13 +753,17 @@ def api_get_thread(thread_id, thread_instance_uuid, translation_target=None, nb= # if meta['chat']: # meta['chat'] = get_chat_meta_from_global_id(meta['chat']) meta['messages'], meta['pagination'], meta['tags_messages'] = thread.get_messages(translation_target=translation_target, nb=nb, page=page) + meta['messages'] = get_chat_object_messages_forward_meta(meta['messages']) return meta, 200 def api_get_message(message_id, translation_target=None): message = Messages.Message(message_id) if not message.exists(): return {"status": "error", "reason": "Unknown uuid"}, 404 - meta = message.get_meta({'chat', 'content', 'files-names', 'icon', 'images', 'language', 'link', 'parent', 'parent_meta', 'reactions', 'thread', 'translation', 'user-account'}, translation_target=translation_target) + meta = message.get_meta({'chat', 'content', 'files-names', 'forwarded_from', 'icon', 'images', 'language', 'link', 'parent', 'parent_meta', 'reactions', 'thread', 'translation', 'user-account'}, translation_target=translation_target) + if 'forwarded_from' in meta: + chat = get_obj_chat_from_global_id(meta['forwarded_from']) + meta['forwarded_from'] = chat.get_meta({'icon'}) return meta, 200 def api_message_detect_language(message_id): diff --git a/bin/lib/objects/Messages.py b/bin/lib/objects/Messages.py index 104553b0..be75b4d1 100755 --- a/bin/lib/objects/Messages.py +++ b/bin/lib/objects/Messages.py @@ -278,6 +278,10 @@ class Message(AbstractObject): if parent_type == 'message': message = Message(parent_id) meta['reply_to'] = message.get_meta(options=options, translation_target=translation_target) + if 'forwarded_from' in options: + fwd_from = self.get_first_relationship('forwarded_from', 'chat') + if fwd_from: + meta['forwarded_from'] = fwd_from['id'] if 'investigations' in options: meta['investigations'] = self.get_investigations() if 'link' in options: diff --git a/bin/lib/objects/abstract_chat_object.py b/bin/lib/objects/abstract_chat_object.py index b5562fb2..34e87e55 100755 --- a/bin/lib/objects/abstract_chat_object.py +++ b/bin/lib/objects/abstract_chat_object.py @@ -226,7 +226,7 @@ class AbstractChatObject(AbstractSubtypeObject, ABC): def get_message_meta(self, message, timestamp=None, translation_target='', options=None): # TODO handle file message message = Messages.Message(message[9:]) if not options: - options = {'content', 'files-names', 'images', 'language', 'link', 'parent', 'parent_meta', 'reactions', 'thread', 'translation', 'user-account'} + options = {'content', 'files-names', 'forwarded_from', 'images', 'language', 'link', 'parent', 'parent_meta', 'reactions', 'thread', 'translation', 'user-account'} meta = message.get_meta(options=options, timestamp=timestamp, translation_target=translation_target) return meta diff --git a/bin/lib/objects/abstract_object.py b/bin/lib/objects/abstract_object.py index 2203ead0..42c8f0ad 100755 --- a/bin/lib/objects/abstract_object.py +++ b/bin/lib/objects/abstract_object.py @@ -302,6 +302,11 @@ class AbstractObject(ABC): def get_obj_relationships(self, relationships=set(), filter_types=set()): return get_obj_relationships(self.get_global_id(), relationships=relationships, filter_types=filter_types) + def get_first_relationship(self, relationship, filter_type): + rel = get_obj_relationships(self.get_global_id(), relationships={relationship}, filter_types={filter_type}) + if rel: + return rel.pop() + def add_relationship(self, obj2_global_id, relationship, source=True): # is source if source: diff --git a/var/www/templates/chats_explorer/block_message.html b/var/www/templates/chats_explorer/block_message.html index d8d1c1e2..2bc16a32 100644 --- a/var/www/templates/chats_explorer/block_message.html +++ b/var/www/templates/chats_explorer/block_message.html @@ -34,6 +34,30 @@
+ {% if 'forwarded_from' in message %} +
+ forwarded from: +
+
+

+ {% if message['forwarded_from']['icon'] %} + + {{ message['forwarded_from']['id'] }} + +{# {% else %}#} +{# #} +{# #} +{# #} +{# {{ message['forwarded_from']["svg_icon"]["icon"] }}#} +{# #} +{# #} + {% endif %} + {% if message['forwarded_from']['name'] %}{{ message['forwarded_from']['name'] }}{% endif %} : {{ message['forwarded_from']['id'] }} +

+
+
+
+ {% endif %}
{% if message['user-account']['username'] %} {{ message['user-account']['username']['id'] }}