Show
Ignore:
Timestamp:
05/05/08 23:55:59 (7 months ago)
Author:
asterix
Message:

[Florob] Send and handle nicknames reveices through PEP. Fixes #3651

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common/pep.py

    r9580 r9585  
    225225                        del contact.activity['text'] 
    226226 
     227def user_nickname(items, name, jid): 
     228        has_child = False 
     229        retract = False 
     230        nick = None 
     231 
     232        for item in items.getTags('item'): 
     233                child = item.getTag('nick') 
     234                if child is not None: 
     235                        has_child = True 
     236                        nick = child.getData() 
     237                        break 
     238 
     239        if items.getTag('retract') is not None: 
     240                retract = True 
     241 
     242        if jid == gajim.get_jid_from_account(name): 
     243                if has_child: 
     244                        gajim.nicks[name] = nick 
     245                if retract: 
     246                        gajim.nicks[name] = gajim.config.get_per('accounts', name, 'name') 
     247 
     248        (user, resource) = gajim.get_room_and_nick_from_fjid(jid) 
     249        contact = gajim.contacts.get_contact(name, user, resource=resource) 
     250        if not contact: 
     251                return 
     252        if has_child: 
     253                if nick is not None: 
     254                        contact.contact_name = nick 
     255                        gajim.interface.roster.draw_contact(user, name) 
     256                        ctrl = gajim.interface.msg_win_mgr.get_control(user, name) 
     257                        if ctrl: 
     258                                ctrl.update_ui() 
     259                                win = gajim.interface.msg_win_mgr.get_window(user, name) 
     260                                win.redraw_tab(ctrl) 
     261                                win.show_title() 
     262        elif retract: 
     263                contact.contact_name = '' 
     264 
    227265def user_send_mood(account, mood, message = ''): 
    228266        if not gajim.config.get('publish_mood'): 
     
    276314        gajim.connections[account].send_pb_publish('', xmpp.NS_TUNE, item, '0') 
    277315 
     316def user_send_nickname(account, nick): 
     317        if not (gajim.config.get('publish_nick') and \ 
     318        gajim.connections[account].pep_supported): 
     319                return 
     320        item = xmpp.Node('nick', {'xmlns': xmpp.NS_NICK}) 
     321        item.addData(nick) 
     322 
     323        gajim.connections[account].send_pb_publish('', xmpp.NS_NICK, item, '0') 
     324 
    278325def user_retract_mood(account): 
    279326        gajim.connections[account].send_pb_retract('', xmpp.NS_MOOD, '0') 
     
    284331def user_retract_tune(account): 
    285332        gajim.connections[account].send_pb_retract('', xmpp.NS_TUNE, '0') 
     333 
     334def user_retract_nickname(account): 
     335        gajim.connections[account].send_pb_retract('', xmpp.NS_NICK, '0')