mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-22 22:27:17 +00:00
fix: [chats] fix messages replies
This commit is contained in:
parent
b1d5399607
commit
3fb1d0ad74
4 changed files with 27 additions and 9 deletions
|
@ -79,6 +79,9 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
|
||||||
def get_thread_id(self):
|
def get_thread_id(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_message_id(self):
|
||||||
|
return self.json_data['meta']['id']
|
||||||
|
|
||||||
def get_message_timestamp(self):
|
def get_message_timestamp(self):
|
||||||
return self.json_data['meta']['date']['timestamp'] # TODO CREATE DEFAULT TIMESTAMP
|
return self.json_data['meta']['date']['timestamp'] # TODO CREATE DEFAULT TIMESTAMP
|
||||||
# if self.json_data['meta'].get('date'):
|
# 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)
|
subchannel = self.process_subchannel(message, date, timestamp, reply_id=reply_id)
|
||||||
chat.add_children(obj_global_id=subchannel.get_global_id())
|
chat.add_children(obj_global_id=subchannel.get_global_id())
|
||||||
else:
|
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
|
# if meta.get('subchannels'): # TODO Update icon + names
|
||||||
|
|
||||||
|
@ -166,7 +169,7 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
|
||||||
if meta.get('info'):
|
if meta.get('info'):
|
||||||
subchannel.set_info(meta['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
|
return subchannel
|
||||||
|
|
||||||
def process_sender(self, date, timestamp):
|
def process_sender(self, date, timestamp):
|
||||||
|
|
|
@ -20,7 +20,7 @@ sys.path.append(os.environ['AIL_BIN'])
|
||||||
from lib.objects.abstract_subtype_object import AbstractSubtypeObject
|
from lib.objects.abstract_subtype_object import AbstractSubtypeObject
|
||||||
from lib.ail_core import get_object_all_subtypes, zscan_iter ################
|
from lib.ail_core import get_object_all_subtypes, zscan_iter ################
|
||||||
from lib.ConfigLoader import ConfigLoader
|
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.UsersAccount import UserAccount
|
||||||
from lib.objects.Usernames import Username
|
from lib.objects.Usernames import Username
|
||||||
from lib.data_retention_engine import update_obj_date
|
from lib.data_retention_engine import update_obj_date
|
||||||
|
@ -127,8 +127,20 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
|
||||||
def _get_messages(self): # TODO paginate
|
def _get_messages(self): # TODO paginate
|
||||||
return r_object.zrange(f'messages:{self.type}:{self.subtype}:{self.id}', 0, -1, withscores=True)
|
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
|
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'})
|
mess_dict = obj.get_meta(options={'content', 'link', 'parent', 'user-account'})
|
||||||
# print(mess_dict)
|
# print(mess_dict)
|
||||||
if mess_dict.get('parent') and parent:
|
if mess_dict.get('parent') and parent:
|
||||||
|
@ -149,8 +161,8 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
|
||||||
mess_dict['user-account'] = {'id': 'UNKNOWN'}
|
mess_dict['user-account'] = {'id': 'UNKNOWN'}
|
||||||
|
|
||||||
if not mess_datetime:
|
if not mess_datetime:
|
||||||
obj_mess_id = message.get_timestamp()
|
obj_mess_id = obj.get_timestamp()
|
||||||
mess_datetime = datetime.fromtimestamp(obj_mess_id)
|
mess_datetime = datetime.fromtimestamp(float(obj_mess_id))
|
||||||
mess_dict['date'] = mess_datetime.isoformat(' ')
|
mess_dict['date'] = mess_datetime.isoformat(' ')
|
||||||
mess_dict['hour'] = mess_datetime.strftime('%H:%M:%S')
|
mess_dict['hour'] = mess_datetime.strftime('%H:%M:%S')
|
||||||
return mess_dict
|
return mess_dict
|
||||||
|
@ -193,7 +205,7 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
|
||||||
def get_cached_message_reply(self, message_id):
|
def get_cached_message_reply(self, message_id):
|
||||||
objs_global_id = []
|
objs_global_id = []
|
||||||
for mess_id in self._get_message_cached_reply(message_id):
|
for mess_id in self._get_message_cached_reply(message_id):
|
||||||
obj_global_id = self.get_obj_by_message_id(mess_id) # TODO CATCH EXCEPTION
|
obj_global_id = self.get_obj_by_message_id(mess_id) # TODO CATCH EXCEPTION
|
||||||
if obj_global_id:
|
if obj_global_id:
|
||||||
objs_global_id.append(obj_global_id)
|
objs_global_id.append(obj_global_id)
|
||||||
return objs_global_id
|
return objs_global_id
|
||||||
|
@ -209,6 +221,9 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
|
||||||
self.add_obj_children(reply_obj, obj_global_id)
|
self.add_obj_children(reply_obj, obj_global_id)
|
||||||
else:
|
else:
|
||||||
self.add_message_cached_reply(reply_id, message_id)
|
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 ????
|
# get_messages_meta ????
|
||||||
|
|
|
@ -169,7 +169,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if mess['reply_to'] %}
|
{% 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">
|
<div class="font-weight-bold mb-1">
|
||||||
{% if mess['reply_to']['user-account']['username'] %}
|
{% if mess['reply_to']['user-account']['username'] %}
|
||||||
{{ mess['reply_to']['user-account']['username']['id'] }}
|
{{ mess['reply_to']['user-account']['username']['id'] }}
|
||||||
|
|
|
@ -167,7 +167,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if mess['reply_to'] %}
|
{% 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">
|
<div class="font-weight-bold mb-1">
|
||||||
{% if mess['reply_to']['user-account']['username'] %}
|
{% if mess['reply_to']['user-account']['username'] %}
|
||||||
{{ mess['reply_to']['user-account']['username']['id'] }}
|
{{ mess['reply_to']['user-account']['username']['id'] }}
|
||||||
|
|
Loading…
Reference in a new issue