Mercurial > libervia-web
comparison libervia/pages/chat/page_meta.py @ 1509:106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:44:11 +0200 |
parents | ce879da7fcf7 |
children |
comparison
equal
deleted
inserted
replaced
1508:ec3ad9abf9f9 | 1509:106bae41f5c8 |
---|---|
17 template = "chat/chat.html" | 17 template = "chat/chat.html" |
18 dynamic = True | 18 dynamic = True |
19 | 19 |
20 | 20 |
21 def parse_url(self, request): | 21 def parse_url(self, request): |
22 rdata = self.getRData(request) | 22 rdata = self.get_r_data(request) |
23 | 23 |
24 try: | 24 try: |
25 target_jid_s = self.nextPath(request) | 25 target_jid_s = self.next_path(request) |
26 except IndexError: | 26 except IndexError: |
27 # not chat jid, we redirect to jid selection page | 27 # not chat jid, we redirect to jid selection page |
28 self.pageRedirect("chat_select", request) | 28 self.page_redirect("chat_select", request) |
29 | 29 |
30 try: | 30 try: |
31 target_jid = jid.JID(target_jid_s) | 31 target_jid = jid.JID(target_jid_s) |
32 if not target_jid.user: | 32 if not target_jid.user: |
33 raise ValueError(_("invalid jid for chat (no local part)")) | 33 raise ValueError(_("invalid jid for chat (no local part)")) |
34 except Exception as e: | 34 except Exception as e: |
35 log.warning( | 35 log.warning( |
36 _("bad chat jid entered: {jid} ({msg})").format(jid=target_jid, msg=e) | 36 _("bad chat jid entered: {jid} ({msg})").format(jid=target_jid, msg=e) |
37 ) | 37 ) |
38 self.pageError(request, C.HTTP_BAD_REQUEST) | 38 self.page_error(request, C.HTTP_BAD_REQUEST) |
39 else: | 39 else: |
40 rdata["target"] = target_jid | 40 rdata["target"] = target_jid |
41 | 41 |
42 | 42 |
43 @defer.inlineCallbacks | 43 @defer.inlineCallbacks |
44 def prepare_render(self, request): | 44 def prepare_render(self, request): |
45 # FIXME: bug on room filtering (currently display messages from all rooms) | 45 # FIXME: bug on room filtering (currently display messages from all rooms) |
46 session = self.host.getSessionData(request, session_iface.IWebSession) | 46 session = self.host.get_session_data(request, session_iface.IWebSession) |
47 template_data = request.template_data | 47 template_data = request.template_data |
48 rdata = self.getRData(request) | 48 rdata = self.get_r_data(request) |
49 target_jid = rdata["target"] | 49 target_jid = rdata["target"] |
50 profile = session.profile | 50 profile = session.profile |
51 profile_jid = session.jid | 51 profile_jid = session.jid |
52 | 52 |
53 disco = yield self.host.bridgeCall("discoInfos", target_jid.host, "", True, profile) | 53 disco = yield self.host.bridge_call("disco_infos", target_jid.host, "", True, profile) |
54 if "conference" in [i[0] for i in disco[1]]: | 54 if "conference" in [i[0] for i in disco[1]]: |
55 chat_type = C.CHAT_GROUP | 55 chat_type = C.CHAT_GROUP |
56 join_ret = yield self.host.bridgeCall( | 56 join_ret = yield self.host.bridge_call( |
57 "mucJoin", target_jid.userhost(), "", "", profile | 57 "muc_join", target_jid.userhost(), "", "", profile |
58 ) | 58 ) |
59 (already_joined, | 59 (already_joined, |
60 room_jid_s, | 60 room_jid_s, |
61 occupants, | 61 occupants, |
62 user_nick, | 62 user_nick, |
71 chat_type = C.CHAT_ONE2ONE | 71 chat_type = C.CHAT_ONE2ONE |
72 own_jid = profile_jid | 72 own_jid = profile_jid |
73 rdata["chat_type"] = chat_type | 73 rdata["chat_type"] = chat_type |
74 template_data["own_jid"] = own_jid | 74 template_data["own_jid"] = own_jid |
75 | 75 |
76 self.registerSignal(request, "messageNew") | 76 self.register_signal(request, "message_new") |
77 history = yield self.host.bridgeCall( | 77 history = yield self.host.bridge_call( |
78 "historyGet", | 78 "history_get", |
79 profile_jid.userhost(), | 79 profile_jid.userhost(), |
80 target_jid.userhost(), | 80 target_jid.userhost(), |
81 20, | 81 20, |
82 True, | 82 True, |
83 {}, | 83 {}, |
84 profile, | 84 profile, |
85 ) | 85 ) |
86 authors = {m[2] for m in history} | 86 authors = {m[2] for m in history} |
87 identities = session.identities | 87 identities = session.identities |
88 for author in authors: | 88 for author in authors: |
89 id_raw = yield self.host.bridgeCall( | 89 id_raw = yield self.host.bridge_call( |
90 "identityGet", author, [], True, profile) | 90 "identity_get", author, [], True, profile) |
91 identities[author] = data_format.deserialise(id_raw) | 91 identities[author] = data_format.deserialise(id_raw) |
92 | 92 |
93 template_data["messages"] = data_objects.Messages(history) | 93 template_data["messages"] = data_objects.Messages(history) |
94 rdata['identities'] = identities | 94 rdata['identities'] = identities |
95 template_data["target_jid"] = target_jid | 95 template_data["target_jid"] = target_jid |
96 template_data["chat_type"] = chat_type | 96 template_data["chat_type"] = chat_type |
97 | 97 |
98 | 98 |
99 def on_data(self, request, data): | 99 def on_data(self, request, data): |
100 session = self.host.getSessionData(request, session_iface.IWebSession) | 100 session = self.host.get_session_data(request, session_iface.IWebSession) |
101 rdata = self.getRData(request) | 101 rdata = self.get_r_data(request) |
102 target = rdata["target"] | 102 target = rdata["target"] |
103 data_type = data.get("type", "") | 103 data_type = data.get("type", "") |
104 if data_type == "msg": | 104 if data_type == "msg": |
105 message = data["body"] | 105 message = data["body"] |
106 mess_type = ( | 106 mess_type = ( |
107 C.MESS_TYPE_GROUPCHAT | 107 C.MESS_TYPE_GROUPCHAT |
108 if rdata["chat_type"] == C.CHAT_GROUP | 108 if rdata["chat_type"] == C.CHAT_GROUP |
109 else C.MESS_TYPE_CHAT | 109 else C.MESS_TYPE_CHAT |
110 ) | 110 ) |
111 log.debug("message received: {}".format(message)) | 111 log.debug("message received: {}".format(message)) |
112 self.host.bridgeCall( | 112 self.host.bridge_call( |
113 "messageSend", | 113 "message_send", |
114 target.full(), | 114 target.full(), |
115 {"": message}, | 115 {"": message}, |
116 {}, | 116 {}, |
117 mess_type, | 117 mess_type, |
118 "", | 118 "", |