Mercurial > libervia-web
comparison src/browser/libervia_main.py @ 606:7af8f4ab3675 frontends_multi_profiles
browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 09 Feb 2015 21:55:16 +0100 |
parents | be2891462e63 |
children | ec77c2bc18d3 |
comparison
equal
deleted
inserted
replaced
605:917e271975d9 | 606:7af8f4ab3675 |
---|---|
49 from sat_browser import xmlui | 49 from sat_browser import xmlui |
50 from sat_browser import html_tools | 50 from sat_browser import html_tools |
51 from sat_browser import notification | 51 from sat_browser import notification |
52 | 52 |
53 from sat_browser.constants import Const as C | 53 from sat_browser.constants import Const as C |
54 import os.path | |
54 | 55 |
55 | 56 |
56 try: | 57 try: |
57 # FIXME: import plugin dynamically | 58 # FIXME: import plugin dynamically |
58 from sat_browser import plugin_sec_otr | 59 from sat_browser import plugin_sec_otr |
96 self.initialised = False | 97 self.initialised = False |
97 self.init_cache = [] # used to cache events until initialisation is done | 98 self.init_cache = [] # used to cache events until initialisation is done |
98 self.cached_params = {} | 99 self.cached_params = {} |
99 | 100 |
100 #FIXME: to be removed (managed with cache and in quick_frontend | 101 #FIXME: to be removed (managed with cache and in quick_frontend |
101 self.avatars_cache = {} # keep track of jid's avatar hash (key=jid, value=file) | |
102 #FIXME: microblog cache should be managed directly in blog module | 102 #FIXME: microblog cache should be managed directly in blog module |
103 self.mblog_cache = [] # used to keep our own blog entries in memory, to show them in new mblog panel | 103 self.mblog_cache = [] # used to keep our own blog entries in memory, to show them in new mblog panel |
104 | 104 |
105 | 105 |
106 | 106 |
195 event.preventDefault() | 195 event.preventDefault() |
196 return True | 196 return True |
197 | 197 |
198 # FIXME: must not call _entityDataUpdatedCb by itself | 198 # FIXME: must not call _entityDataUpdatedCb by itself |
199 # should not get VCard, backend plugin must be fixed too | 199 # should not get VCard, backend plugin must be fixed too |
200 # def getAvatar(self, jid_str): | 200 def getAvatarURL(self, jid_): |
201 # """Return avatar of a jid if in cache, else ask for it. | 201 """Return avatar of a jid if in cache, else ask for it. |
202 | 202 |
203 # @param jid_str (str): JID of the contact | 203 @param jid_ (jid.JID): JID of the contact |
204 # @return: the URL to the avatar (str) | 204 @return: the URL to the avatar (str) |
205 # """ | 205 """ |
206 # def dataReceived(result): | 206 assert isinstance(jid_, jid.JID) |
207 # if 'avatar' in result: | 207 avatar_hash = self.contact_lists[C.PROF_KEY_NONE].getCache(jid_, 'avatar') |
208 # self._entityDataUpdatedCb(jid_str, 'avatar', result['avatar']) | 208 if avatar_hash is None: |
209 # else: | 209 # we have no value for avatar_hash, so we request the vcard |
210 # self.bridge.call("getCard", None, jid_str) | 210 self.bridge.getCard(unicode(jid_), profile=C.PROF_KEY_NONE) |
211 | 211 if not avatar_hash: |
212 # def avatarError(error_data): | 212 return C.DEFAULT_AVATAR_URL |
213 # # The jid is maybe not in our roster, we ask for the VCard | 213 ret = os.path.join(C.AVATARS_DIR, avatar_hash) |
214 # self.bridge.call("getCard", None, jid_str) | 214 return ret |
215 | |
216 # if jid_str not in self.avatars_cache: | |
217 # self.bridge.call('getEntityData', (dataReceived, avatarError), jid_str, ['avatar']) | |
218 # self.avatars_cache[jid_str] = C.DEFAULT_AVATAR | |
219 # return self.avatars_cache[jid_str] | |
220 | 215 |
221 def registerWidget(self, wid): | 216 def registerWidget(self, wid): |
222 log.debug("Registering %s" % wid.getDebugName()) | 217 log.debug("Registering %s" % wid.getDebugName()) |
223 self.libervia_widgets.add(wid) | 218 self.libervia_widgets.add(wid) |
224 | 219 |
346 | 341 |
347 # count = [0] # used to do something similar to DeferredList | 342 # count = [0] # used to do something similar to DeferredList |
348 # for cat, name in C.CACHED_PARAMS: | 343 # for cat, name in C.CACHED_PARAMS: |
349 # self.bridge.call('asyncGetParamA', param_cb(cat, name, count), name, cat) | 344 # self.bridge.call('asyncGetParamA', param_cb(cat, name, count), name, cat) |
350 | 345 |
351 def profilePlugged(self, profile): | 346 def profilePlugged(self, dummy): |
352 #we fill the panels already here | 347 # we fill the panels already here |
353 for widget in self.widgets.getWidgets(blog.MicroblogPanel): | 348 for widget in self.widgets.getWidgets(blog.MicroblogPanel): |
354 if widget.accept_all(): | 349 if widget.accept_all(): |
355 self.bridge.getMassiveLastMblogs('ALL', [], 10, profile=C.PROF_KEY_NONE, callback=widget.massiveInsert) | 350 self.bridge.getMassiveLastMblogs('ALL', [], 10, profile=C.PROF_KEY_NONE, callback=widget.massiveInsert) |
356 else: | 351 else: |
357 self.bridge.getMassiveLastMblogs('GROUP', widget.accepted_groups, 10, profile=C.PROF_KEY_NONE, callback=widget.massiveInsert) | 352 self.bridge.getMassiveLastMblogs('GROUP', widget.accepted_groups, 10, profile=C.PROF_KEY_NONE, callback=widget.massiveInsert) |
422 @param data: data needed only for certain actions | 417 @param data: data needed only for certain actions |
423 | 418 |
424 """ | 419 """ |
425 if data is None: | 420 if data is None: |
426 data = {} | 421 data = {} |
427 self.bridge.call('launchAction', (self._actionCb, self._actionEb), callback_id, data) | 422 self.bridge.launchAction(callback_id, data, profile=C.PROF_KEY_NONE, callback=self._actionCb, errback=self._actionEb) |
428 | 423 |
429 def _getContactsCB(self, contacts_data): | 424 def _getContactsCB(self, contacts_data): |
430 for contact_ in contacts_data: | 425 for contact_ in contacts_data: |
431 jid, attributes, groups = contact_ | 426 jid, attributes, groups = contact_ |
432 self._newContactCb(jid, attributes, groups) | 427 self._newContactCb(jid, attributes, groups) |
798 | 793 |
799 def _newContactCb(self, contact_jid, attributes, groups): | 794 def _newContactCb(self, contact_jid, attributes, groups): |
800 self.contact_panel.updateContact(contact_jid, attributes, groups) | 795 self.contact_panel.updateContact(contact_jid, attributes, groups) |
801 | 796 |
802 def _entityDataUpdatedCb(self, entity_jid_s, key, value): | 797 def _entityDataUpdatedCb(self, entity_jid_s, key, value): |
798 raise Exception # FIXME should not be here | |
803 if key == "avatar": | 799 if key == "avatar": |
804 avatar = '/' + C.AVATARS_DIR + value | 800 avatar = '/' + C.AVATARS_DIR + value |
805 self.avatars_cache[entity_jid_s] = avatar | 801 self.avatars_cache[entity_jid_s] = avatar |
806 self.contact_panel.updateAvatar(entity_jid_s, avatar) | 802 self.contact_panel.updateAvatar(entity_jid_s, avatar) |
807 | 803 |