comparison libervia/web/pages/chat/select/page_meta.py @ 1518:eb00d593801d

refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 16:49:28 +0200
parents libervia/pages/chat/select/page_meta.py@106bae41f5c8
children c57133362fb7
comparison
equal deleted inserted replaced
1517:b8ed9726525b 1518:eb00d593801d
1 #!/usr/bin/env python3
2
3
4 from libervia.backend.core.i18n import _
5 from libervia.web.server.constants import Const as C
6 from twisted.internet import defer
7 from twisted.words.protocols.jabber import jid
8 from libervia.backend.tools.common import data_objects
9 from libervia.backend.core.log import getLogger
10
11 log = getLogger(__name__)
12
13 name = "chat_select"
14 access = C.PAGES_ACCESS_PROFILE
15 template = "chat/select.html"
16
17
18 @defer.inlineCallbacks
19 def prepare_render(self, request):
20 profile = self.get_profile(request)
21 template_data = request.template_data
22 rooms = template_data["rooms"] = []
23 bookmarks = yield self.host.bridge_call("bookmarks_list", "muc", "all", profile)
24 for bm_values in list(bookmarks.values()):
25 for room_jid, room_data in bm_values.items():
26 url = self.get_page_by_name("chat").get_url(room_jid)
27 rooms.append(data_objects.Room(room_jid, name=room_data.get("name"), url=url))
28 rooms.sort(key=lambda r: r.name)
29
30
31 @defer.inlineCallbacks
32 def on_data_post(self, request):
33 jid_ = self.get_posted_data(request, "jid")
34 if "@" not in jid_:
35 profile = self.get_profile(request)
36 service = yield self.host.bridge_call("muc_get_service", "", profile)
37 if service:
38 muc_jid = jid.JID(service)
39 muc_jid.user = jid_
40 jid_ = muc_jid.full()
41 else:
42 log.warning(_("Invalid jid received: {jid}".format(jid=jid_)))
43 defer.returnValue(C.POST_NO_CONFIRM)
44 url = self.get_page_by_name("chat").get_url(jid_)
45 self.http_redirect(request, url)