comparison frontends/src/quick_frontend/quick_app.py @ 2067:7834743705f0

quich frontend, primivius (chat): better avatar handling: - new getAvatar method in QuickApp which request vCard if avatar if needed and return default avatar is no avatar is found - frontends based on quick frontend can now specify if they handle avatar or not using AVATARS_HANDLER - when avatar is updated, occupant widget(s) and all message widget(s) of the concerned entity are updated
author Goffi <goffi@goffi.org>
date Fri, 09 Sep 2016 23:54:33 +0200
parents 09c18fcd8225
children 4633cfcbcccb
comparison
equal deleted inserted replaced
2066:09c18fcd8225 2067:7834743705f0
184 return self._profiles.keys()[0] 184 return self._profiles.keys()[0]
185 185
186 186
187 class QuickApp(object): 187 class QuickApp(object):
188 """This class contain the main methods needed for the frontend""" 188 """This class contain the main methods needed for the frontend"""
189 MB_HANDLE = True # Set to false if the frontend doesn't manage microblog 189 MB_HANDLER = True # Set to False if the frontend doesn't manage microblog
190 AVATARS_HANDLER = True # set to False if avatars are not used
190 191
191 def __init__(self, create_bridge, xmlui, check_options=None): 192 def __init__(self, create_bridge, xmlui, check_options=None):
192 """Create a frontend application 193 """Create a frontend application
193 194
194 @param create_bridge: method to use to create the Bridge 195 @param create_bridge: method to use to create the Bridge
668 @param event_type (unicode): event type (one of C.PUBLISH, C.RETRACT, C.DELETE) 669 @param event_type (unicode): event type (one of C.PUBLISH, C.RETRACT, C.DELETE)
669 @param data (dict): event data 670 @param data (dict): event data
670 """ 671 """
671 service_s = jid.JID(service_s) 672 service_s = jid.JID(service_s)
672 673
673 if category == C.PS_MICROBLOG and self.MB_HANDLE: 674 if category == C.PS_MICROBLOG and self.MB_HANDLER:
674 if event_type == C.PS_PUBLISH: 675 if event_type == C.PS_PUBLISH:
675 if not 'content' in data: 676 if not 'content' in data:
676 log.warning("No content found in microblog data") 677 log.warning("No content found in microblog data")
677 return 678 return
678 _groups = set(data_format.dict2iter('group', data)) or None # FIXME: check if [] make sense (instead of None) 679 _groups = set(data_format.dict2iter('group', data)) or None # FIXME: check if [] make sense (instead of None)
829 else: 830 else:
830 callback(data=data, cb_id=callback_id, profile=profile) 831 callback(data=data, cb_id=callback_id, profile=profile)
831 832
832 self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure) 833 self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure)
833 834
835 def getAvatar(self, entity, profile):
836 """return avatar path for an entity"""
837 contact_list = self.contact_lists[profile]
838 avatar = contact_list.getCache(entity, "avatar")
839 if avatar is None:
840 self.bridge.getCard(unicode(entity), profile)
841 contact_list.setCache(entity, "avatar", "")
842 if not avatar:
843 avatar = self.getDefaultAvatar(entity)
844 return avatar
845
834 def getDefaultAvatar(self, entity=None): 846 def getDefaultAvatar(self, entity=None):
835 """return default avatar to use with given entity 847 """return default avatar to use with given entity
836 848
837 must be implemented by frontend 849 must be implemented by frontend
838 @param entity(jid.JID): entity for which a default avatar is needed 850 @param entity(jid.JID): entity for which a default avatar is needed