Mercurial > libervia-web
diff libervia/web/pages/chat/page_meta.py @ 1536:dc81403a5b2f
browser: chat page:
since the move to Brython, the chat was really basic and not really usable. Now that
dynamism has been re-implemented correctly in the new frontend, a real advanced chat page
can be done. This is the first draft in this direction.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 28 Jun 2023 10:05:13 +0200 |
parents | eb00d593801d |
children | f00497c00e38 |
line wrap: on
line diff
--- a/libervia/web/pages/chat/page_meta.py Thu Jun 22 16:36:18 2023 +0200 +++ b/libervia/web/pages/chat/page_meta.py Wed Jun 28 10:05:13 2023 +0200 @@ -5,7 +5,7 @@ from libervia.backend.core.log import getLogger from libervia.backend.tools.common import data_objects from libervia.backend.tools.common import data_format -from twisted.words.protocols.jabber import jid +from libervia.frontends.tools import jid from libervia.web.server.constants import Const as C from libervia.web.server import session_iface @@ -26,22 +26,22 @@ except IndexError: # not chat jid, we redirect to jid selection page self.page_redirect("chat_select", request) + return try: target_jid = jid.JID(target_jid_s) - if not target_jid.user: + if not target_jid.local: raise ValueError(_("invalid jid for chat (no local part)")) except Exception as e: log.warning( - _("bad chat jid entered: {jid} ({msg})").format(jid=target_jid, msg=e) + _("bad chat jid entered: {jid} ({msg})").format(jid=target_jid_s, msg=e) ) self.page_error(request, C.HTTP_BAD_REQUEST) else: rdata["target"] = target_jid -@defer.inlineCallbacks -def prepare_render(self, request): +async def prepare_render(self, request): # Â FIXME: bug on room filtering (currently display messages from all rooms) session = self.host.get_session_data(request, session_iface.IWebSession) template_data = request.template_data @@ -50,11 +50,13 @@ profile = session.profile profile_jid = session.jid - disco = yield self.host.bridge_call("disco_infos", target_jid.host, "", True, profile) + disco = await self.host.bridge_call( + "disco_infos", target_jid.domain, "", True, profile + ) if "conference" in [i[0] for i in disco[1]]: chat_type = C.CHAT_GROUP - join_ret = yield self.host.bridge_call( - "muc_join", target_jid.userhost(), "", "", profile + join_ret = await self.host.bridge_call( + "muc_join", target_jid.bare, "", "", profile ) (already_joined, room_jid_s, @@ -66,27 +68,28 @@ template_data["subject"] = room_subject template_data["room_statuses"] = room_statuses own_jid = jid.JID(room_jid_s) - own_jid.resource = user_nick + own_jid = own_jid.change_resource(user_nick) else: + room_subject = None chat_type = C.CHAT_ONE2ONE own_jid = profile_jid rdata["chat_type"] = chat_type template_data["own_jid"] = own_jid - self.register_signal(request, "message_new") - history = yield self.host.bridge_call( + history = await self.host.bridge_call( "history_get", profile_jid.userhost(), - target_jid.userhost(), + target_jid.bare, 20, True, {}, profile, ) + authors = {m[2] for m in history} identities = session.identities for author in authors: - id_raw = yield self.host.bridge_call( + id_raw = await self.host.bridge_call( "identity_get", author, [], True, profile) identities[author] = data_format.deserialise(id_raw) @@ -94,6 +97,13 @@ rdata['identities'] = identities template_data["target_jid"] = target_jid template_data["chat_type"] = chat_type + self.expose_to_scripts( + request, + room_subject=room_subject, + own_jid=own_jid, + target_jid=target_jid, + chat_type=chat_type, + ) def on_data(self, request, data):