Changeset 8709 for branches/gajim_0.11.1

Show
Ignore:
Timestamp:
09/04/07 20:32:31 (15 months ago)
Author:
asterix
Message:

ask vcard to rela jid in muc if we knows it

Location:
branches/gajim_0.11.1/src
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • branches/gajim_0.11.1/src/chat_control.py

    r8683 r8709  
    15891589                        return 
    15901590 
    1591                 jid = self.contact.jid 
    1592                 jid_with_resource = jid 
    1593                 if resource: 
    1594                         jid_with_resource += '/' + resource 
     1591                is_fake = False 
     1592                if self.TYPE_ID == message_control.TYPE_PM: 
     1593                        is_fake = True 
     1594                        jid_with_resource = self.contact.jid # fake jid 
     1595                else: 
     1596                        jid_with_resource = self.contact.jid 
     1597                        if resource: 
     1598                                jid_with_resource += '/' + resource 
    15951599 
    15961600                # we assume contact has no avatar 
    15971601                scaled_pixbuf = None 
    15981602 
    1599                 pixbuf = None 
    1600                 is_fake = False 
    1601                 if gajim.contacts.is_pm_from_jid(self.account, jid): 
    1602                         is_fake = True 
    16031603                pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid_with_resource, 
    16041604                        is_fake) 
    16051605                if pixbuf == 'ask': 
    16061606                        # we don't have the vcard 
    1607                         gajim.connections[self.account].request_vcard(jid_with_resource, 
    1608                                 is_fake) 
     1607                        if self.TYPE_ID == message_control.TYPE_PM: 
     1608                                if self.gc_contact.jid: 
     1609                                        # We know the real jid of this contact 
     1610                                        real_jid = self.gc_contact.jid 
     1611                                        if self.gc_contact.resource: 
     1612                                                real_jid += '/' + self.gc_contact.resource 
     1613                                else: 
     1614                                        real_jid = jid_with_resource 
     1615                                gajim.connections[self.account].request_vcard(real_jid, 
     1616                                        jid_with_resource) 
     1617                        else: 
     1618                                gajim.connections[self.account].request_vcard(jid_with_resource) 
    16091619                        return 
    16101620                if pixbuf is not None: 
  • branches/gajim_0.11.1/src/common/connection_handlers.py

    r8699 r8709  
    797797                self.vcard_shas = {} # sha of contacts 
    798798                self.room_jids = [] # list of gc jids so that vcard are saved in a folder 
     799                self.groupchat_jids = {} # {ID : groupchat_jid} 
    799800                 
    800801        def add_sha(self, p, send_caps = True): 
     
    895896                return vcard 
    896897 
    897         def request_vcard(self, jid = None, is_fake_jid = False): 
    898                 '''request the VCARD. If is_fake_jid is True, it means we request a vcard 
    899                 to a fake jid, like in private messages in groupchat''' 
     898        def request_vcard(self, jid = None, groupchat_jid = None): 
     899                '''request the VCARD. If groupchat_jid is not nul, it means we request a vcard 
     900                to a fake jid, like in private messages in groupchat. jid can be the 
     901                real jid of the contact, but we want to consider it comes from a fake jid''' 
    900902                if not self.connection: 
    901903                        return 
     
    910912                if not j: 
    911913                        j = gajim.get_jid_from_account(self.name) 
    912                 self.awaiting_answers[id] = (VCARD_ARRIVED, j) 
    913                 if is_fake_jid: 
    914                         room_jid, nick = gajim.get_room_and_nick_from_fjid(jid) 
     914                self.awaiting_answers[id] = (VCARD_ARRIVED, j, groupchat_jid) 
     915                if groupchat_jid: 
     916                        room_jid, nick = gajim.get_room_and_nick_from_fjid(groupchat_jid) 
    915917                        if not room_jid in self.room_jids: 
    916918                                self.room_jids.append(room_jid) 
     919                        self.groupchat_jids[id] = groupchat_jid 
    917920                self.connection.send(iq) 
    918                         #('VCARD', {entry1: data, entry2: {entry21: data, ...}, ...}) 
    919921 
    920922        def send_vcard(self, vcard): 
     
    9991001                        # it knows it arrived 
    10001002                        jid = self.awaiting_answers[id][1] 
     1003                        groupchat_jid = self.awaiting_answers[id][2] 
     1004                        frm = jid 
     1005                        if groupchat_jid: 
     1006                                # We do as if it comes from the fake_jid 
     1007                                frm = groupchat_jid 
    10011008                        our_jid = gajim.get_jid_from_account(self.name) 
    10021009                        if iq_obj.getType() == 'error' and jid == our_jid: 
     
    10041011                                self.vcard_supported = False 
    10051012                        if not iq_obj.getTag('vCard') or iq_obj.getType() == 'error': 
    1006                                 if jid and jid != our_jid: 
     1013                                if frm and frm != our_jid: 
    10071014                                        # Write an empty file 
    1008                                         self.save_vcard_to_hd(jid, '') 
    1009                                         self.dispatch('VCARD', {'jid': jid}) 
    1010                                 elif jid == our_jid: 
    1011                                         self.dispatch('MYVCARD', {'jid': jid}) 
     1015                                        self.save_vcard_to_hd(frm, '') 
     1016                                        self.dispatch('VCARD', {'jid': frm}) 
     1017                                elif frm == our_jid: 
     1018                                        self.dispatch('MYVCARD', {'jid': frm}) 
    10121019                elif self.awaiting_answers[id][0] == AGENT_REMOVED: 
    10131020                        jid = self.awaiting_answers[id][1] 
     
    10521059                if not vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD: 
    10531060                        return 
     1061                id = vc.getID() 
    10541062                frm_iq = vc.getFrom() 
    10551063                our_jid = gajim.get_jid_from_account(self.name) 
    10561064                resource = '' 
    1057                 if frm_iq: 
     1065                if id in self.groupchat_jids: 
     1066                        who = self.groupchat_jids[id] 
     1067                        frm, resource = gajim.get_room_and_nick_from_fjid(who) 
     1068                        del self.groupchat_jids[id] 
     1069                elif frm_iq: 
    10581070                        who = helpers.get_full_jid_from_iq(vc) 
    10591071                        frm, resource = gajim.get_room_and_nick_from_fjid(who) 
     
    11271139                        self.connection.send(p) 
    11281140                else: 
     1141                        #('VCARD', {entry1: data, entry2: {entry21: data, ...}, ...}) 
    11291142                        self.dispatch('VCARD', vcard) 
    11301143 
     
    16551668                                if gajim.config.get('log_contact_status_changes') and self.name\ 
    16561669                                not in no_log_for and jid_stripped not in no_log_for: 
    1657                                         gc_c = gajim.contacts.get_gc_contact(self.name, jid_stripped, resource) 
     1670                                        gc_c = gajim.contacts.get_gc_contact(self.name, jid_stripped, 
     1671                                                resource) 
    16581672                                        st = status or '' 
    16591673                                        if gc_c: 
     
    16731687                                                puny_nick = helpers.sanitize_filename(resource) 
    16741688                                                gajim.interface.remove_avatar_files(jid_stripped, puny_nick) 
    1675                                         if self.vcard_shas.has_key(who): # Verify sha cached in mem 
    1676                                                 if avatar_sha != self.vcard_shas[who]: 
    1677                                                         # avatar has been updated 
    1678                                                         self.request_vcard(who, True) 
    1679                                         else: # Verify sha cached in hdd 
    1680                                                 cached_vcard = self.get_cached_vcard(who, True) 
    1681                                                 if cached_vcard and cached_vcard.has_key('PHOTO') and \ 
    1682                                                 cached_vcard['PHOTO'].has_key('SHA'): 
    1683                                                         cached_sha = cached_vcard['PHOTO']['SHA'] 
    1684                                                 else: 
    1685                                                         cached_sha = '' 
    1686                                                 if cached_sha != avatar_sha: 
    1687                                                         # avatar has been updated 
    1688                                                         # sha in mem will be updated later 
    1689                                                         self.request_vcard(who, True) 
    1690                                                 else: 
    1691                                                         # save sha in mem NOW 
    1692                                                         self.vcard_shas[who] = avatar_sha 
     1689                                        # if it's a gc presence, don't ask vcard here. We may ask it to 
     1690                                        # real jid in gui part. 
    16931691                                self.dispatch('GC_NOTIFY', (jid_stripped, show, status, resource, 
    16941692                                        prs.getRole(), prs.getAffiliation(), prs.getJid(), 
    16951693                                        prs.getReason(), prs.getActor(), prs.getStatusCode(), 
    1696                                         prs.getNewNick())) 
     1694                                        prs.getNewNick(), avatar_sha)) 
    16971695                        return 
    16981696 
  • branches/gajim_0.11.1/src/gajim.py

    r8700 r8709  
    759759                                        gc_c = gajim.contacts.create_gc_contact(room_jid = jid, 
    760760                                                name = nick, show = show) 
    761                                         c = gajim.contacts.contact_from_gc_contact(gc_c) 
    762                                         self.roster.new_chat(c, account, private_chat = True) 
     761                                        self.roster.new_private_chat(gc_c, account) 
    763762                                ctrl = self.msg_win_mgr.get_control(full_jid_with_resource, account) 
    764763                                ctrl.print_conversation('Error %s: %s' % (array[1], array[2]), 
     
    10011000        def handle_event_gc_notify(self, account, array): 
    10021001                #'GC_NOTIFY' (account, (room_jid, show, status, nick, 
    1003                 # role, affiliation, jid, reason, actor, statusCode, newNick)) 
     1002                # role, affiliation, jid, reason, actor, statusCode, newNick, avatar_sha)) 
    10041003                nick = array[3] 
    10051004                if not nick: 
     
    10171016                if control: 
    10181017                        control.chg_contact_status(nick, show, status, array[4], array[5], 
    1019                                 array[6], array[7], array[8], array[9], array[10]) 
     1018                                array[6], array[7], array[8], array[9], array[10], array[11]) 
    10201019 
    10211020                # print status in chat window and update status/GPG image 
  • branches/gajim_0.11.1/src/groupchat_control.py

    r8696 r8709  
    104104        TYPE_ID = message_control.TYPE_PM 
    105105 
    106         def __init__(self, parent_win, contact, acct): 
     106        def __init__(self, parent_win, gc_contact, contact, acct): 
    107107                room_jid = contact.jid.split('/')[0] 
    108108                room_ctrl = gajim.interface.msg_win_mgr.get_control(room_jid, acct) 
    109109                self.room_name = room_ctrl.name 
     110                self.gc_contact = gc_contact 
    110111                ChatControl.__init__(self, parent_win, contact, acct) 
    111112                self.TYPE_ID = 'pm' 
     
    826827 
    827828        def chg_contact_status(self, nick, show, status, role, affiliation, jid, 
    828         reason, actor, statusCode, new_nick): 
     829        reason, actor, statusCode, new_nick, avatar_sha, tim = None): 
    829830                '''When an occupant changes his or her status''' 
    830831                if show == 'invisible': 
     
    835836                if not affiliation: 
    836837                        affiliation = 'none' 
    837  
     838                fake_jid = self.room_jid + '/' + nick 
    838839                newly_created = False 
    839840                if show in ('offline', 'error'): 
     
    896897                                self.print_conversation(s, 'info') 
    897898 
    898                         if len(gajim.events.get_events(self.account, 
    899                         self.room_jid + '/' + nick)) == 0: 
     899                        if len(gajim.events.get_events(self.account, fake_jid)) == 0: 
    900900                                self.remove_contact(nick) 
    901901                        else: 
     
    955955                                                affiliation, status, jid) 
    956956                                else: 
    957                                         c = gajim.contacts.get_gc_contact(self.account, self.room_jid, 
    958                                                 nick) 
    959                                         if c.show == show and c.status == status and \ 
    960                                                 c.affiliation == affiliation: #no change 
     957                                        if gc_c.show == show and gc_c.status == status and \ 
     958                                                gc_c.affiliation == affiliation: # no change 
    961959                                                return 
    962                                         c.show = show 
    963                                         c.affiliation = affiliation 
    964                                         c.status = status 
     960                                        gc_c.show = show 
     961                                        gc_c.affiliation = affiliation 
     962                                        gc_c.status = status 
    965963                                        self.draw_contact(nick) 
    966964 
     
    10291027                if gajim.config.get('ask_avatars_on_startup') and \ 
    10301028                not server.startswith('irc'): 
    1031                         fjid = self.room_jid + '/' + nick 
    1032                         pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(fjid, True) 
     1029                        fake_jid = self.room_jid + '/' + nick 
     1030                        pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(fake_jid, True) 
    10331031                        if pixbuf == 'ask': 
    1034                                 gajim.connections[self.account].request_vcard(fjid, True) 
     1032                                if j: 
     1033                                        fjid = j 
     1034                                        if resource: 
     1035                                                fjid += '/' + resource 
     1036                                        gajim.connections[self.account].request_vcard(fjid, fake_jid) 
     1037                                else: 
     1038                                        gajim.connections[self.account].request_vcard(fake_jid, fake_jid) 
    10351039                if nick == self.nick: # we became online 
    10361040                        self.got_connected() 
     
    17481752        def _start_private_message(self, nick): 
    17491753                gc_c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick) 
    1750                 c = gajim.contacts.contact_from_gc_contact(gc_c) 
    1751                 nick_jid = c.jid 
     1754                nick_jid = gc_c.get_full_jid() 
    17521755 
    17531756                win = gajim.interface.msg_win_mgr.get_window(nick_jid, self.account) 
    17541757                if not win: 
    1755                         gajim.interface.roster.new_chat(c, self.account, private_chat = True) 
     1758                        gajim.interface.roster.new_private_chat(gc_c, self.account) 
    17561759                        win = gajim.interface.msg_win_mgr.get_window(nick_jid, self.account) 
    17571760                win.set_active_tab(nick_jid, self.account) 
  • branches/gajim_0.11.1/src/roster_window.py

    r8707 r8709  
    30563056                self.update_status_combobox() 
    30573057 
    3058         def new_chat(self, contact, account, private_chat = False, resource = None): 
     3058        def new_private_chat(self, gc_contact, account): 
     3059                contact = gajim.contacts.contact_from_gc_contact(gc_contact) 
     3060                type_ = message_control.TYPE_PM 
     3061                fjid = gc_contact.room_jid + '/' + gc_contact.name 
     3062                mw = gajim.interface.msg_win_mgr.get_window(fjid, account) 
     3063                if not mw: 
     3064                        mw = gajim.interface.msg_win_mgr.create_window(contact, account, type_) 
     3065 
     3066                chat_control = PrivateChatControl(mw, gc_contact, contact, account) 
     3067                mw.new_tab(chat_control) 
     3068                if len(gajim.events.get_events(account, fjid)): 
     3069                        # We call this here to avoid race conditions with widget validation 
     3070                        chat_control.read_queue() 
     3071 
     3072        def new_chat(self, contact, account, resource = None): 
    30593073                # Get target window, create a control, and associate it with the window 
    3060                 if not private_chat: 
    3061                         type_ = message_control.TYPE_CHAT 
    3062                 else: 
    3063                         type_ = message_control.TYPE_PM 
     3074                type_ = message_control.TYPE_CHAT 
    30643075 
    30653076                fjid = contact.jid 
     
    30703081                        mw = gajim.interface.msg_win_mgr.create_window(contact, account, type_) 
    30713082 
    3072                 if not private_chat: 
    3073                         chat_control = ChatControl(mw, contact, account, resource) 
    3074                 else: 
    3075                         chat_control = PrivateChatControl(mw, contact, account) 
     3083                chat_control = ChatControl(mw, contact, account, resource) 
    30763084 
    30773085                mw.new_tab(chat_control) 
  • branches/gajim_0.11.1/src/vcard.py

    r8621 r8709  
    359359                self.fill_status_label() 
    360360 
    361                 gajim.connections[self.account].request_vcard(self.contact.jid, 
    362                         self.gc_contact is not None) 
     361                if self.gc_contact: 
     362                        gajim.connections[self.account].request_vcard(self.contact.jid, 
     363                                self.gc_contact.get_full_jid()) 
     364                else: 
     365                        gajim.connections[self.account].request_vcard(self.contact.jid) 
    363366 
    364367        def on_close_button_clicked(self, widget):