From c05f4d7833912eee005e616bb39d961b6d017e3c Mon Sep 17 00:00:00 2001 From: terrtia Date: Tue, 2 Jan 2024 17:15:45 +0100 Subject: [PATCH] chg: [chats] get user message ids by chat --- bin/importer/feeders/abstract_chats_feeder.py | 4 +++- bin/lib/correlations_engine.py | 3 +++ bin/lib/objects/UsersAccount.py | 12 ++++++++---- bin/lib/objects/abstract_object.py | 8 +++++++- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/bin/importer/feeders/abstract_chats_feeder.py b/bin/importer/feeders/abstract_chats_feeder.py index a966e951..1dadb970 100755 --- a/bin/importer/feeders/abstract_chats_feeder.py +++ b/bin/importer/feeders/abstract_chats_feeder.py @@ -318,7 +318,7 @@ class AbstractChatFeeder(DefaultFeeder, ABC): message.create('') objs.add(message) - if message.exists(): + if message.exists(): # TODO Correlation user-account image/filename ???? obj = Images.create(self.get_message_content()) obj.add(date, message) obj.set_parent(obj_global_id=message.get_global_id()) @@ -336,6 +336,8 @@ class AbstractChatFeeder(DefaultFeeder, ABC): # TODO get created subchannel + thread # => create correlation user-account with object + print(obj.id) + # CHAT chat_objs = self.process_chat(new_objs, obj, date, timestamp, reply_id=reply_id) diff --git a/bin/lib/correlations_engine.py b/bin/lib/correlations_engine.py index fe37e7fe..378687bf 100755 --- a/bin/lib/correlations_engine.py +++ b/bin/lib/correlations_engine.py @@ -123,6 +123,9 @@ def is_obj_correlated(obj_type, subtype, obj_id, obj2_type, subtype2, obj2_id): except: return False +def get_obj_inter_correlation(obj_type1, subtype1, obj_id1, obj_type2, subtype2, obj_id2, correl_type): + return r_metadata.sinter(f'correlation:obj:{obj_type1}:{subtype1}:{correl_type}:{obj_id1}', f'correlation:obj:{obj_type2}:{subtype2}:{correl_type}:{obj_id2}') + def add_obj_correlation(obj1_type, subtype1, obj1_id, obj2_type, subtype2, obj2_id): if subtype1 is None: subtype1 = '' diff --git a/bin/lib/objects/UsersAccount.py b/bin/lib/objects/UsersAccount.py index 92076f24..2148697a 100755 --- a/bin/lib/objects/UsersAccount.py +++ b/bin/lib/objects/UsersAccount.py @@ -119,6 +119,9 @@ class UserAccount(AbstractSubtypeObject): def update_username_timeline(self, username_global_id, timestamp): self._get_timeline_username().add_timestamp(timestamp, username_global_id) + def get_messages_by_chat_obj(self, chat_obj): + return self.get_correlation_iter_obj(chat_obj, 'message') + def get_meta(self, options=set()): # TODO Username timeline meta = self._get_meta(options=options) meta['id'] = self.id @@ -191,7 +194,8 @@ def get_all_by_subtype(subtype): return get_all_id('user-account', subtype) -# if __name__ == '__main__': -# name_to_search = 'co' -# subtype = 'telegram' -# print(search_usernames_by_name(name_to_search, subtype)) +if __name__ == '__main__': + from lib.objects import Chats + chat = Chats.Chat('', '00098785-7e70-5d12-a120-c5cdc1252b2b') + account = UserAccount('', '00098785-7e70-5d12-a120-c5cdc1252b2b') + print(account.get_messages_by_chat_obj(chat)) diff --git a/bin/lib/objects/abstract_object.py b/bin/lib/objects/abstract_object.py index cac9d58c..d651761f 100755 --- a/bin/lib/objects/abstract_object.py +++ b/bin/lib/objects/abstract_object.py @@ -22,7 +22,7 @@ from lib import ail_logger from lib import Tag from lib.ConfigLoader import ConfigLoader from lib import Duplicate -from lib.correlations_engine import get_nb_correlations, get_correlations, add_obj_correlation, delete_obj_correlation, delete_obj_correlations, exists_obj_correlation, is_obj_correlated, get_nb_correlation_by_correl_type +from lib.correlations_engine import get_nb_correlations, get_correlations, add_obj_correlation, delete_obj_correlation, delete_obj_correlations, exists_obj_correlation, is_obj_correlated, get_nb_correlation_by_correl_type, get_obj_inter_correlation from lib.Investigations import is_object_investigated, get_obj_investigations, delete_obj_investigations from lib.Tracker import is_obj_tracked, get_obj_trackers, delete_obj_trackers @@ -270,6 +270,12 @@ class AbstractObject(ABC): return is_obj_correlated(self.type, self.subtype, self.id, object2.get_type(), object2.get_subtype(r_str=True), object2.get_id()) + def get_correlation_iter(self, obj_type2, subtype2, obj_id2, correl_type): + return get_obj_inter_correlation(self.type, self.get_subtype(r_str=True), self.id, obj_type2, subtype2, obj_id2, correl_type) + + def get_correlation_iter_obj(self, object2, correl_type): + return self.get_correlation_iter(object2.get_type(), object2.get_subtype(r_str=True), object2.get_id(), correl_type) + def delete_correlation(self, type2, subtype2, id2): """ Get object correlations