comparison frontends/src/quick_frontend/quick_chat.py @ 2123:c42aab22c2c0

plugin XEP-0054, quick frontend(app): various improvments: - memory.cache is now used - getAvatar and setAvatar has been renamed to avatarGet and avatarSet to follow new convention - getAvatar now return (optionally) full path, and may request vCard or only return avatar in cache - getAvatarFile has been removed as it is not needed anymore (avatarGet can return full path) - getCard has been removed from bridge as it was only used to request avatar - new internal method getBareOfFull return jid to use depending of the jid being part of a MUC or not - cache is now set per profile in client, instead of a general one for all profiles - thanks to the use of memory.cache, correct extension is now used in saved file, according to MIME type - fixed and better cache handling - a warning message is shown if given avatar hash differs from computed one - empty hash value is now in a constant, and ignored if received - QuickApp has been updated to follow new behaviour - Primitivus has been fixed (it was not declaring not using avatars correclty) - jp has been updated to follow new methods name
author Goffi <goffi@goffi.org>
date Sun, 15 Jan 2017 17:51:37 +0100
parents 3435e8d2e8e4
children 4b78b4c7f805
comparison
equal deleted inserted replaced
2122:3970ebcf8830 2123:c42aab22c2c0
124 time_format = u"%c" if timestamp < self.parent.day_change else u"%H:%M" 124 time_format = u"%c" if timestamp < self.parent.day_change else u"%H:%M"
125 return time.strftime(time_format, timestamp).decode(getlocale()[1] or 'utf-8') 125 return time.strftime(time_format, timestamp).decode(getlocale()[1] or 'utf-8')
126 126
127 @property 127 @property
128 def avatar(self): 128 def avatar(self):
129 return self.host.getAvatar(self.from_jid, self.profile) 129 """avatar full path or None if no avatar is found"""
130 ret = self.host.getAvatar(self.from_jid, profile=self.profile)
131 return ret
130 132
131 def getNick(self, entity): 133 def getNick(self, entity):
132 """Return nick of an entity when possible""" 134 """Return nick of an entity when possible"""
133 contact_list = self.host.contact_lists[self.profile] 135 contact_list = self.host.contact_lists[self.profile]
134 if self.type == C.MESS_TYPE_INFO and self.info_type in ROOM_USER_MOVED: 136 if self.type == C.MESS_TYPE_INFO and self.info_type in ROOM_USER_MOVED:
581 else: 583 else:
582 mess_data.status = status 584 mess_data.status = status
583 585
584 def onAvatar(self, entity, filename, profile): 586 def onAvatar(self, entity, filename, profile):
585 if self.type == C.CHAT_GROUP: 587 if self.type == C.CHAT_GROUP:
586 if entity.bare == self.target and entity.resource in self.occupants: 588 if entity.bare == self.target:
587 self.occupants[entity.resource].update({'avatar': filename}) 589 try:
590 self.occupants[entity.resource].update({'avatar': filename})
591 except KeyError:
592 # can happen for a message in history where the
593 # entity is not here anymore
594 pass
595
588 for m in self.messages.values(): 596 for m in self.messages.values():
589 if m.nick == entity.resource: 597 if m.nick == entity.resource:
590 for w in m.widgets: 598 for w in m.widgets:
591 w.update({'avatar': filename}) 599 w.update({'avatar': filename})
592 else: 600 else:
593 if entity.bare == self.target.bare: 601 if entity.bare == self.target.bare or entity.bare == self.host.profiles[profile].whoami.bare:
594 log.info("entity avatar updated") 602 log.info(u"avatar updated for {}".format(entity))
595 # TODO: call a specific method 603 for m in self.messages.values():
604 if m.from_jid.bare == entity.bare:
605 for w in m.widgets:
606 w.update({'avatar': filename})
596 607
597 608
598 quick_widgets.register(QuickChat) 609 quick_widgets.register(QuickChat)