chg: [chat viewer] show message forwarded from

This commit is contained in:
terrtia 2024-08-12 12:14:26 +02:00
parent c93bc5937b
commit 8e819f85cd
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
5 changed files with 53 additions and 2 deletions

View file

@ -417,6 +417,18 @@ def get_nb_messages_iterator(filters={}):
nb_messages += chat.get_nb_messages() nb_messages += chat.get_nb_messages()
return 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): def get_user_account_chats_meta(user_id, chats, subchannels):
meta = [] meta = []
for chat_g_id in chats: 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 translation_target = None
if messages: if messages:
meta['messages'], meta['pagination'], meta['tags_messages'] = chat.get_messages(translation_target=translation_target, nb=nb, page=page) 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 return meta, 200
def api_get_nb_message_by_week(chat_type, chat_instance_uuid, chat_id): 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'): if meta.get('username'):
meta['username'] = get_username_meta_from_global_id(meta['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'], 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 return meta, 200
def api_get_thread(thread_id, thread_instance_uuid, translation_target=None, nb=-1, page=-1): 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']: # if meta['chat']:
# meta['chat'] = get_chat_meta_from_global_id(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'], 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 return meta, 200
def api_get_message(message_id, translation_target=None): def api_get_message(message_id, translation_target=None):
message = Messages.Message(message_id) message = Messages.Message(message_id)
if not message.exists(): if not message.exists():
return {"status": "error", "reason": "Unknown uuid"}, 404 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 return meta, 200
def api_message_detect_language(message_id): def api_message_detect_language(message_id):

View file

@ -278,6 +278,10 @@ class Message(AbstractObject):
if parent_type == 'message': if parent_type == 'message':
message = Message(parent_id) message = Message(parent_id)
meta['reply_to'] = message.get_meta(options=options, translation_target=translation_target) 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: if 'investigations' in options:
meta['investigations'] = self.get_investigations() meta['investigations'] = self.get_investigations()
if 'link' in options: if 'link' in options:

View file

@ -226,7 +226,7 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
def get_message_meta(self, message, timestamp=None, translation_target='', options=None): # TODO handle file message def get_message_meta(self, message, timestamp=None, translation_target='', options=None): # TODO handle file message
message = Messages.Message(message[9:]) message = Messages.Message(message[9:])
if not options: 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) meta = message.get_meta(options=options, timestamp=timestamp, translation_target=translation_target)
return meta return meta

View file

@ -302,6 +302,11 @@ class AbstractObject(ABC):
def get_obj_relationships(self, relationships=set(), filter_types=set()): def get_obj_relationships(self, relationships=set(), filter_types=set()):
return get_obj_relationships(self.get_global_id(), relationships=relationships, filter_types=filter_types) 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): def add_relationship(self, obj2_global_id, relationship, source=True):
# is source # is source
if source: if source:

View file

@ -34,6 +34,30 @@
</div> </div>
</div> </div>
<div class="flex-shrink-1 bg-light rounded py-2 px-3 ml-4 pb-4" style="overflow-x: auto"> <div class="flex-shrink-1 bg-light rounded py-2 px-3 ml-4 pb-4" style="overflow-x: auto">
{% if 'forwarded_from' in message %}
<div>
<small class="text-secondary"><i>forwarded from:</i></small>
<div class="card">
<div class="card-header">
<h4 class="text-secondary mb-0">
{% if message['forwarded_from']['icon'] %}
<a href="{{ url_for('chats_explorer.objects_user_account')}}?subtype={{ message['user-account']['subtype'] }}&id={{ message['user-account']['id'] }}">
<img src="{{ url_for('objects_image.image', filename=message['forwarded_from']['icon'])}}" class="rounded-circle mr-1" alt="{{ message['forwarded_from']['id'] }}" width="40" height="40">
</a>
{# {% else %}#}
{# <svg height="30" width="30">#}
{# <g class="nodes">#}
{# <circle cx="15" cy="15" r="15" fill="{{ message['forwarded_from']["svg_icon"]["color"] }}"></circle>#}
{# <text x="15" y="15" text-anchor="middle" dominant-baseline="central" class="{{ message['forwarded_from']["svg_icon"]["style"] }}" font-size="16px">{{ message['forwarded_from']["svg_icon"]["icon"] }}</text>#}
{# </g>#}
{# </svg>#}
{% endif %}
{% if message['forwarded_from']['name'] %}{{ message['forwarded_from']['name'] }}{% endif %} : <small><a href="{{ url_for('chats_explorer.chats_explorer_chat') }}?subtype={{ message['forwarded_from']['subtype'] }}&id={{ message['forwarded_from']['id'] }}">{{ message['forwarded_from']['id'] }}</a></small>
</h4>
</div>
</div>
</div>
{% endif %}
<div class="font-weight-bold mb-1"> <div class="font-weight-bold mb-1">
{% if message['user-account']['username'] %} {% if message['user-account']['username'] %}
{{ message['user-account']['username']['id'] }} {{ message['user-account']['username']['id'] }}