comparison libervia.py @ 137:b145da69a218

server + browser side: new api fix
author Goffi <goffi@goffi.org>
date Mon, 22 Oct 2012 00:08:41 +0200
parents ceef355156de
children 008fa8d36602
comparison
equal deleted inserted replaced
136:9d7d98954e34 137:b145da69a218
82 class BridgeCall(LiberviaJsonProxy): 82 class BridgeCall(LiberviaJsonProxy):
83 def __init__(self): 83 def __init__(self):
84 LiberviaJsonProxy.__init__(self, "/json_api", 84 LiberviaJsonProxy.__init__(self, "/json_api",
85 ["getContacts", "addContact", "sendMessage", "sendMblog", "getLastMblogs", "getMassiveLastMblogs", "getProfileJid", "getHistory", "getPresenceStatus", 85 ["getContacts", "addContact", "sendMessage", "sendMblog", "getLastMblogs", "getMassiveLastMblogs", "getProfileJid", "getHistory", "getPresenceStatus",
86 "joinMUC", "getRoomsJoined", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady", "tarotGameContratChoosed", 86 "joinMUC", "getRoomsJoined", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady", "tarotGameContratChoosed",
87 "tarotGamePlayCards", "launchRadioCollective", "getWaitingSub", "subscription", "delContact", "updateContact", "getCardCache"]) 87 "tarotGamePlayCards", "launchRadioCollective", "getWaitingSub", "subscription", "delContact", "updateContact", "getEntityData"])
88 88
89 class BridgeSignals(LiberviaJsonProxy): 89 class BridgeSignals(LiberviaJsonProxy):
90 def __init__(self, host): 90 def __init__(self, host):
91 self.host = host 91 self.host = host
92 LiberviaJsonProxy.__init__(self, "/json_signal_api", 92 LiberviaJsonProxy.__init__(self, "/json_signal_api",
139 event.preventDefault() 139 event.preventDefault()
140 return True 140 return True
141 141
142 def getAvatar(self, jid_str): 142 def getAvatar(self, jid_str):
143 """Return avatar of a jid if in cache, else ask for it""" 143 """Return avatar of a jid if in cache, else ask for it"""
144 def cacheCardResult(result): 144 def dataReceived(result):
145 if result.has_key('avatar'): 145 if result.has_key('avatar'):
146 self._updatedValueCb("card_avatar", {'jid':jid_str, 'avatar':result['avatar']}) 146 self._entityDataUpdatedCb(jid_str, 'avatar', result['avatar'])
147 147
148 if jid_str not in self.avatars_cache: 148 if jid_str not in self.avatars_cache:
149 self.bridge.call('getCardCache', cacheCardResult, jid_str) 149 self.bridge.call('getEntityData', dataReceived, jid_str, ['avatar'])
150 self.avatars_cache[jid_str] = "/media/misc/empty_avatar" 150 self.avatars_cache[jid_str] = "/media/misc/empty_avatar"
151 return self.avatars_cache[jid_str] 151 return self.avatars_cache[jid_str]
152 152
153 def registerWidget(self, wid): 153 def registerWidget(self, wid):
154 print "Registering", wid 154 print "Registering", wid
263 self._subscribeCb(*args) 263 self._subscribeCb(*args)
264 elif name == 'contactDeleted': 264 elif name == 'contactDeleted':
265 self._contactDeletedCb(*args) 265 self._contactDeletedCb(*args)
266 elif name == 'newContact': 266 elif name == 'newContact':
267 self._newContactCb(*args) 267 self._newContactCb(*args)
268 elif name == 'updatedValue': 268 elif name == 'entityDataUpdated':
269 self._updatedValueCb(*args) 269 self._entityDataUpdatedCb(*args)
270 270
271 def _getProfileJidCB(self, jid): 271 def _getProfileJidCB(self, jid):
272 self.whoami = JID(jid) 272 self.whoami = JID(jid)
273 #we can now ask our status 273 #we can now ask our status
274 self.bridge.call('getPresenceStatus', self._getPresenceStatusCb) 274 self.bridge.call('getPresenceStatus', self._getPresenceStatusCb)
421 self.contact_panel.removeContact(entity) 421 self.contact_panel.removeContact(entity)
422 422
423 def _newContactCb(self, contact, attributes, groups): 423 def _newContactCb(self, contact, attributes, groups):
424 self.contact_panel.updateContact(contact, attributes, groups) 424 self.contact_panel.updateContact(contact, attributes, groups)
425 425
426 def _updatedValueCb(self, name, value): 426 def _entityDataUpdatedCb(self, entity_jid_s, key, value):
427 if name == "card_avatar": 427 if key == "avatar":
428 try: 428 entity_jid_s = value['entity_jid_s']
429 jid = value['jid'] 429 avatar = '/avatars/%s' % value
430 avatar = '/avatars/%s' % value['avatar'] 430
431 except: 431 self.avatars_cache[entity_jid_s] = avatar
432 print ("ERROR: can't get avatar value")
433 return
434
435 self.avatars_cache[jid] = avatar
436 432
437 for lib_wid in self.libervia_widgets: 433 for lib_wid in self.libervia_widgets:
438 if isinstance(lib_wid, panels.MicroblogPanel): 434 if isinstance(lib_wid, panels.MicroblogPanel):
439 if lib_wid.isJidAccepted(jid) or (self.whoami and jid == self.whoami.bare): 435 if lib_wid.isJidAccepted(entity_jid_s) or (self.whoami and entity_jid_s == self.whoami.bare):
440 lib_wid.updateValue('avatar', jid, avatar) 436 lib_wid.updateValue('avatar', entity_jid_s, avatar)
441 437
442 438
443 439
444 if __name__ == '__main__': 440 if __name__ == '__main__':
445 pyjd.setup("http://localhost:8080/libervia.html") 441 pyjd.setup("http://localhost:8080/libervia.html")