mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-26 15:57:16 +00:00
chg: [user-account] show chats + subchannels
This commit is contained in:
parent
9d481bd0b0
commit
3ecd3fd023
5 changed files with 93 additions and 41 deletions
|
@ -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 ####
|
||||
|
||||
|
@ -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):
|
||||
|
|
|
@ -75,6 +75,7 @@ class Chat(AbstractChatObject):
|
|||
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:
|
||||
|
|
|
@ -307,6 +307,9 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
|
|||
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):
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<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">
|
||||
|
@ -54,7 +54,18 @@
|
|||
</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"]}}
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<div class="">
|
||||
{{ meta['info'] }}
|
||||
</div>
|
||||
|
||||
<div class="">
|
||||
{% for tag in meta['tags'] %}
|
||||
|
@ -62,6 +73,52 @@
|
|||
{% 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>
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue