diff --git a/bin/importer/feeders/abstract_chats_feeder.py b/bin/importer/feeders/abstract_chats_feeder.py index dfc559b7..21f12d0c 100755 --- a/bin/importer/feeders/abstract_chats_feeder.py +++ b/bin/importer/feeders/abstract_chats_feeder.py @@ -128,6 +128,9 @@ class AbstractChatFeeder(DefaultFeeder, ABC): if meta.get('name'): chat.set_name(meta['name']) + if meta.get('info'): + chat.set_info(meta['info']) + if meta.get('date'): # TODO check if already exists chat.set_created_at(int(meta['date']['timestamp'])) @@ -160,6 +163,9 @@ class AbstractChatFeeder(DefaultFeeder, ABC): subchannel.set_name(meta['name']) # subchannel.update_name(meta['name'], timestamp) # TODO ################# + if meta.get('info'): + subchannel.set_info(meta['info']) + subchannel.add_message(message.get_global_id(), message.id, timestamp, reply_id=reply_id) return subchannel diff --git a/bin/lib/chats_viewer.py b/bin/lib/chats_viewer.py index ef02e0c8..69b9c4af 100755 --- a/bin/lib/chats_viewer.py +++ b/bin/lib/chats_viewer.py @@ -185,6 +185,15 @@ class ChatServiceInstance: def get_chat_service_instances(): return r_obj.smembers(f'chatSerIns:all') +def get_chat_service_instances_by_protocol(protocol): + instance_uuids = {} + for network in r_obj.smembers(f'chat:protocol:networks:{protocol}'): + inst_uuids = r_obj.hvals(f'map:chatSerIns:{protocol}:{network}') + if not network: + network = 'default' + instance_uuids[network] = inst_uuids + return instance_uuids + def get_chat_service_instance_uuid(protocol, network, address): if not network: network = '' @@ -192,6 +201,14 @@ def get_chat_service_instance_uuid(protocol, network, address): address = '' return r_obj.hget(f'map:chatSerIns:{protocol}:{network}', address) +def get_chat_service_instance_uuid_meta_from_network_dict(instance_uuids): + for network in instance_uuids: + metas = [] + for instance_uuid in instance_uuids[network]: + metas.append(ChatServiceInstance(instance_uuid).get_meta()) + instance_uuids[network] = metas + return instance_uuids + def get_chat_service_instance(protocol, network, address): instance_uuid = get_chat_service_instance_uuid(protocol, network, address) if instance_uuid: @@ -280,7 +297,7 @@ def api_get_chat(chat_id, chat_instance_uuid): chat = Chats.Chat(chat_id, chat_instance_uuid) if not chat.exists(): return {"status": "error", "reason": "Unknown chat"}, 404 - meta = chat.get_meta({'img', 'subchannels', 'username'}) + meta = chat.get_meta({'img', 'info', 'subchannels', 'username'}) if meta['subchannels']: meta['subchannels'] = get_subchannels_meta_from_global_id(meta['subchannels']) else: diff --git a/bin/lib/objects/Chats.py b/bin/lib/objects/Chats.py index bf73e95b..f4e3bd72 100755 --- a/bin/lib/objects/Chats.py +++ b/bin/lib/objects/Chats.py @@ -76,6 +76,8 @@ class Chat(AbstractChatObject): meta['tags'] = self.get_tags(r_list=True) if 'img': meta['icon'] = self.get_img() + if 'info': + meta['info'] = self.get_info() if 'username' in options: meta['username'] = self.get_username() if 'subchannels' in options: diff --git a/bin/lib/objects/abstract_chat_object.py b/bin/lib/objects/abstract_chat_object.py index 465bb9e4..a8f4c960 100755 --- a/bin/lib/objects/abstract_chat_object.py +++ b/bin/lib/objects/abstract_chat_object.py @@ -115,6 +115,12 @@ class AbstractChatObject(AbstractSubtypeObject, ABC): def set_img(self, icon): self._set_field('img', icon) + def get_info(self): + return self._get_field('info') + + def set_info(self, info): + self._set_field('info', info) + def get_nb_messages(self): return r_object.zcard(f'messages:{self.type}:{self.subtype}:{self.id}') diff --git a/var/www/blueprints/chats_explorer.py b/var/www/blueprints/chats_explorer.py index 2f122a77..132e5a94 100644 --- a/var/www/blueprints/chats_explorer.py +++ b/var/www/blueprints/chats_explorer.py @@ -57,6 +57,19 @@ def chats_explorer_protocols(): protocols = chats_viewer.get_chat_protocols_meta() return render_template('chats_protocols.html', protocols=protocols) +@chats_explorer.route("chats/explorer/networks", methods=['GET']) +@login_required +@login_read_only +def chats_explorer_networks(): + protocol = request.args.get('protocol') + networks = chats_viewer.get_chat_service_instances_by_protocol(protocol) + if len(networks) == 1: + instance_uuid = list(networks.values())[0] + return redirect(url_for('chats_explorer.chats_explorer_instance', uuid=instance_uuid)) + else: + return render_template('chats_networks.html', protocol=protocol, networks=networks) + + @chats_explorer.route("chats/explorer/instance", methods=['GET']) @login_required @login_read_only @@ -93,7 +106,7 @@ def objects_subchannel_messages(): return create_json_response(subchannel[0], subchannel[1]) else: subchannel = subchannel[0] - return render_template('SubChannelMessages.html', subchannel=subchannel) + return render_template('SubChannelMessages.html', subchannel=subchannel, bootstrap_label=bootstrap_label) ############################################################################################# ############################################################################################# diff --git a/var/www/templates/chats_explorer/SubChannelMessages.html b/var/www/templates/chats_explorer/SubChannelMessages.html index 3d7bf5fb..a21c9065 100644 --- a/var/www/templates/chats_explorer/SubChannelMessages.html +++ b/var/www/templates/chats_explorer/SubChannelMessages.html @@ -98,6 +98,11 @@ + {% if subchannel['info'] %} +
  • +
    {{ subchannel['info'] }}
    +
  • + {% endif %}

  • diff --git a/var/www/templates/chats_explorer/chat_viewer.html b/var/www/templates/chats_explorer/chat_viewer.html index cde2e9bb..e7756137 100644 --- a/var/www/templates/chats_explorer/chat_viewer.html +++ b/var/www/templates/chats_explorer/chat_viewer.html @@ -84,6 +84,11 @@ + {% if chat['info'] %} +
  • +
    {{ chat['info'] }}
    +
  • + {% endif %} diff --git a/var/www/templates/chats_explorer/chats_networks.html b/var/www/templates/chats_explorer/chats_networks.html new file mode 100644 index 00000000..9754e2b0 --- /dev/null +++ b/var/www/templates/chats_explorer/chats_networks.html @@ -0,0 +1,78 @@ + + + + + Chats Protocols - AIL + + + + + + + + + + + + + + + + + + {% include 'nav_bar.html' %} + +
    +
    + + {% include 'sidebars/sidebar_objects.html' %} + +
    + +

    {{ protocol }} Networks:

    + + {% for network in networks %} + + {% endfor %} + +
    + +
    +
    + + + + + + diff --git a/var/www/templates/chats_explorer/chats_protocols.html b/var/www/templates/chats_explorer/chats_protocols.html index f7b56e39..401d2624 100644 --- a/var/www/templates/chats_explorer/chats_protocols.html +++ b/var/www/templates/chats_explorer/chats_protocols.html @@ -29,10 +29,12 @@
    +

    Chats Protocols:

    + {% if protocols %}
    {% for meta in protocols %} - +