Skip to content

Commit

Permalink
chg: [user-account] show chats + subchannels
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrtia committed Mar 26, 2024
1 parent 9d481bd commit 3ecd3fd
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 41 deletions.
19 changes: 19 additions & 0 deletions bin/lib/chats_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,23 @@ def get_nb_messages_iterator(filters={}):
nb_messages += chat.get_nb_messages()
return nb_messages

def get_user_account_chats_meta(user_id, chats, subchannels):
meta = []
for chat_g_id in chats:
c_subtype, c_id = chat_g_id.split(':', 1)
chat = Chats.Chat(c_id, c_subtype)
chat_meta = chat.get_meta(options={'icon', 'info', 'nb_participants', 'tags_safe', 'username'})
chat_meta['nb_messages'] = len(chat.get_user_messages(user_id))
chat_meta['subchannels'] = []
for subchannel_gid in chat.get_subchannels():
if subchannel_gid[16:] in subchannels:
_, s_subtype, s_id = subchannel_gid.split(':', 2)
subchannel = ChatSubChannels.ChatSubChannel(s_id, s_subtype)
subchannel_meta = subchannel.get_meta(options={'created_at'})
subchannel_meta['nb_messages'] = len(subchannel.get_user_messages(user_id))
chat_meta['subchannels'].append(subchannel_meta)
meta.append(chat_meta)
return meta

#### FIX ####

Expand Down Expand Up @@ -514,6 +531,8 @@ def api_get_user_account(user_id, instance_uuid, translation_target=None):
if not user_account.exists():
return {"status": "error", "reason": "Unknown user-account"}, 404
meta = user_account.get_meta({'chats', 'icon', 'info', 'subchannels', 'threads', 'translation', 'username', 'username_meta'}, translation_target=translation_target)
if meta['chats']:
meta['chats'] = get_user_account_chats_meta(user_id, meta['chats'], meta['subchannels'])
return meta, 200

def api_chat_messages(subtype, chat_id):
Expand Down
1 change: 1 addition & 0 deletions bin/lib/objects/Chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def get_meta(self, options=set(), translation_target=None):
meta['name'] = self.get_name()
meta['tags'] = self.get_tags(r_list=True)
if 'icon' in options:
meta['svg_icon'] = self.get_svg_icon()
meta['icon'] = self.get_icon()
meta['img'] = meta['icon']
if 'info' in options:
Expand Down
3 changes: 3 additions & 0 deletions bin/lib/objects/abstract_chat_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ def get_participants(self):
def get_nb_participants(self):
return self.get_nb_correlation('user-account')

def get_user_messages(self, user_id):
return self.get_correlation_iter('user-account', self.subtype, user_id, 'message')

# TODO move me to abstract subtype
class AbstractChatObjects(ABC):
def __init__(self, type):
Expand Down
63 changes: 60 additions & 3 deletions var/www/templates/chats_explorer/basic_card_chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h4 class="text-secondary mb-0">
<text x="15" y="15" text-anchor="middle" dominant-baseline="central" class="{{ meta["svg_icon"]["style"] }}" font-size="16px">{{ meta["svg_icon"]["icon"] }}</text>
</g>
</svg>
{% if meta['username'] %}{{ meta["username"]["id"] }} {% else %} {{ meta['name'] }}{% endif %} :
{% if meta['username'] %}{{ meta["username"]["id"] }} {% else %} {{ meta['name'] }}{% endif %} : <small><a href="{{ url_for('chats_explorer.chats_explorer_chat') }}?subtype={{ meta['subtype'] }}&id={{ meta['id'] }}">{{ meta['id'] }}</a></small>
</h4>
</div>
<div class="card-body py-0">
Expand Down Expand Up @@ -46,22 +46,79 @@ <h4 class="text-secondary mb-0">
</span>
<span class="badge badge-dark">
<span class="badge badge-info" style="font-size: 0.8rem;">
<i class="far fa-comments"></i>
</span>
<i class="far fa-comments"></i>
</span>
{{meta["nb_subchannels"]}}&nbsp;&nbsp;
<span class="badge badge-info" style="font-size: 0.8rem;">
<i class="fas fa-user-circle"></i>
</span>
{{meta["nb_participants"]}}
</span>
<span class="badge badge-dark">
<span class="badge badge-info" style="font-size: 0.8rem;">
<i class="fas fa-user-circle"></i>
<i class="far fa-comment-dots"></i>
</span>
{{meta["nb_messages"]}}&nbsp;&nbsp;
</span>
</span>

<div class="">
{{ meta['info'] }}
</div>

<div class="">
{% for tag in meta['tags'] %}
<span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">{{ tag }}</span>
{% endfor %}
</div>

{% if meta['subchannels'] %}
<table id="tablesubchannels" class="table">
<thead class="bg-dark text-white">
<tr>
<th>Name</th>
<th>ID</th>
<th>Created at</th>
<th>First Seen</th>
<th>Last Seen</th>
<th>
<i class="fas fa-user-circle"></i>
<i class="fas fa-comment-dots"></i>
</th>
</tr>
</thead>
<tbody>
{% for meta_s in meta["subchannels"] %}
<tr>
<td>
<b>{{ meta_s['name'] }}</b>
{% if meta_s['translation_name'] %}
<div class="text-secondary">{{ meta_s['translation_name'] }}</div>
{% endif %}
</td>
<td><a href="{{ url_for('chats_explorer.objects_subchannel_messages') }}?subtype={{ meta_s['subtype'] }}&id={{ meta_s['id'] }}">{{ meta_s['id'] }}</a></td>
<td>{{ meta_s['created_at'] }}</td>
<td>
{% if meta_s['first_seen'] %}
{{ meta_s['first_seen'][0:4] }}-{{ meta_s['first_seen'][4:6] }}-{{ meta_s['first_seen'][6:8] }}
{% endif %}
</td>
<td>
{% if meta_s['last_seen'] %}
{{ meta_s['last_seen'][0:4] }}-{{ meta_s['last_seen'][4:6] }}-{{ meta_s['last_seen'][6:8] }}
{% endif %}
</td>
<td>
{{ meta_s['nb_messages'] }}
</td>
</tr>
{% endfor %}
</tbody>
</table>

{% endif %}

</div>
{% include 'objects/block_object_footer_small.html' %}
</div>
48 changes: 10 additions & 38 deletions var/www/templates/chats_explorer/user_account.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,16 @@
{% include 'chats_explorer/block_translation.html' %}
{% endwith %}


{# {% if meta['subchannels'] %}#}
{# <h4>Sub-Channels:</h4>#}
{# <table id="tablesubchannels" class="table">#}
{# <thead class="bg-dark text-white">#}
{# <tr>#}
{# <th></th>#}
{# <th></th>#}
{# <th></th>#}
{# <th></th>#}
{# </tr>#}
{# </thead>#}
{# <tbody style="font-size: 15px;">#}
{# {% for meta in meta["subchannels"] %}#}
{# <tr>#}
{# <td>#}
{# <img src="{{ url_for('static', filename='image/ail-icon.png') }}" class="rounded-circle mr-1" alt="{{ meta['id'] }}" width="40" height="40">#}
{# </td>#}
{# <td><b>{{ meta['name'] }}</b></td>#}
{# <td><a href="{{ url_for('metas_explorer.objects_subchannel_messages') }}?uuid={{ meta['subtype'] }}&id={{ meta['id'] }}">{{ meta['id'] }}</a></td>#}
{# <td>{{ meta['created_at'] }}</td>#}
{# <td>#}
{# {% if meta['first_seen'] %}#}
{# {{ meta['first_seen'][0:4] }}-{{ meta['first_seen'][4:6] }}-{{ meta['first_seen'][6:8] }}#}
{# {% endif %}#}
{# </td>#}
{# <td>#}
{# {% if meta['last_seen'] %}#}
{# {{ meta['last_seen'][0:4] }}-{{ meta['last_seen'][4:6] }}-{{ meta['last_seen'][6:8] }}#}
{# {% endif %}#}
{# </td>#}
{# <td>{{ meta['nb_messages'] }}</td>#}
{# </tr>#}
{# {% endfor %}#}
{# </tbody>#}
{# </table>#}
{##}
{# {% endif %}#}
{% if meta['chats'] %}
<h4>User Chats:</h4>
{% for meta_chats in meta['chats'] %}
<div class="my-2">
{% with meta=meta_chats %}
{% include 'chats_explorer/basic_card_chat.html' %}
{% endwith %}
</div>
{% endfor %}
{% endif %}


</div>
Expand Down

0 comments on commit 3ecd3fd

Please sign in to comment.