fix: [chats] fix messages replies

dev
terrtia 2023-11-07 11:24:24 +01:00
parent b1d5399607
commit 3fb1d0ad74
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
4 changed files with 27 additions and 9 deletions

View File

@ -79,6 +79,9 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
def get_thread_id(self):
pass
def get_message_id(self):
return self.json_data['meta']['id']
def get_message_timestamp(self):
return self.json_data['meta']['date']['timestamp'] # TODO CREATE DEFAULT TIMESTAMP
# if self.json_data['meta'].get('date'):
@ -142,7 +145,7 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
subchannel = self.process_subchannel(message, date, timestamp, reply_id=reply_id)
chat.add_children(obj_global_id=subchannel.get_global_id())
else:
chat.add_message(message.get_global_id(), message.id, timestamp, reply_id=reply_id)
chat.add_message(message.get_global_id(), self.get_message_id(), timestamp, reply_id=reply_id)
# if meta.get('subchannels'): # TODO Update icon + names
@ -166,7 +169,7 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
if meta.get('info'):
subchannel.set_info(meta['info'])
subchannel.add_message(message.get_global_id(), message.id, timestamp, reply_id=reply_id)
subchannel.add_message(message.get_global_id(), self.get_message_id(), timestamp, reply_id=reply_id)
return subchannel
def process_sender(self, date, timestamp):

View File

@ -20,7 +20,7 @@ sys.path.append(os.environ['AIL_BIN'])
from lib.objects.abstract_subtype_object import AbstractSubtypeObject
from lib.ail_core import get_object_all_subtypes, zscan_iter ################
from lib.ConfigLoader import ConfigLoader
from lib.objects.Messages import Message
from lib.objects import Messages
from lib.objects.UsersAccount import UserAccount
from lib.objects.Usernames import Username
from lib.data_retention_engine import update_obj_date
@ -127,8 +127,20 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
def _get_messages(self): # TODO paginate
return r_object.zrange(f'messages:{self.type}:{self.subtype}:{self.id}', 0, -1, withscores=True)
def get_timestamp_first_message(self):
return r_object.zrange(f'messages:{self.type}:{self.subtype}:{self.id}', 0, 0, withscores=True)
def get_timestamp_last_message(self):
return r_object.zrevrange(f'messages:{self.type}:{self.subtype}:{self.id}', 0, 0, withscores=True)
def get_first_message(self):
return r_object.zrange(f'messages:{self.type}:{self.subtype}:{self.id}', 0, 0)
def get_last_message(self):
return r_object.zrevrange(f'messages:{self.type}:{self.subtype}:{self.id}', 0, 0)
def get_message_meta(self, message, parent=True, mess_datetime=None): # TODO handle file message
obj = Message(message[9:])
obj = Messages.Message(message[9:])
mess_dict = obj.get_meta(options={'content', 'link', 'parent', 'user-account'})
# print(mess_dict)
if mess_dict.get('parent') and parent:
@ -149,8 +161,8 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
mess_dict['user-account'] = {'id': 'UNKNOWN'}
if not mess_datetime:
obj_mess_id = message.get_timestamp()
mess_datetime = datetime.fromtimestamp(obj_mess_id)
obj_mess_id = obj.get_timestamp()
mess_datetime = datetime.fromtimestamp(float(obj_mess_id))
mess_dict['date'] = mess_datetime.isoformat(' ')
mess_dict['hour'] = mess_datetime.strftime('%H:%M:%S')
return mess_dict
@ -209,6 +221,9 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
self.add_obj_children(reply_obj, obj_global_id)
else:
self.add_message_cached_reply(reply_id, message_id)
# CACHED REPLIES
for mess_id in self.get_cached_message_reply(message_id):
self.add_obj_children(obj_global_id, mess_id)
# get_messages_meta ????

View File

@ -169,7 +169,7 @@
{% endif %}
</div>
{% if mess['reply_to'] %}
<div class="flex-shrink-1 border rounded py-2 px-3 ml-4 mb-3" style="overflow-x: auto">
<div class="flex-shrink-1 bg-white border rounded py-2 px-3 ml-4 mb-3" style="overflow-x: auto">
<div class="font-weight-bold mb-1">
{% if mess['reply_to']['user-account']['username'] %}
{{ mess['reply_to']['user-account']['username']['id'] }}

View File

@ -167,7 +167,7 @@
{% endif %}
</div>
{% if mess['reply_to'] %}
<div class="flex-shrink-1 border rounded py-2 px-3 ml-4 mb-3" style="overflow-x: auto">
<div class="flex-shrink-1 bg-white border rounded py-2 px-3 ml-4 mb-3" style="overflow-x: auto">
<div class="font-weight-bold mb-1">
{% if mess['reply_to']['user-account']['username'] %}
{{ mess['reply_to']['user-account']['username']['id'] }}