Mercurial > libervia-web
comparison libervia.py @ 119:a8d11fdea090
microblog avatar update
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 06 Jul 2011 03:03:07 +0200 |
parents | aff34642616b |
children | 397a88b340f3 |
comparison
equal
deleted
inserted
replaced
118:a2a21e0290dc | 119:a8d11fdea090 |
---|---|
76 class BridgeCall(LiberviaJsonProxy): | 76 class BridgeCall(LiberviaJsonProxy): |
77 def __init__(self): | 77 def __init__(self): |
78 LiberviaJsonProxy.__init__(self, "/json_api", | 78 LiberviaJsonProxy.__init__(self, "/json_api", |
79 ["getContacts", "addContact", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus", | 79 ["getContacts", "addContact", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus", |
80 "joinMUC", "getRoomJoined", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady", "tarotGameContratChoosed", | 80 "joinMUC", "getRoomJoined", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady", "tarotGameContratChoosed", |
81 "tarotGamePlayCards", "getWaitingSub", "subscription", "delContact", "updateContact"]) | 81 "tarotGamePlayCards", "getWaitingSub", "subscription", "delContact", "updateContact", "getCardCache"]) |
82 | 82 |
83 class BridgeSignals(LiberviaJsonProxy): | 83 class BridgeSignals(LiberviaJsonProxy): |
84 def __init__(self, host): | 84 def __init__(self, host): |
85 self.host = host | 85 self.host = host |
86 LiberviaJsonProxy.__init__(self, "/json_signal_api", | 86 LiberviaJsonProxy.__init__(self, "/json_signal_api", |
117 self.discuss_panel = self.panel.discuss_panel | 117 self.discuss_panel = self.panel.discuss_panel |
118 self.tab_panel = self.panel.tab_panel | 118 self.tab_panel = self.panel.tab_panel |
119 self.libervia_widgets = set() #keep track of all actives LiberviaWidgets | 119 self.libervia_widgets = set() #keep track of all actives LiberviaWidgets |
120 self.room_list = set() #set of rooms | 120 self.room_list = set() #set of rooms |
121 self.mblog_cache = [] #used to keep blog entries in memory, to show them in new mblog panel | 121 self.mblog_cache = [] #used to keep blog entries in memory, to show them in new mblog panel |
122 self.avatars_cache = {} #keep track of jid's avatar hash (key=jid, value=hash) | 122 self.avatars_cache = {} #keep track of jid's avatar hash (key=jid, value=file) |
123 #self.discuss_panel.addWidget(panels.EmptyPanel(self)) | 123 #self.discuss_panel.addWidget(panels.EmptyPanel(self)) |
124 self.discuss_panel.addWidget(panels.MicroblogPanel(self, accept_all=True)) | 124 self.discuss_panel.addWidget(panels.MicroblogPanel(self, accept_all=True)) |
125 #self.discuss_panel.addWidget(panels.EmptyPanel(self)) | 125 #self.discuss_panel.addWidget(panels.EmptyPanel(self)) |
126 self._register_box = None | 126 self._register_box = None |
127 RootPanel().add(self.panel) | 127 RootPanel().add(self.panel) |
137 def onEventPreview(self, event): | 137 def onEventPreview(self, event): |
138 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: | 138 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: |
139 #needed to prevent request cancellation in Firefox | 139 #needed to prevent request cancellation in Firefox |
140 event.preventDefault() | 140 event.preventDefault() |
141 return True | 141 return True |
142 | |
143 def getAvatar(self, jid_str): | |
144 """Return avatar of a jid if in cache, else ask for it""" | |
145 def cacheCardResult(result): | |
146 if result.has_key('avatar'): | |
147 self._updatedValueCb("card_avatar", {'jid':jid_str, 'avatar':result['avatar']}) | |
148 | |
149 if jid_str not in self.avatars_cache: | |
150 self.bridge.call('getCardCache', cacheCardResult, jid_str) | |
151 self.avatars_cache[jid_str] = "/media/misc/empty_avatar" | |
152 return self.avatars_cache[jid_str] | |
142 | 153 |
143 def registerWidget(self, wid): | 154 def registerWidget(self, wid): |
144 print "Registering", wid | 155 print "Registering", wid |
145 self.libervia_widgets.add(wid) | 156 self.libervia_widgets.add(wid) |
146 | 157 |
234 self._subscribeCb(*args) | 245 self._subscribeCb(*args) |
235 elif name == 'contactDeleted': | 246 elif name == 'contactDeleted': |
236 self._contactDeletedCb(*args) | 247 self._contactDeletedCb(*args) |
237 elif name == 'newContact': | 248 elif name == 'newContact': |
238 self._newContactCb(*args) | 249 self._newContactCb(*args) |
250 elif name == 'updatedValue': | |
251 self._updatedValueCb(*args) | |
239 | 252 |
240 def _getProfileJidCB(self, jid): | 253 def _getProfileJidCB(self, jid): |
241 self.whoami = JID(jid) | 254 self.whoami = JID(jid) |
242 #we can now ask our status | 255 #we can now ask our status |
243 self.bridge.call('getPresenceStatus', self._getPresenceStatusCb) | 256 self.bridge.call('getPresenceStatus', self._getPresenceStatusCb) |
379 self.contact_panel.removeContact(entity) | 392 self.contact_panel.removeContact(entity) |
380 | 393 |
381 def _newContactCb(self, contact, attributes, groups): | 394 def _newContactCb(self, contact, attributes, groups): |
382 self.contact_panel.updateContact(contact, attributes, groups) | 395 self.contact_panel.updateContact(contact, attributes, groups) |
383 | 396 |
397 def _updatedValueCb(self, name, value): | |
398 if name == "card_avatar": | |
399 try: | |
400 jid = value['jid'] | |
401 avatar = '/avatars/%s' % value['avatar'] | |
402 except: | |
403 print ("ERROR: can't get avatar value") | |
404 return | |
405 | |
406 self.avatars_cache[jid] = avatar | |
407 | |
408 for lib_wid in self.libervia_widgets: | |
409 if isinstance(lib_wid, panels.MicroblogPanel): | |
410 if lib_wid.isJidAccepted(jid) or (self.whoami and jid == self.whoami.bare): | |
411 lib_wid.updateValue('avatar', jid, avatar) | |
412 | |
413 | |
414 | |
384 if __name__ == '__main__': | 415 if __name__ == '__main__': |
385 pyjd.setup("http://localhost:8080/libervia.html") | 416 pyjd.setup("http://localhost:8080/libervia.html") |
386 app = SatWebFrontend() | 417 app = SatWebFrontend() |
387 app.onModuleLoad() | 418 app.onModuleLoad() |
388 pyjd.run() | 419 pyjd.run() |