diff --git a/bin/lib/chats_viewer.py b/bin/lib/chats_viewer.py
index 491f315f..6a910172 100755
--- a/bin/lib/chats_viewer.py
+++ b/bin/lib/chats_viewer.py
@@ -23,6 +23,7 @@ from lib.objects import Chats
from lib.objects import ChatSubChannels
from lib.objects import ChatThreads
from lib.objects import Messages
+from lib.objects.QrCodes import Qrcode
from lib.objects import UsersAccount
from lib.objects import Usernames
from lib import Language
@@ -418,7 +419,7 @@ def get_nb_messages_iterator(filters={}):
nb_messages += chat.get_nb_messages()
return nb_messages
-def get_chat_object_messages_forward_meta(c_messages):
+def get_chat_object_messages_meta(c_messages):
temp_chats = {}
for date in c_messages:
for meta in c_messages[date]:
@@ -428,6 +429,12 @@ def get_chat_object_messages_forward_meta(c_messages):
temp_chats[meta['forwarded_from']] = chat.get_meta({'icon'})
else:
meta['forwarded_from'] = temp_chats[meta['forwarded_from']]
+ if meta['qrcodes']:
+ qrcodes = []
+ for q in meta['qrcodes']:
+ qr = Qrcode(q)
+ qrcodes.append({'id': qr.id, 'content': qr.get_content(), 'tags': qr.get_tags()})
+ meta['qrcodes'] = qrcodes
return c_messages
def get_user_account_chats_meta(user_id, chats, subchannels):
@@ -754,7 +761,7 @@ def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, pa
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'] = get_chat_object_messages_forward_meta(meta['messages'])
+ meta['messages'] = get_chat_object_messages_meta(meta['messages'])
return meta, 200
def api_get_nb_message_by_week(chat_type, chat_instance_uuid, chat_id):
@@ -800,7 +807,7 @@ def api_get_subchannel(chat_id, chat_instance_uuid, translation_target=None, nb=
if meta.get('username'):
meta['username'] = get_username_meta_from_global_id(meta['username'])
meta['messages'], meta['pagination'], meta['tags_messages'] = subchannel.get_messages(translation_target=translation_target, nb=nb, page=page)
- meta['messages'] = get_chat_object_messages_forward_meta(meta['messages'])
+ meta['messages'] = get_chat_object_messages_meta(meta['messages'])
return meta, 200
def api_get_thread(thread_id, thread_instance_uuid, translation_target=None, nb=-1, page=-1):
@@ -812,17 +819,22 @@ def api_get_thread(thread_id, thread_instance_uuid, translation_target=None, nb=
# if meta['chat']:
# meta['chat'] = get_chat_meta_from_global_id(meta['chat'])
meta['messages'], meta['pagination'], meta['tags_messages'] = thread.get_messages(translation_target=translation_target, nb=nb, page=page)
- meta['messages'] = get_chat_object_messages_forward_meta(meta['messages'])
+ meta['messages'] = get_chat_object_messages_meta(meta['messages'])
return meta, 200
def api_get_message(message_id, translation_target=None):
message = Messages.Message(message_id)
if not message.exists():
return {"status": "error", "reason": "Unknown uuid"}, 404
- meta = message.get_meta({'chat', 'content', 'files-names', 'forwarded_from', 'icon', 'images', 'language', 'link', 'parent', 'parent_meta', 'reactions', 'thread', 'translation', 'user-account'}, translation_target=translation_target)
+ meta = message.get_meta({'chat', 'content', 'files-names', 'forwarded_from', 'icon', 'images', 'language', 'link', 'parent', 'parent_meta', 'qrcodes', 'reactions', 'thread', 'translation', 'user-account'}, translation_target=translation_target)
if 'forwarded_from' in meta:
chat = get_obj_chat_from_global_id(meta['forwarded_from'])
meta['forwarded_from'] = chat.get_meta({'icon'})
+ qrcodes = []
+ for q in meta['qrcodes']:
+ qr = Qrcode(q)
+ qrcodes.append({'id': qr.id, 'content': qr.get_content(), 'tags': qr.get_tags()})
+ meta['qrcodes'] = qrcodes
return meta, 200
def api_message_detect_language(message_id):
diff --git a/bin/lib/objects/Messages.py b/bin/lib/objects/Messages.py
index be75b4d1..ee4879db 100755
--- a/bin/lib/objects/Messages.py
+++ b/bin/lib/objects/Messages.py
@@ -151,6 +151,12 @@ class Message(AbstractObject):
images.append({'id': obj_id, 'ocr': self._get_image_ocr(obj_id)})
return images
+ def get_qrcodes(self):
+ qrcodes = []
+ for c in self.get_correlation('qrcode').get('qrcode', []):
+ qrcodes.append(c[1:])
+ return qrcodes
+
def get_user_account(self, meta=False):
user_account = self.get_correlation('user-account')
if user_account.get('user-account'):
@@ -300,6 +306,8 @@ class Message(AbstractObject):
meta['thread'] = thread
if 'images' in options:
meta['images'] = self.get_images()
+ if 'qrcodes' in options:
+ meta['qrcodes'] = self.get_qrcodes()
if 'files-names' in options:
meta['files-names'] = self.get_files_names()
if 'reactions' in options:
diff --git a/bin/lib/objects/abstract_chat_object.py b/bin/lib/objects/abstract_chat_object.py
index 34e87e55..7f449205 100755
--- a/bin/lib/objects/abstract_chat_object.py
+++ b/bin/lib/objects/abstract_chat_object.py
@@ -226,7 +226,7 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
def get_message_meta(self, message, timestamp=None, translation_target='', options=None): # TODO handle file message
message = Messages.Message(message[9:])
if not options:
- options = {'content', 'files-names', 'forwarded_from', 'images', 'language', 'link', 'parent', 'parent_meta', 'reactions', 'thread', 'translation', 'user-account'}
+ options = {'content', 'files-names', 'forwarded_from', 'images', 'language', 'link', 'parent', 'parent_meta', 'qrcodes', 'reactions', 'thread', 'translation', 'user-account'}
meta = message.get_meta(options=options, timestamp=timestamp, translation_target=translation_target)
return meta
diff --git a/var/www/blueprints/objects_qrcode.py b/var/www/blueprints/objects_qrcode.py
index 1061aee9..747f065c 100644
--- a/var/www/blueprints/objects_qrcode.py
+++ b/var/www/blueprints/objects_qrcode.py
@@ -80,7 +80,7 @@ def objects_qrcodes_range_json():
return jsonify(QrCodes.Qrcodes().api_get_chart_nb_by_daterange(date_from, date_to))
-@objects_qrcode.route("/objects/qrcodes", methods=['GET'])
+@objects_qrcode.route("/objects/qrcode", methods=['GET'])
@login_required
@login_read_only
def object_qrcode():
@@ -90,11 +90,9 @@ def object_qrcode():
return create_json_response(meta[0], meta[1])
else:
meta = meta[0]
- languages = Language.get_translation_languages()
return render_template("ShowQrcode.html", meta=meta,
bootstrap_label=bootstrap_label,
- ail_tags=Tag.get_modal_add_tags(meta['id'], meta['type'], meta['subtype']),
- translation_languages=languages, translation_target=target)
+ ail_tags=Tag.get_modal_add_tags(meta['id'], meta['type'], meta['subtype']))
# ============= ROUTES ==============
diff --git a/var/www/templates/chats_explorer/block_message.html b/var/www/templates/chats_explorer/block_message.html
index 394d8255..849b8bc7 100644
--- a/var/www/templates/chats_explorer/block_message.html
+++ b/var/www/templates/chats_explorer/block_message.html
@@ -97,6 +97,21 @@
OCR
{% endif %}
+ {% if message['qrcodes'] %}
+ {% for qrcode in message['qrcodes'] %}
+
+
+ {{ qrcode['content'] }}
+