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
This commit is contained in:
parent
42167b6ae9
commit
78750cb265
1 changed files with 42 additions and 7 deletions
|
|
@ -117,8 +117,7 @@ class Message(object):
|
|||
|
||||
@property
|
||||
def avatar(self):
|
||||
contact_list = self.host.contact_lists[self.profile]
|
||||
return contact_list.getCache(self.from_jid, "avatar") or self.host.getDefaultAvatar(self.from_jid)
|
||||
return self.host.getAvatar(self.from_jid, self.profile)
|
||||
|
||||
def getNick(self, entity):
|
||||
"""Return nick of an entity when possible"""
|
||||
|
|
@ -167,7 +166,6 @@ class Message(object):
|
|||
self.message[lang] = u"* " + nick + mess[3:]
|
||||
|
||||
|
||||
|
||||
class Occupant(object):
|
||||
"""Occupant metadata"""
|
||||
|
||||
|
|
@ -216,6 +214,10 @@ class Occupant(object):
|
|||
for w in self.widgets:
|
||||
w.updated(["state"])
|
||||
|
||||
def update(self, key=None):
|
||||
for w in self.widgets:
|
||||
w.update(key)
|
||||
|
||||
|
||||
class QuickChat(quick_widgets.QuickWidget):
|
||||
visible_states = ['chat_state'] # FIXME: to be removed, used only in quick_games
|
||||
|
|
@ -249,6 +251,8 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
self.subject = subject
|
||||
lt = time.localtime()
|
||||
self.day_change = (lt.tm_year, lt.tm_mon, lt.tm_mday, 0, 0, 0, lt.tm_wday, lt.tm_yday, lt.tm_isdst) # struct_time of day changing time
|
||||
if self.host.AVATARS_HANDLER:
|
||||
self.host.addListener('avatar', self.onAvatar, profiles)
|
||||
|
||||
def postInit(self):
|
||||
"""Method to be called by frontend after widget is initialised
|
||||
|
|
@ -259,6 +263,10 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
if self.subject is not None:
|
||||
self.setSubject(self.subject)
|
||||
|
||||
def onDelete(self):
|
||||
if self.host.AVATARS_HANDLER:
|
||||
self.host.removeListener('avatar', self.onAvatar)
|
||||
|
||||
@property
|
||||
def contact_list(self):
|
||||
return self.host.contact_lists[self.profile]
|
||||
|
|
@ -539,6 +547,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
|
||||
@param entity (jid.JID): entity to update
|
||||
"""
|
||||
# FIXME: to remove ?
|
||||
raise NotImplementedError
|
||||
|
||||
## events ##
|
||||
|
|
@ -561,5 +570,18 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
else:
|
||||
mess_data.status = status
|
||||
|
||||
def onAvatar(self, entity, filename, profile):
|
||||
if self.type == C.CHAT_GROUP:
|
||||
if entity.bare == self.target and entity.resource in self.occupants:
|
||||
self.occupants[entity.resource].update('avatar')
|
||||
for m in self.messages.values():
|
||||
if m.nick == entity.resource:
|
||||
for w in m.widgets:
|
||||
w.update('avatar', filename)
|
||||
else:
|
||||
if entity.bare == self.target.bare:
|
||||
log.info("entity avatar updated")
|
||||
# TODO: call a specific method
|
||||
|
||||
|
||||
quick_widgets.register(QuickChat)
|
||||
|
|
|
|||
Loading…
Reference in a new issue