comparison libervia/pages/chat/page_meta.py @ 1504:409d10211b20

server, browser: dynamic pages refactoring: dynamic pages has been reworked, to change the initial basic implementation. Pages are now dynamic by default, and a websocket is established by the first connected page of a session. The socket is used to transmit bridge signals, and then the signal is broadcasted to other tabs using broadcast channel. If the connecting tab is closed, an other one is chosen. Some tests are made to retry connecting in case of problem, and sometimes reload the pages (e.g. if profile is connected). Signals (or other data) are cached during reconnection phase, to avoid lost of data. All previous partial rendering mechanism have been removed, chat page is temporarily not working anymore, but will be eventually redone (one of the goal of this work is to have proper chat).
author Goffi <goffi@goffi.org>
date Wed, 01 Mar 2023 18:02:44 +0100
parents 01936fc55cd9
children ce879da7fcf7
comparison
equal deleted inserted replaced
1503:2796e73ed50c 1504:409d10211b20
118 "", 118 "",
119 session.profile, 119 session.profile,
120 ) 120 )
121 else: 121 else:
122 log.warning("unknown message type: {type}".format(type=data_type)) 122 log.warning("unknown message type: {type}".format(type=data_type))
123
124
125 @defer.inlineCallbacks
126 def on_signal(self, request, signal, *args):
127 if signal == "messageNew":
128 rdata = self.getRData(request)
129 template_data_update = {"msg": data_objects.Message((args))}
130 target_jid = rdata["target"]
131 identities = rdata["identities"]
132 uid, timestamp, from_jid_s, to_jid_s, message, subject, mess_type, extra_s, __ = (
133 args
134 )
135 from_jid = jid.JID(from_jid_s)
136 to_jid = jid.JID(to_jid_s)
137 if (
138 target_jid.userhostJID() != from_jid.userhostJID()
139 and target_jid.userhostJID() != to_jid.userhostJID()
140 ):
141 # the message is not linked with page's room/user
142 return
143
144 if from_jid_s not in identities:
145 profile = self.getProfile(request)
146 id_raw = yield self.host.bridgeCall(
147 "identityGet", from_jid_s, [], True, profile
148 )
149 identities[from_jid_s] = data_format.deserialise(id_raw)
150 template_data_update["identities"] = identities
151 self.renderAndUpdate(
152 request, "chat/message.html", "#messages", template_data_update
153 )
154 else:
155 log.error(_("Unexpected signal: {signal}").format(signal=signal))