mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-10 08:38:28 +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()
|
nb_messages += chat.get_nb_messages()
|
||||||
return 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 ####
|
#### FIX ####
|
||||||
|
|
||||||
|
@ -514,6 +531,8 @@ def api_get_user_account(user_id, instance_uuid, translation_target=None):
|
||||||
if not user_account.exists():
|
if not user_account.exists():
|
||||||
return {"status": "error", "reason": "Unknown user-account"}, 404
|
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)
|
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
|
return meta, 200
|
||||||
|
|
||||||
def api_chat_messages(subtype, chat_id):
|
def api_chat_messages(subtype, chat_id):
|
||||||
|
|
|
@ -75,6 +75,7 @@ class Chat(AbstractChatObject):
|
||||||
meta['name'] = self.get_name()
|
meta['name'] = self.get_name()
|
||||||
meta['tags'] = self.get_tags(r_list=True)
|
meta['tags'] = self.get_tags(r_list=True)
|
||||||
if 'icon' in options:
|
if 'icon' in options:
|
||||||
|
meta['svg_icon'] = self.get_svg_icon()
|
||||||
meta['icon'] = self.get_icon()
|
meta['icon'] = self.get_icon()
|
||||||
meta['img'] = meta['icon']
|
meta['img'] = meta['icon']
|
||||||
if 'info' in options:
|
if 'info' in options:
|
||||||
|
|
|
@ -307,6 +307,9 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
|
||||||
def get_nb_participants(self):
|
def get_nb_participants(self):
|
||||||
return self.get_nb_correlation('user-account')
|
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
|
# TODO move me to abstract subtype
|
||||||
class AbstractChatObjects(ABC):
|
class AbstractChatObjects(ABC):
|
||||||
def __init__(self, type):
|
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>
|
<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>
|
</g>
|
||||||
</svg>
|
</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>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body py-0">
|
<div class="card-body py-0">
|
||||||
|
@ -46,22 +46,79 @@
|
||||||
</span>
|
</span>
|
||||||
<span class="badge badge-dark">
|
<span class="badge badge-dark">
|
||||||
<span class="badge badge-info" style="font-size: 0.8rem;">
|
<span class="badge badge-info" style="font-size: 0.8rem;">
|
||||||
<i class="far fa-comments"></i>
|
<i class="far fa-comments"></i>
|
||||||
</span>
|
</span>
|
||||||
{{meta["nb_subchannels"]}}
|
{{meta["nb_subchannels"]}}
|
||||||
<span class="badge badge-info" style="font-size: 0.8rem;">
|
<span class="badge badge-info" style="font-size: 0.8rem;">
|
||||||
<i class="fas fa-user-circle"></i>
|
<i class="fas fa-user-circle"></i>
|
||||||
</span>
|
</span>
|
||||||
{{meta["nb_participants"]}}
|
{{meta["nb_participants"]}}
|
||||||
</span>
|
</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>
|
</span>
|
||||||
|
|
||||||
|
<div class="">
|
||||||
|
{{ meta['info'] }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="">
|
<div class="">
|
||||||
{% for tag in meta['tags'] %}
|
{% for tag in meta['tags'] %}
|
||||||
<span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">{{ tag }}</span>
|
<span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">{{ tag }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</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>
|
</div>
|
||||||
{% include 'objects/block_object_footer_small.html' %}
|
{% include 'objects/block_object_footer_small.html' %}
|
||||||
</div>
|
</div>
|
|
@ -38,44 +38,16 @@
|
||||||
{% include 'chats_explorer/block_translation.html' %}
|
{% include 'chats_explorer/block_translation.html' %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
||||||
|
{% if meta['chats'] %}
|
||||||
{# {% if meta['subchannels'] %}#}
|
<h4>User Chats:</h4>
|
||||||
{# <h4>Sub-Channels:</h4>#}
|
{% for meta_chats in meta['chats'] %}
|
||||||
{# <table id="tablesubchannels" class="table">#}
|
<div class="my-2">
|
||||||
{# <thead class="bg-dark text-white">#}
|
{% with meta=meta_chats %}
|
||||||
{# <tr>#}
|
{% include 'chats_explorer/basic_card_chat.html' %}
|
||||||
{# <th></th>#}
|
{% endwith %}
|
||||||
{# <th></th>#}
|
</div>
|
||||||
{# <th></th>#}
|
{% endfor %}
|
||||||
{# <th></th>#}
|
{% endif %}
|
||||||
{# </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 %}#}
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue