diff options
author | Yann Leboulanger <asterix@lagaule.org> | 2008-11-03 17:25:08 +0300 |
---|---|---|
committer | Yann Leboulanger <asterix@lagaule.org> | 2008-11-03 17:25:08 +0300 |
commit | 67d19a226d2db8f79cc1a93f92913424245b3dd5 (patch) | |
tree | 83f54b33f7e5c983c9756d47f62bd899fcc7899b /src/common | |
parent | bf93cb76f123fdb7631a3ca25e1a6ef6219d671c (diff) |
handle mood in messages, send mood in message if pep is not supported on server. Fixes #4449
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/connection.py | 9 | ||||
-rw-r--r-- | src/common/connection_handlers.py | 12 | ||||
-rw-r--r-- | src/common/pep.py | 41 |
3 files changed, 42 insertions, 20 deletions
diff --git a/src/common/connection.py b/src/common/connection.py index 84c48f9ac..b3d16dca2 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1132,9 +1132,16 @@ class Connection(ConnectionHandlers): # XEP-0172: user_nickname if user_nick: - msg_iq.setTag('nick', namespace = common.xmpp.NS_NICK).setData( + msg_iq.setTag('nick', namespace=common.xmpp.NS_NICK).setData( user_nick) + # XEP-0107: User Mood + if 'mood' in self.mood and not self.pep_supported: + mood_iq = msg_iq.setTag('mood', namespace=common.xmpp.NS_MOOD) + mood_iq.setTag(self.mood['mood']) + if 'text' in self.mood and self.mood['text']: + mood_iq.setTagData('text', self.mood['text']) + # TODO: We might want to write a function so we don't need to # reproduce that ugly if somewhere else. if resource: diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 1aa57e95d..652f2a411 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1805,6 +1805,18 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, session.control.conv_textview.hide_xep0184_warning( msg.getID()) + # Check mood in message + if msg.getTag('mood', namespace=common.xmpp.NS_MOOD): + mood_iq = msg.getTag('mood', namespace=common.xmpp.NS_MOOD) + mood = None + text = None + for ch in mood_iq.getChildren(): + if ch.getName() != 'text': + mood = ch.getName() + else: + text = ch.getData() + pep.handle_mood(self.name, jid, mood=mood, text=text, retract=False) + if encTag and self.USE_GPG: encmsg = encTag.getData() diff --git a/src/common/pep.py b/src/common/pep.py index 6dc3bfd8c..c844fbf5a 100644 --- a/src/common/pep.py +++ b/src/common/pep.py @@ -201,45 +201,48 @@ def user_mood(items, name, jid): text = ch.getData() if items.getTag('retract') is not None: retract = True + if has_child or retract: + handle_mood(name, jid, mood=mood, text=text, retract=retract) - if jid == gajim.get_jid_from_account(name): - acc = gajim.connections[name] - if has_child: +def handle_mood(account, jid, mood=None, text=None, retract=False): + if jid == gajim.get_jid_from_account(account): + acc = gajim.connections[account] + if retract: if 'mood' in acc.mood: del acc.mood['mood'] if 'text' in acc.mood: del acc.mood['text'] - if mood is not None: - acc.mood['mood'] = mood - if text is not None: - acc.mood['text'] = text - elif retract: + else: if 'mood' in acc.mood: del acc.mood['mood'] if 'text' in acc.mood: del acc.mood['text'] + if mood is not None: + acc.mood['mood'] = mood + if text is not None: + acc.mood['text'] = text (user, resource) = gajim.get_room_and_nick_from_fjid(jid) - for contact in gajim.contacts.get_contacts(name, user): - if has_child: + for contact in gajim.contacts.get_contacts(account, user): + if retract: if 'mood' in contact.mood: del contact.mood['mood'] if 'text' in contact.mood: del contact.mood['text'] - if mood is not None: - contact.mood['mood'] = mood - if text is not None: - contact.mood['text'] = text - elif retract: + else: if 'mood' in contact.mood: del contact.mood['mood'] if 'text' in contact.mood: del contact.mood['text'] + if mood is not None: + contact.mood['mood'] = mood + if text is not None: + contact.mood['text'] = text - if jid == gajim.get_jid_from_account(name): - gajim.interface.roster.draw_account(name) - gajim.interface.roster.draw_mood(user, name) - ctrl = gajim.interface.msg_win_mgr.get_control(user, name) + if jid == gajim.get_jid_from_account(account): + gajim.interface.roster.draw_account(account) + gajim.interface.roster.draw_mood(user, account) + ctrl = gajim.interface.msg_win_mgr.get_control(user, account) if ctrl: ctrl.update_mood() |