mirror of https://github.com/CIRCL/AIL-framework
chg: [user message] show user messages by chat
parent
0dfd92bcd6
commit
21642fe9d4
|
@ -328,6 +328,31 @@ def get_username_meta_from_global_id(username_global_id):
|
||||||
username = Usernames.Username(username_id, instance_uuid)
|
username = Usernames.Username(username_id, instance_uuid)
|
||||||
return username.get_meta(options={'icon'})
|
return username.get_meta(options={'icon'})
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# TODO Pagination
|
||||||
|
def list_messages_to_dict(l_messages_id, translation_target=None):
|
||||||
|
options = {'content', 'files-names', 'images', 'language', 'link', 'parent', 'parent_meta', 'reactions', 'thread', 'translation', 'user-account'}
|
||||||
|
meta = {}
|
||||||
|
curr_date = None
|
||||||
|
for mess_id in l_messages_id:
|
||||||
|
message = Messages.Message(mess_id[1:])
|
||||||
|
timestamp = message.get_timestamp()
|
||||||
|
date_day = message.get_date()
|
||||||
|
date_day = f'{date_day[0:4]}/{date_day[4:6]}/{date_day[6:8]}'
|
||||||
|
if date_day != curr_date:
|
||||||
|
meta[date_day] = []
|
||||||
|
curr_date = date_day
|
||||||
|
meta_mess = message.get_meta(options=options, timestamp=timestamp, translation_target=translation_target)
|
||||||
|
meta[date_day].append(meta_mess)
|
||||||
|
|
||||||
|
# if mess_dict.get('tags'):
|
||||||
|
# for tag in mess_dict['tags']:
|
||||||
|
# if tag not in tags:
|
||||||
|
# tags[tag] = 0
|
||||||
|
# tags[tag] += 1
|
||||||
|
# return messages, pagination, tags
|
||||||
|
return meta
|
||||||
|
|
||||||
# TODO Filter
|
# TODO Filter
|
||||||
## Instance type
|
## Instance type
|
||||||
## Chats IDS
|
## Chats IDS
|
||||||
|
@ -354,7 +379,7 @@ def get_messages_iterator(filters={}):
|
||||||
# threads
|
# threads
|
||||||
for threads in chat.get_threads():
|
for threads in chat.get_threads():
|
||||||
thread = ChatThreads.ChatThread(threads['id'], instance_uuid)
|
thread = ChatThreads.ChatThread(threads['id'], instance_uuid)
|
||||||
_, _ = thread._get_messages(nb=-1)
|
messages, _ = thread._get_messages(nb=-1)
|
||||||
for mess in messages:
|
for mess in messages:
|
||||||
message_id, _, message_id = mess[0].split(':', )
|
message_id, _, message_id = mess[0].split(':', )
|
||||||
yield Messages.Message(message_id)
|
yield Messages.Message(message_id)
|
||||||
|
@ -404,6 +429,15 @@ def get_user_account_chats_meta(user_id, chats, subchannels):
|
||||||
meta.append(chat_meta)
|
meta.append(chat_meta)
|
||||||
return meta
|
return meta
|
||||||
|
|
||||||
|
def get_user_account_chat_message(user_id, subtype, chat_id): # TODO subchannel + threads ...
|
||||||
|
meta = {}
|
||||||
|
chat = Chats.Chat(chat_id, subtype)
|
||||||
|
chat_meta = chat.get_meta(options={'icon', 'info', 'nb_participants', 'tags_safe', 'username'})
|
||||||
|
if chat_meta['username']:
|
||||||
|
chat_meta['username'] = get_username_meta_from_global_id(chat_meta['username'])
|
||||||
|
|
||||||
|
meta['messages'] = list_messages_to_dict(chat.get_user_messages(user_id), translation_target=None)
|
||||||
|
return meta
|
||||||
|
|
||||||
def get_user_account_nb_all_week_messages(user_id, chats, subchannels):
|
def get_user_account_nb_all_week_messages(user_id, chats, subchannels):
|
||||||
week = {}
|
week = {}
|
||||||
|
@ -487,12 +521,12 @@ def api_get_chat_service_instance(chat_instance_uuid):
|
||||||
return {"status": "error", "reason": "Unknown uuid"}, 404
|
return {"status": "error", "reason": "Unknown uuid"}, 404
|
||||||
return chat_instance.get_meta({'chats'}), 200
|
return chat_instance.get_meta({'chats'}), 200
|
||||||
|
|
||||||
def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, page=-1):
|
def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, page=-1, messages=True):
|
||||||
chat = Chats.Chat(chat_id, chat_instance_uuid)
|
chat = Chats.Chat(chat_id, chat_instance_uuid)
|
||||||
if not chat.exists():
|
if not chat.exists():
|
||||||
return {"status": "error", "reason": "Unknown chat"}, 404
|
return {"status": "error", "reason": "Unknown chat"}, 404
|
||||||
# print(chat.get_obj_language_stats())
|
# print(chat.get_obj_language_stats())
|
||||||
meta = chat.get_meta({'created_at', 'icon', 'info', 'nb_participants', 'subchannels', 'threads', 'translation', 'username'}, translation_target=translation_target)
|
meta = chat.get_meta({'created_at', 'icon', 'info', 'nb_participants', 'subchannels', 'tags_safe', 'threads', 'translation', 'username'}, translation_target=translation_target)
|
||||||
if meta['username']:
|
if meta['username']:
|
||||||
meta['username'] = get_username_meta_from_global_id(meta['username'])
|
meta['username'] = get_username_meta_from_global_id(meta['username'])
|
||||||
if meta['subchannels']:
|
if meta['subchannels']:
|
||||||
|
@ -500,6 +534,7 @@ def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, pa
|
||||||
else:
|
else:
|
||||||
if translation_target not in Language.get_translation_languages():
|
if translation_target not in Language.get_translation_languages():
|
||||||
translation_target = None
|
translation_target = None
|
||||||
|
if messages:
|
||||||
meta['messages'], meta['pagination'], meta['tags_messages'] = chat.get_messages(translation_target=translation_target, nb=nb, page=page)
|
meta['messages'], meta['pagination'], meta['tags_messages'] = chat.get_messages(translation_target=translation_target, nb=nb, page=page)
|
||||||
return meta, 200
|
return meta, 200
|
||||||
|
|
||||||
|
@ -602,6 +637,18 @@ def api_get_user_account(user_id, instance_uuid, translation_target=None):
|
||||||
meta['chats'] = get_user_account_chats_meta(user_id, meta['chats'], meta['subchannels'])
|
meta['chats'] = get_user_account_chats_meta(user_id, meta['chats'], meta['subchannels'])
|
||||||
return meta, 200
|
return meta, 200
|
||||||
|
|
||||||
|
def api_get_user_account_chat_messages(user_id, instance_uuid, chat_id, translation_target=None):
|
||||||
|
user_account = UsersAccount.UserAccount(user_id, instance_uuid)
|
||||||
|
if not user_account.exists():
|
||||||
|
return {"status": "error", "reason": "Unknown user-account"}, 404
|
||||||
|
meta = get_user_account_chat_message(user_id, instance_uuid, chat_id)
|
||||||
|
meta['user-account'] = user_account.get_meta({'icon', 'info', 'translation', 'username', 'username_meta'}, translation_target=translation_target)
|
||||||
|
resp = api_get_chat(chat_id, instance_uuid, translation_target=translation_target, messages=False)
|
||||||
|
if resp[1] != 200:
|
||||||
|
return resp
|
||||||
|
meta['chat'] = resp[0]
|
||||||
|
return meta, 200
|
||||||
|
|
||||||
def api_get_user_account_nb_all_week_messages(user_id, instance_uuid):
|
def api_get_user_account_nb_all_week_messages(user_id, instance_uuid):
|
||||||
user_account = UsersAccount.UserAccount(user_id, instance_uuid)
|
user_account = UsersAccount.UserAccount(user_id, instance_uuid)
|
||||||
if not user_account.exists():
|
if not user_account.exists():
|
||||||
|
|
|
@ -157,6 +157,7 @@ class UserAccount(AbstractSubtypeObject):
|
||||||
meta['usernames'] = self.get_usernames()
|
meta['usernames'] = self.get_usernames()
|
||||||
if 'icon' in options:
|
if 'icon' in options:
|
||||||
meta['icon'] = self.get_icon()
|
meta['icon'] = self.get_icon()
|
||||||
|
meta['svg_icon'] = meta['icon']
|
||||||
if 'info' in options:
|
if 'info' in options:
|
||||||
meta['info'] = self.get_info()
|
meta['info'] = self.get_info()
|
||||||
if 'translation' in options and translation_target:
|
if 'translation' in options and translation_target:
|
||||||
|
|
|
@ -297,6 +297,26 @@ def objects_user_account():
|
||||||
ail_tags=Tag.get_modal_add_tags(user_account['id'], user_account['type'], user_account['subtype']),
|
ail_tags=Tag.get_modal_add_tags(user_account['id'], user_account['type'], user_account['subtype']),
|
||||||
translation_languages=languages, translation_target=target)
|
translation_languages=languages, translation_target=target)
|
||||||
|
|
||||||
|
@chats_explorer.route("/objects/user-account/chat", methods=['GET'])
|
||||||
|
@login_required
|
||||||
|
@login_read_only
|
||||||
|
def objects_user_account_chat():
|
||||||
|
instance_uuid = request.args.get('subtype')
|
||||||
|
user_id = request.args.get('id')
|
||||||
|
chat_id = request.args.get('chat_id')
|
||||||
|
target = request.args.get('target')
|
||||||
|
if target == "Don't Translate":
|
||||||
|
target = None
|
||||||
|
meta = chats_viewer.api_get_user_account_chat_messages(user_id, instance_uuid, chat_id, translation_target=target)
|
||||||
|
if meta[1] != 200:
|
||||||
|
return create_json_response(meta[0], meta[1])
|
||||||
|
else:
|
||||||
|
meta = meta[0]
|
||||||
|
languages = Language.get_translation_languages()
|
||||||
|
return render_template('chats_explorer/user_chat_messages.html', meta=meta, bootstrap_label=bootstrap_label,
|
||||||
|
ail_tags=Tag.get_modal_add_tags(meta['user-account']['id'], meta['user-account']['type'], meta['user-account']['subtype']),
|
||||||
|
translation_languages=languages, translation_target=target)
|
||||||
|
|
||||||
@chats_explorer.route("objects/user-account/messages/stats/week/all", methods=['GET'])
|
@chats_explorer.route("objects/user-account/messages/stats/week/all", methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
@login_read_only
|
@login_read_only
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
<i class="fas fa-user-circle"></i>
|
<i class="fas fa-user-circle"></i>
|
||||||
<i class="far fa-comment-dots"></i>
|
<i class="far fa-comment-dots"></i>
|
||||||
</span>
|
</span>
|
||||||
{{ meta["nb_messages"] }}
|
<a class="badge-primary px-1 py-0" href="{{ url_for('chats_explorer.objects_user_account_chat') }}?subtype={{ meta['subtype'] }}&id={{ main_obj_id }}&chat_id={{ meta['id'] }}">{{ meta["nb_messages"] }} </a>
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
<h4>User Chats:</h4>
|
<h4>User Chats:</h4>
|
||||||
{% for meta_chats in meta['chats'] %}
|
{% for meta_chats in meta['chats'] %}
|
||||||
<div class="my-2">
|
<div class="my-2">
|
||||||
{% with meta=meta_chats %}
|
{% with meta=meta_chats,main_obj_id=meta['id'] %}
|
||||||
{% include 'chats_explorer/basic_card_chat.html' %}
|
{% include 'chats_explorer/basic_card_chat.html' %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,133 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>User Account - AIL</title>
|
||||||
|
<link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png') }}">
|
||||||
|
|
||||||
|
<!-- Core CSS -->
|
||||||
|
<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
|
||||||
|
<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
|
||||||
|
<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">
|
||||||
|
|
||||||
|
<!-- JS -->
|
||||||
|
<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/d3.min.js')}}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/d3/heatmap_week_hour.js')}}"></script>
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
{% include 'nav_bar.html' %}
|
||||||
|
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
{% include 'sidebars/sidebar_objects.html' %}
|
||||||
|
|
||||||
|
<div class="col-12 col-lg-10" id="core_content">
|
||||||
|
|
||||||
|
<h3>User:</h3>
|
||||||
|
{% with meta=meta['user-account'] %}
|
||||||
|
{% include 'chats_explorer/card_user_account.html' %}
|
||||||
|
{% endwith %}
|
||||||
|
|
||||||
|
<h3>Chat:</h3>
|
||||||
|
{% with meta=meta['chat'] %}
|
||||||
|
{% include 'chats_explorer/basic_card_chat.html' %}
|
||||||
|
{% endwith %}
|
||||||
|
|
||||||
|
<div class="mt-2">
|
||||||
|
{% with translate_url=url_for('chats_explorer.objects_user_account', subtype=meta['subtype']), obj_id=meta['id'] %}
|
||||||
|
{% include 'chats_explorer/block_translation.html' %}
|
||||||
|
{% endwith %}
|
||||||
|
{% include 'objects/image/block_blur_img_slider.html' %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="position-relative">
|
||||||
|
<div class="chat-messages p-2">
|
||||||
|
|
||||||
|
{% for date in meta['messages'] %}
|
||||||
|
|
||||||
|
<div class="divider d-flex align-items-center mb-4">
|
||||||
|
<p class="text-center h2 mx-3 mb-0" style="color: #a2aab7;">
|
||||||
|
<span class="badge badge-secondary mb-2" id="date_section_{{ date }}">{{ date }}</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% for mess in meta['messages'][date] %}
|
||||||
|
|
||||||
|
{% with message=mess %}
|
||||||
|
{% include 'chats_explorer/block_message.html' %}
|
||||||
|
{% endwith %}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
<br>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{# {% if meta['chats'] %}#}
|
||||||
|
{# <h4 class="mx-5 mt-2 text-secondary">User All Messages:</h4>#}
|
||||||
|
{# <div id="heatmapweekhourall"></div>#}
|
||||||
|
{##}
|
||||||
|
{# <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>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(document).ready(function(){
|
||||||
|
$("#page-Decoded").addClass("active");
|
||||||
|
$("#nav_chat").addClass("active");
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
{#d3.json("{{ url_for('chats_explorer.user_account_messages_stats_week_all') }}?subtype={{ meta['subtype'] }}&id={{ meta['id'] }}")#}
|
||||||
|
{# .then(function(data) {#}
|
||||||
|
{# create_heatmap_week_hour('#heatmapweekhourall', data);#}
|
||||||
|
{# })#}
|
||||||
|
|
||||||
|
function toggle_sidebar(){
|
||||||
|
if($('#nav_menu').is(':visible')){
|
||||||
|
$('#nav_menu').hide();
|
||||||
|
$('#side_menu').removeClass('border-right')
|
||||||
|
$('#side_menu').removeClass('col-lg-2')
|
||||||
|
$('#core_content').removeClass('col-lg-10')
|
||||||
|
}else{
|
||||||
|
$('#nav_menu').show();
|
||||||
|
$('#side_menu').addClass('border-right')
|
||||||
|
$('#side_menu').addClass('col-lg-2')
|
||||||
|
$('#core_content').addClass('col-lg-10')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Reference in New Issue