mirror of https://github.com/CIRCL/AIL-framework
chg: [chats explorer] filter Chats that don't contain messages
parent
c7204d5bbd
commit
5c0b80405c
|
@ -229,12 +229,15 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
|
|||
if meta.get('subchannel'):
|
||||
subchannel, thread = self.process_subchannel(obj, date, timestamp, reply_id=reply_id)
|
||||
chat.add_children(obj_global_id=subchannel.get_global_id())
|
||||
if obj.type == 'message':
|
||||
chat.add_chat_with_messages()
|
||||
else:
|
||||
if obj.type == 'message':
|
||||
if self.get_thread_id():
|
||||
thread = self.process_thread(obj, chat, date, timestamp, reply_id=reply_id)
|
||||
else:
|
||||
chat.add_message(obj.get_global_id(), self.get_message_id(), timestamp, reply_id=reply_id)
|
||||
chat.add_chat_with_messages()
|
||||
|
||||
chats_obj = [chat]
|
||||
if subchannel:
|
||||
|
|
|
@ -180,6 +180,11 @@ class ChatServiceInstance:
|
|||
meta['chats'] = []
|
||||
for chat_id in self.get_chats():
|
||||
meta['chats'].append(Chats.Chat(chat_id, self.uuid).get_meta({'created_at', 'icon', 'nb_subchannels', 'nb_messages'}))
|
||||
if 'chats_with_messages':
|
||||
meta['chats'] = []
|
||||
for chat_id in self.get_chats_with_messages():
|
||||
meta['chats'].append(
|
||||
Chats.Chat(chat_id, self.uuid).get_meta({'created_at', 'icon', 'nb_subchannels', 'nb_messages'}))
|
||||
return meta
|
||||
|
||||
def get_nb_chats(self):
|
||||
|
@ -188,6 +193,9 @@ class ChatServiceInstance:
|
|||
def get_chats(self):
|
||||
return Chats.Chats().get_ids_by_subtype(self.uuid)
|
||||
|
||||
def get_chats_with_messages(self):
|
||||
return Chats.Chats().get_ids_with_messages_by_subtype(self.uuid)
|
||||
|
||||
def get_chat_service_instances():
|
||||
return r_obj.smembers(f'chatSerIns:all')
|
||||
|
||||
|
@ -583,6 +591,23 @@ def fix_correlations_subchannel_message():
|
|||
_, _, message_id = mess[0].split(':', )
|
||||
subchannel.add_correlation('message', '', message_id)
|
||||
|
||||
def fix_chats_with_messages():
|
||||
for instance_uuid in get_chat_service_instances():
|
||||
for chat_id in ChatServiceInstance(instance_uuid).get_chats():
|
||||
chat = Chats.Chat(chat_id, instance_uuid)
|
||||
|
||||
messages = chat.get_nb_messages()
|
||||
if messages > 0:
|
||||
chat.add_chat_with_messages()
|
||||
continue
|
||||
|
||||
for subchannel_gid in chat.get_subchannels():
|
||||
_, _, subchannel_id = subchannel_gid.split(':', 2)
|
||||
subchannel = ChatSubChannels.ChatSubChannel(subchannel_id, instance_uuid)
|
||||
if subchannel.get_nb_messages() > 0:
|
||||
chat.add_chat_with_messages()
|
||||
break
|
||||
|
||||
#### API ####
|
||||
|
||||
def get_chat_user_account_label(chat_gid):
|
||||
|
@ -636,7 +661,8 @@ def api_get_chat_service_instance(chat_instance_uuid):
|
|||
chat_instance = ChatServiceInstance(chat_instance_uuid)
|
||||
if not chat_instance.exists():
|
||||
return {"status": "error", "reason": "Unknown uuid"}, 404
|
||||
return chat_instance.get_meta({'chats'}), 200
|
||||
# return chat_instance.get_meta({'chats'}), 200
|
||||
return chat_instance.get_meta({'chats_with_messages'}), 200
|
||||
|
||||
def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, page=-1, messages=True):
|
||||
chat = Chats.Chat(chat_id, chat_instance_uuid)
|
||||
|
|
|
@ -203,6 +203,12 @@ class Chats(AbstractChatObjects):
|
|||
def __init__(self):
|
||||
super().__init__('chat')
|
||||
|
||||
def get_ids_with_messages_by_subtype(self, subtype):
|
||||
return r_object.smembers(f'{self.type}_w_mess:{subtype}')
|
||||
|
||||
# def get_ids_with_messages_iter(self, subtype):
|
||||
# return sscan_iter(r_object, f'{self.type}_w_mess:{subtype}')
|
||||
|
||||
# TODO factorize
|
||||
def get_all_subtypes():
|
||||
return ail_core.get_object_all_subtypes('chat')
|
||||
|
|
|
@ -284,6 +284,9 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
|
|||
objs_global_id.append(obj_global_id)
|
||||
return objs_global_id
|
||||
|
||||
def add_chat_with_messages(self):
|
||||
r_object.sadd(f'{self.type}_w_mess:{self.subtype}', self.id)
|
||||
|
||||
def add_message(self, obj_global_id, message_id, timestamp, reply_id=None):
|
||||
r_object.hset(f'messages:ids:{self.type}:{self.subtype}:{self.id}', message_id, obj_global_id)
|
||||
r_object.zadd(f'messages:{self.type}:{self.subtype}:{self.id}', {obj_global_id: float(timestamp)})
|
||||
|
|
|
@ -13,7 +13,7 @@ sys.path.append(os.environ['AIL_HOME'])
|
|||
from update.bin.ail_updater import AIL_Updater
|
||||
from lib import ail_users
|
||||
from lib.ConfigLoader import ConfigLoader
|
||||
|
||||
from lib import chats_viewer
|
||||
|
||||
class Updater(AIL_Updater):
|
||||
"""default Updater."""
|
||||
|
@ -33,6 +33,8 @@ if __name__ == '__main__':
|
|||
r_serv_db.hset(f'ail:user:metadata:{user_id}', 'created_at', date)
|
||||
r_serv_db.hset(f'ail:user:metadata:{user_id}', 'last_edit', date)
|
||||
|
||||
chats_viewer.fix_chats_with_messages()
|
||||
|
||||
updater = Updater('v5.7')
|
||||
updater.run_update()
|
||||
|
||||
|
|
Loading…
Reference in New Issue