Skip to content

Commit

Permalink
chg: [chat users] add users icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrtia committed Nov 24, 2023
1 parent 2b8e9b4 commit fa4f126
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 8 additions & 2 deletions bin/importer/feeders/abstract_chats_feeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def process_subchannel(self, obj, date, timestamp, reply_id=None): # TODO CREAT
subchannel.add_message(obj.get_global_id(), self.get_message_id(), timestamp, reply_id=reply_id)
return subchannel

def process_sender(self, obj, date, timestamp):
def process_sender(self, new_objs, obj, date, timestamp):
meta = self.json_data['meta']['sender']
user_account = UsersAccount.UserAccount(meta['id'], self.get_chat_instance_uuid())

Expand All @@ -217,6 +217,12 @@ def process_sender(self, obj, date, timestamp):
if meta.get('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

# Create abstract class: -> new API endpoint ??? => force field, check if already imported ?
Expand Down Expand Up @@ -271,7 +277,7 @@ def process_meta(self): # TODO CHECK MANDATORY FIELDS
chat = self.process_chat(new_objs, obj, date, timestamp, reply_id=reply_id)

# 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
user_account.add_correlation(chat.type, chat.get_subtype(r_str=True), chat.id)
Expand Down
10 changes: 10 additions & 0 deletions bin/lib/objects/UsersAccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ def set_last_name(self, lastname):
def set_phone(self, 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):
return Timeline(self.get_global_id(), 'username')

Expand All @@ -107,6 +115,8 @@ def get_meta(self, options=set()):
meta['username'] = Usernames.Username(username_account_id, username_account_subtype).get_meta()
if 'usernames' in options:
meta['usernames'] = self.get_usernames()
if 'icon' in options:
meta['icon'] = self.get_icon()
return meta

def get_misp_object(self):
Expand Down
3 changes: 2 additions & 1 deletion var/www/templates/chats_explorer/block_message.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

<div class="chat-message-left pb-1">
<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>
<div class="flex-shrink-1 bg-light rounded py-2 px-3 ml-4 pb-4" style="overflow-x: auto">
Expand Down

0 comments on commit fa4f126

Please sign in to comment.