Mercurial > libervia-web
comparison src/browser/libervia_main.py @ 914:0c0551967bdf
server, browser: partial Libervia fix
Libervia was broken following the refactorings. This commit partially fixes it : Libervia is starting, avatar, blog and message are working again, but not everything is restablished yet.
following things have been fixed/changed:
- new dependency: shortuuid
- D-Bus bridge is working again
- fixed naming in several bridge methods
- register method changed to register_signal
- fixed Chat widget, which was not working anymore since the refactoring
- avatar now use avatarGet. Cache dir is accessible using a session specific uuid, to avoid cache leak (i.e. accessing cache of other profiles)
- server: new uuid attribute in session data
Browser code is not fully working yet, notably OTR and contact list are not fully fixed.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 26 Feb 2017 18:32:47 +0100 |
parents | 58f611481e6d |
children | 5d9f6d25c586 |
comparison
equal
deleted
inserted
replaced
913:58f611481e6d | 914:0c0551967bdf |
---|---|
56 from sat_browser import libervia_widget | 56 from sat_browser import libervia_widget |
57 from sat_browser import web_widget | 57 from sat_browser import web_widget |
58 assert web_widget # XXX: just here to avoid pyflakes warning | 58 assert web_widget # XXX: just here to avoid pyflakes warning |
59 | 59 |
60 from sat_browser.constants import Const as C | 60 from sat_browser.constants import Const as C |
61 import os.path | |
62 | 61 |
63 | 62 |
64 try: | 63 try: |
65 # FIXME: import plugin dynamically | 64 # FIXME: import plugin dynamically |
66 from sat_browser import plugin_sec_otr | 65 from sat_browser import plugin_sec_otr |
77 class SatWebFrontend(InputHistory, QuickApp): | 76 class SatWebFrontend(InputHistory, QuickApp): |
78 | 77 |
79 def onModuleLoad(self): | 78 def onModuleLoad(self): |
80 log.info("============ onModuleLoad ==============") | 79 log.info("============ onModuleLoad ==============") |
81 self.bridge_signals = json.BridgeSignals(self) | 80 self.bridge_signals = json.BridgeSignals(self) |
82 QuickApp.__init__(self, json.BridgeCall, xmlui=xmlui) | 81 QuickApp.__init__(self, json.BridgeCall, xmlui=xmlui, connect_bridge=False) |
82 self.connectBridge() | |
83 self._profile_plugged = False | 83 self._profile_plugged = False |
84 self.signals_cache[C.PROF_KEY_NONE] = [] | 84 self.signals_cache[C.PROF_KEY_NONE] = [] |
85 self.panel = main_panel.MainPanel(self) | 85 self.panel = main_panel.MainPanel(self) |
86 self.tab_panel = self.panel.tab_panel | 86 self.tab_panel = self.panel.tab_panel |
87 self.tab_panel.addTabListener(self) | 87 self.tab_panel.addTabListener(self) |
91 self.alerts_counter = notification.FaviconCounter() | 91 self.alerts_counter = notification.FaviconCounter() |
92 self.notification = notification.Notification(self.alerts_counter) | 92 self.notification = notification.Notification(self.alerts_counter) |
93 DOM.addEventPreview(self) | 93 DOM.addEventPreview(self) |
94 self.importPlugins() | 94 self.importPlugins() |
95 self._register = json.RegisterCall() | 95 self._register = json.RegisterCall() |
96 self._register.call('getMenus', self.gotMenus) | 96 self._register.call('menusGet', self.gotMenus) |
97 self._register.call('registerParams', None) | 97 self._register.call('registerParams', None) |
98 self._register.call('getSessionMetadata', self._getSessionMetadataCB) | 98 self._register.call('getSessionMetadata', self._getSessionMetadataCB) |
99 self.initialised = False | 99 self.initialised = False |
100 self.init_cache = [] # used to cache events until initialisation is done | 100 self.init_cache = [] # used to cache events until initialisation is done |
101 self.cached_params = {} | 101 self.cached_params = {} |
168 if handler is None: | 168 if handler is None: |
169 callback = getattr(self, "{}{}".format(functionName, "Handler")) | 169 callback = getattr(self, "{}{}".format(functionName, "Handler")) |
170 else: | 170 else: |
171 callback = handler | 171 callback = handler |
172 | 172 |
173 self.bridge_signals.register(functionName, callback, with_profile=with_profile) | 173 self.bridge_signals.register_signal(functionName, callback, with_profile=with_profile) |
174 | 174 |
175 def importPlugins(self): | 175 def importPlugins(self): |
176 self.plugins = {} | 176 self.plugins = {} |
177 try: | 177 try: |
178 self.plugins['otr'] = plugin_sec_otr.OTR(self) | 178 self.plugins['otr'] = plugin_sec_otr.OTR(self) |
224 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: | 224 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: |
225 #needed to prevent request cancellation in Firefox | 225 #needed to prevent request cancellation in Firefox |
226 event.preventDefault() | 226 event.preventDefault() |
227 return True | 227 return True |
228 | 228 |
229 # FIXME: must not call _entityDataUpdatedCb by itself | |
230 # should not get VCard, backend plugin must be fixed too | |
231 def getAvatarURL(self, jid_): | 229 def getAvatarURL(self, jid_): |
232 """Return avatar of a jid if in cache, else ask for it. | 230 """Return avatar of a jid if in cache, else ask for it. |
233 | 231 |
234 @param jid_ (jid.JID): JID of the contact | 232 @param jid_ (jid.JID): JID of the contact |
235 @return: the URL to the avatar (unicode) | 233 @return: the URL to the avatar (unicode) |
236 """ | 234 """ |
237 assert isinstance(jid_, jid.JID) | 235 return self.getAvatar(jid_) or self.getDefaultAvatar() |
238 contact_list = self.contact_list # pyjamas issue: need a temporary variable to call a property's method | 236 |
239 avatar_hash = contact_list.getCache(jid_, 'avatar') | 237 def getDefaultAvatar(self): |
240 if avatar_hash is None: | 238 return C.DEFAULT_AVATAR_URL |
241 # we set to empty string to avoid requesting vcard several times | |
242 contact_list.setCache(jid_, 'avatar', '') | |
243 # we have no value for avatar_hash, so we request the vcard | |
244 self.bridge.getCard(unicode(jid_), profile=C.PROF_KEY_NONE) | |
245 if not avatar_hash: | |
246 return C.DEFAULT_AVATAR_URL | |
247 ret = os.path.join(C.AVATARS_DIR, avatar_hash) | |
248 return ret | |
249 | 239 |
250 def registerWidget(self, wid): | 240 def registerWidget(self, wid): |
251 log.debug(u"Registering %s" % wid.getDebugName()) | 241 log.debug(u"Registering %s" % wid.getDebugName()) |
252 self.libervia_widgets.add(wid) | 242 self.libervia_widgets.add(wid) |
253 | 243 |
334 else: | 324 else: |
335 self._register.call('isConnected', self._isConnectedCB) | 325 self._register.call('isConnected', self._isConnectedCB) |
336 | 326 |
337 def _isConnectedCB(self, connected): | 327 def _isConnectedCB(self, connected): |
338 if not connected: | 328 if not connected: |
339 self._register.call('asyncConnect', lambda x: self.logged()) | 329 self._register.call('connect', lambda x: self.logged()) |
340 else: | 330 else: |
341 self.logged() | 331 self.logged() |
342 | 332 |
343 def logged(self): | 333 def logged(self): |
344 self.panel.setStyleAttribute("opacity", "1") # background becomes foreground | 334 self.panel.setStyleAttribute("opacity", "1") # background becomes foreground |