annotate libervia/web/pages/chat/page_meta.py @ 1637:29dd52585984 default tip

tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients: fix 461
author Goffi <goffi@goffi.org>
date Fri, 04 Jul 2025 18:15:48 +0200
parents d4dd4c94463c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1203
diff changeset
1 #!/usr/bin/env python3
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2
1518
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
3 from libervia.backend.core.i18n import _
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from twisted.internet import defer
1518
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
5 from libervia.backend.core.log import getLogger
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
6 from libervia.backend.tools.common import data_objects
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
7 from libervia.backend.tools.common import data_format
1536
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
8 from libervia.frontends.tools import jid
1518
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
9 from libervia.web.server.constants import Const as C
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
10 from libervia.web.server import session_iface
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
1241
921e9f2a97af pages (chat): renamed `extra` argument to `extra_s` as it is now serialised
Goffi <goffi@goffi.org>
parents: 1232
diff changeset
12
921e9f2a97af pages (chat): renamed `extra` argument to `extra_s` as it is now serialised
Goffi <goffi@goffi.org>
parents: 1232
diff changeset
13 log = getLogger(__name__)
921e9f2a97af pages (chat): renamed `extra` argument to `extra_s` as it is now serialised
Goffi <goffi@goffi.org>
parents: 1232
diff changeset
14
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1203
diff changeset
15 name = "chat"
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 access = C.PAGES_ACCESS_PROFILE
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1203
diff changeset
17 template = "chat/chat.html"
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 dynamic = True
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 def parse_url(self, request):
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
22 rdata = self.get_r_data(request)
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 try:
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
25 target_jid_s = self.next_path(request)
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 except IndexError:
1623
fdb5689fb826 browser (chat): Update following template change + some cleaning:
Goffi <goffi@goffi.org>
parents: 1619
diff changeset
27 target_jid_s = self.get_jid(request).userhost()
1619
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
28 # # not chat jid, we redirect to jid selection page
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
29 # self.page_redirect("chat_select", request)
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
30 # return
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 try:
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 target_jid = jid.JID(target_jid_s)
1536
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
34 if not target_jid.local:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1203
diff changeset
35 raise ValueError(_("invalid jid for chat (no local part)"))
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 except Exception as e:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
37 log.warning(
1536
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
38 _("bad chat jid entered: {jid} ({msg})").format(jid=target_jid_s, msg=e)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
39 )
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
40 self.page_error(request, C.HTTP_BAD_REQUEST)
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 else:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
42 rdata["target"] = target_jid
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43
1000
4cc4d49e1d0f pages (chat): moved rendering preparation in prepare_render, and redirect to page_select if no jid is specified.
Goffi <goffi@goffi.org>
parents: 996
diff changeset
44
1536
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
45 async def prepare_render(self, request):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
46 #  FIXME: bug on room filtering (currently display messages from all rooms)
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
47 session = self.host.get_session_data(request, session_iface.IWebSession)
1000
4cc4d49e1d0f pages (chat): moved rendering preparation in prepare_render, and redirect to page_select if no jid is specified.
Goffi <goffi@goffi.org>
parents: 996
diff changeset
48 template_data = request.template_data
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
49 rdata = self.get_r_data(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
50 target_jid = rdata["target"]
1000
4cc4d49e1d0f pages (chat): moved rendering preparation in prepare_render, and redirect to page_select if no jid is specified.
Goffi <goffi@goffi.org>
parents: 996
diff changeset
51 profile = session.profile
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 profile_jid = session.jid
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53
1619
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
54 bookmarks = data_format.deserialise(
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
55 await self.host.bridge_call( "bookmarks_list", "", profile)
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
56 )
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
57
1536
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
58 disco = await self.host.bridge_call(
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
59 "disco_infos", target_jid.domain, "", True, profile
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
60 )
1631
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
61 categories = {i[0] for i in disco[1]}
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
62
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
63 if "gateway" in categories:
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
64 data_policy = data_format.deserialise(await self.host.bridge_call(
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
65 "data_policy_get", target_jid.domain, profile
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
66 ))
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
67 # TODO: Handle services data policies.
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
68 template_data["data_policy"] = data_policy["main"]
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
69 dp_score = data_policy["main"]["score"]
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
70 dp_min = dp_score["minimum"]
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
71 score = (dp_score["score"] - dp_min) / (dp_score["maximum"] - dp_min) * 10
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
72
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
73 template_data["data_policy_score"] = score
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
74
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
75 self.expose_to_scripts(
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
76 request,
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
77 data_policy=data_policy["main"],
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
78 data_policy_score=score
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
79 )
d4dd4c94463c pages (chat): Retrieve Data Policy and generate score:
Goffi <goffi@goffi.org>
parents: 1627
diff changeset
80 if "conference" in categories:
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 chat_type = C.CHAT_GROUP
1536
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
82 join_ret = await self.host.bridge_call(
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
83 "muc_join", target_jid.bare, "", "", profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
84 )
1232
4ccc5bb65be2 pages (chat): handle room statuses following backend change
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
85 (already_joined,
4ccc5bb65be2 pages (chat): handle room statuses following backend change
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
86 room_jid_s,
4ccc5bb65be2 pages (chat): handle room statuses following backend change
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
87 occupants,
4ccc5bb65be2 pages (chat): handle room statuses following backend change
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
88 user_nick,
4ccc5bb65be2 pages (chat): handle room statuses following backend change
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
89 room_subject,
4ccc5bb65be2 pages (chat): handle room statuses following backend change
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
90 room_statuses,
4ccc5bb65be2 pages (chat): handle room statuses following backend change
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
91 __) = join_ret
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1203
diff changeset
92 template_data["subject"] = room_subject
1232
4ccc5bb65be2 pages (chat): handle room statuses following backend change
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
93 template_data["room_statuses"] = room_statuses
1595
7941444c1671 pages: set `own_local_jid` to avoid confusion with `own_jid`:
Goffi <goffi@goffi.org>
parents: 1543
diff changeset
94 own_local_jid = jid.JID(room_jid_s)
7941444c1671 pages: set `own_local_jid` to avoid confusion with `own_jid`:
Goffi <goffi@goffi.org>
parents: 1543
diff changeset
95 own_local_jid = own_local_jid.change_resource(user_nick)
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 else:
1536
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
97 room_subject = None
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 chat_type = C.CHAT_ONE2ONE
1595
7941444c1671 pages: set `own_local_jid` to avoid confusion with `own_jid`:
Goffi <goffi@goffi.org>
parents: 1543
diff changeset
99 own_local_jid = profile_jid
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
100 rdata["chat_type"] = chat_type
1595
7941444c1671 pages: set `own_local_jid` to avoid confusion with `own_jid`:
Goffi <goffi@goffi.org>
parents: 1543
diff changeset
101 template_data["own_local_jid"] = own_local_jid
1627
61449c5ddd70 browser (chat): Show all one2one message when profile own JID is used:
Goffi <goffi@goffi.org>
parents: 1623
diff changeset
102 filters = {}
61449c5ddd70 browser (chat): Show all one2one message when profile own JID is used:
Goffi <goffi@goffi.org>
parents: 1623
diff changeset
103 from_jid_s = profile_jid.userhost()
61449c5ddd70 browser (chat): Show all one2one message when profile own JID is used:
Goffi <goffi@goffi.org>
parents: 1623
diff changeset
104 to_jid_s = target_jid.bare
61449c5ddd70 browser (chat): Show all one2one message when profile own JID is used:
Goffi <goffi@goffi.org>
parents: 1623
diff changeset
105 if from_jid_s == to_jid_s:
61449c5ddd70 browser (chat): Show all one2one message when profile own JID is used:
Goffi <goffi@goffi.org>
parents: 1623
diff changeset
106 # If we are checking messages from user's profile, we show all one2one messages.
61449c5ddd70 browser (chat): Show all one2one message when profile own JID is used:
Goffi <goffi@goffi.org>
parents: 1623
diff changeset
107 to_jid_s = ""
61449c5ddd70 browser (chat): Show all one2one message when profile own JID is used:
Goffi <goffi@goffi.org>
parents: 1623
diff changeset
108 filters = {"not_types": C.CHAT_GROUP}
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109
1536
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
110 history = await self.host.bridge_call(
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
111 "history_get",
1627
61449c5ddd70 browser (chat): Show all one2one message when profile own JID is used:
Goffi <goffi@goffi.org>
parents: 1623
diff changeset
112 from_jid_s,
61449c5ddd70 browser (chat): Show all one2one message when profile own JID is used:
Goffi <goffi@goffi.org>
parents: 1623
diff changeset
113 to_jid_s,
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
114 20,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
115 True,
1627
61449c5ddd70 browser (chat): Show all one2one message when profile own JID is used:
Goffi <goffi@goffi.org>
parents: 1623
diff changeset
116 filters,
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
117 profile,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
118 )
1536
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
119
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120 authors = {m[2] for m in history}
1266
6b7f9c3558cc server, pages: better identities handling:
Goffi <goffi@goffi.org>
parents: 1243
diff changeset
121 identities = session.identities
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 for author in authors:
1536
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
123 id_raw = await self.host.bridge_call(
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
124 "identity_get", author, [], True, profile)
1243
8aff742d0dd0 pages: updated `identityGet` call, following backend changes
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
125 identities[author] = data_format.deserialise(id_raw)
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1203
diff changeset
127 template_data["messages"] = data_objects.Messages(history)
1266
6b7f9c3558cc server, pages: better identities handling:
Goffi <goffi@goffi.org>
parents: 1243
diff changeset
128 rdata['identities'] = identities
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1203
diff changeset
129 template_data["target_jid"] = target_jid
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1203
diff changeset
130 template_data["chat_type"] = chat_type
1619
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
131 template_data["bookmarks"] = bookmarks
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
132 template_data["chat_url"] = self.url
1536
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
133 self.expose_to_scripts(
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
134 request,
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
135 room_subject=room_subject,
1595
7941444c1671 pages: set `own_local_jid` to avoid confusion with `own_jid`:
Goffi <goffi@goffi.org>
parents: 1543
diff changeset
136 own_local_jid=str(own_local_jid),
1536
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
137 target_jid=target_jid,
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
138 chat_type=chat_type,
1619
a2cd4222c702 browser: Updates for new design:
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
139 chat_url=self.url
1536
dc81403a5b2f browser: chat page:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
140 )
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 def on_data(self, request, data):
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
144 session = self.host.get_session_data(request, session_iface.IWebSession)
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
145 rdata = self.get_r_data(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
146 target = rdata["target"]
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1203
diff changeset
147 data_type = data.get("type", "")
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
148 if data_type == "msg":
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1203
diff changeset
149 message = data["body"]
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
150 mess_type = (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
151 C.MESS_TYPE_GROUPCHAT
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
152 if rdata["chat_type"] == C.CHAT_GROUP
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
153 else C.MESS_TYPE_CHAT
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
154 )
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1203
diff changeset
155 log.debug("message received: {}".format(message))
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
156 self.host.bridge_call(
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
157 "message_send",
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
158 target.full(),
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1203
diff changeset
159 {"": message},
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
160 {},
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
161 mess_type,
1429
01936fc55cd9 pages (chat): fix message sending
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
162 "",
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
163 session.profile,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1091
diff changeset
164 )
996
d821c112e656 pages (chat): implementation of chat page using new dynamic pages, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
165 else:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1203
diff changeset
166 log.warning("unknown message type: {type}".format(type=data_type))