chg: [chat users] add users icons

dev
terrtia 2023-11-24 16:35:45 +01:00
parent 2b8e9b43f3
commit fa4f1269cd
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
3 changed files with 20 additions and 3 deletions

View File

@ -193,7 +193,7 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
subchannel.add_message(obj.get_global_id(), self.get_message_id(), timestamp, reply_id=reply_id) subchannel.add_message(obj.get_global_id(), self.get_message_id(), timestamp, reply_id=reply_id)
return subchannel return subchannel
def process_sender(self, obj, date, timestamp): def process_sender(self, new_objs, obj, date, timestamp):
meta = self.json_data['meta']['sender'] meta = self.json_data['meta']['sender']
user_account = UsersAccount.UserAccount(meta['id'], self.get_chat_instance_uuid()) user_account = UsersAccount.UserAccount(meta['id'], self.get_chat_instance_uuid())
@ -217,6 +217,12 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
if meta.get('phone'): if meta.get('phone'):
user_account.set_phone(meta['phone']) user_account.set_phone(meta['phone'])
if meta.get('icon'):
img = Images.create(meta['icon'], b64=True)
img.add(date, user_account)
user_account.set_icon(img.get_global_id())
new_objs.add(img)
return user_account return user_account
# Create abstract class: -> new API endpoint ??? => force field, check if already imported ? # Create abstract class: -> new API endpoint ??? => force field, check if already imported ?
@ -271,7 +277,7 @@ class AbstractChatFeeder(DefaultFeeder, ABC):
chat = self.process_chat(new_objs, obj, date, timestamp, reply_id=reply_id) chat = self.process_chat(new_objs, obj, date, timestamp, reply_id=reply_id)
# SENDER # TODO HANDLE NULL SENDER # SENDER # TODO HANDLE NULL SENDER
user_account = self.process_sender(obj, date, timestamp) user_account = self.process_sender(new_objs, obj, date, timestamp)
# UserAccount---Chat # UserAccount---Chat
user_account.add_correlation(chat.type, chat.get_subtype(r_str=True), chat.id) user_account.add_correlation(chat.type, chat.get_subtype(r_str=True), chat.id)

View File

@ -83,6 +83,14 @@ class UserAccount(AbstractSubtypeObject):
def set_phone(self, phone): def set_phone(self, phone):
return self._set_field('phone', phone) return self._set_field('phone', phone)
def get_icon(self):
icon = self._get_field('icon')
if icon:
return icon.rsplit(':', 1)[1]
def set_icon(self, icon):
self._set_field('icon', icon)
def _get_timeline_username(self): def _get_timeline_username(self):
return Timeline(self.get_global_id(), 'username') return Timeline(self.get_global_id(), 'username')
@ -107,6 +115,8 @@ class UserAccount(AbstractSubtypeObject):
meta['username'] = Usernames.Username(username_account_id, username_account_subtype).get_meta() meta['username'] = Usernames.Username(username_account_id, username_account_subtype).get_meta()
if 'usernames' in options: if 'usernames' in options:
meta['usernames'] = self.get_usernames() meta['usernames'] = self.get_usernames()
if 'icon' in options:
meta['icon'] = self.get_icon()
return meta return meta
def get_misp_object(self): def get_misp_object(self):

View File

@ -26,7 +26,8 @@
<div class="chat-message-left pb-1"> <div class="chat-message-left pb-1">
<div> <div>
<img src="{{ url_for('static', filename='image/ail-icon.png') }}" class="rounded-circle mr-1" alt="{{ message['user-account']['id'] }}" width="40" height="40"> <img src="{% if message['user-account']['icon'] %}{{ url_for('objects_image.image', filename=message['user-account']['icon'])}}{% else %}{{ url_for('static', filename='image/ail-icon.png') }}{% endif %}"
class="rounded-circle mr-1" alt="{{ message['user-account']['id'] }}" width="40" height="40">
<div class="text-muted small text-nowrap mt-2">{{ message['hour'] }}</div> <div class="text-muted small text-nowrap mt-2">{{ message['hour'] }}</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">