comparison src/pages/chat/select/page_meta.py @ 999:ded41172dcb5

pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
author Goffi <goffi@goffi.org>
date Fri, 05 Jan 2018 16:30:03 +0100
parents
children cdd389ef97bc
comparison
equal deleted inserted replaced
998:0848b8b0188d 999:ded41172dcb5
1 #!/usr/bin/env python2.7
2 # -*- coding: utf-8 -*-
3
4 from sat.core.i18n import _
5 from libervia.server.constants import Const as C
6 from twisted.internet import defer
7 from twisted.words.protocols.jabber import jid
8 from sat.tools.common import data_objects
9 from sat.core.log import getLogger
10 log = getLogger('pages/chat_select')
11
12 name = u'chat_select'
13 access = C.PAGES_ACCESS_PROFILE
14 template = u"chat/select.html"
15
16
17 @defer.inlineCallbacks
18 def prepare_render(self, request):
19 profile = self.getProfile(request)
20 template_data = request.template_data
21 rooms = template_data['rooms'] = []
22 bookmarks = yield self.host.bridgeCall('bookmarksList', 'muc', 'all', profile)
23 for bm_values in bookmarks.values():
24 for room_jid, room_data in bm_values.iteritems():
25 url = self.getPageByName(u'chat').getURL(room_jid)
26 rooms.append(data_objects.Room(room_jid,
27 name=room_data.get('name'),
28 url=url))
29 rooms.sort(key=lambda r: r.name)
30
31
32 @defer.inlineCallbacks
33 def on_data_post(self, request):
34 jid_ = self.getPostedData(request, u'jid')
35 if u'@' not in jid_:
36 profile = self.getProfile(request)
37 service = yield self.host.bridgeCall('mucGetService', '', profile)
38 if service:
39 muc_jid = jid.JID(service)
40 muc_jid.user = jid_
41 jid_ = muc_jid.full()
42 else:
43 log.warning(_(u"Invalid jid received: {jid}".format(jid=jid_)))
44 defer.returnValue(C.POST_NO_CONFIRM)
45 url = self.getPageByName(u'chat').getURL(jid_)
46 self.HTTPRedirect(request, url)