Show
Ignore:
Timestamp:
08/09/07 17:39:18 (17 months ago)
Author:
asterix
Message:

merge diff from trunk to pep branch

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/pep/src/common/contacts.py

    r8197 r8478  
    33## Copyright (C) 2006 Yann Le Boulanger <asterix@lagaule.org> 
    44## Copyright (C) 2006 Nikos Kouremenos <kourem@gmail.com> 
     5## Copyright (C) 2007 Lukas Petrovicky <lukas@petrovicky.net> 
     6## Copyright (C) 2007 Julien Pivotto <roidelapluie@gmail.com> 
    57## 
    68## 
     
    2123        def __init__(self, jid='', name='', groups=[], show='', status='', sub='', 
    2224        ask='', resource='', priority=0, keyID='', our_chatstate=None, 
    23         chatstate=None, last_status_time=None, msg_id = None, composing_jep = None): 
     25        chatstate=None, last_status_time=None, msg_id = None, composing_xep = None): 
    2426                self.jid = jid 
    2527                self.name = name 
     
    3840                self.keyID = keyID 
    3941 
     42                # Capabilities; filled by caps.py/ConnectionCaps object 
     43                # every time it gets these from presence stanzas 
     44                self.caps_node=None 
     45                self.caps_ver=None 
     46                self.caps_exts=None 
     47 
    4048                # please read jep-85 http://www.jabber.org/jeps/jep-0085.html 
    4149                # we keep track of jep85 support with the peer by three extra states: 
     
    4856                self.msg_id = msg_id 
    4957                # tell which JEP we're using for composing state 
    50                 # None = have to ask, JEP-0022 = use this jep, 
    51                 # JEP-0085 = use this jep, False = no composing support 
    52                 self.composing_jep = composing_jep 
     58                # None = have to ask, XEP-0022 = use this jep, 
     59                # XEP-0085 = use this jep, False = no composing support 
     60                self.composing_xep = composing_xep 
    5361                # this is contact's chatstate 
    5462                self.chatstate = chatstate 
     
    154162        def create_contact(self, jid='', name='', groups=[], show='', status='', 
    155163                sub='', ask='', resource='', priority=0, keyID='', our_chatstate=None, 
    156                 chatstate=None, last_status_time=None, composing_jep=None): 
     164                chatstate=None, last_status_time=None, composing_xep=None): 
    157165                return Contact(jid, name, groups, show, status, sub, ask, resource, 
    158166                        priority, keyID, our_chatstate, chatstate, last_status_time, 
    159                         composing_jep) 
     167                        composing_xep) 
    160168         
    161169        def copy_contact(self, contact): 
     
    209217                self.remove_metacontact(account, jid) 
    210218 
     219        def get_contacts(self, account, jid): 
     220                '''Returns the list of contact instances for this jid.''' 
     221                if jid in self._contacts[account]: 
     222                        return self._contacts[account][jid] 
     223                else: 
     224                        return [] 
     225         
    211226        def get_contact(self, account, jid, resource = None): 
    212                 '''Returns the list of contact instances for this jid (one per resource) 
    213                 or [] if no resource is given 
    214                 returns the contact instance for the given resource if it's given 
    215                 or None if there is not''' 
     227                '''Returns the contact instance for the given resource if it's given else 
     228                the first contact is no resource is given or None if there is not''' 
    216229                if jid in self._contacts[account]: 
    217                         contacts = self._contacts[account][jid] 
    218230                        if not resource: 
    219                                 return contacts 
    220                         for c in contacts: 
     231                                return self._contacts[account][jid][0] 
     232                        for c in self._contacts[account][jid]: 
    221233                                if c.resource == resource: 
    222234                                        return c 
    223                 if resource: 
    224                         return None 
    225                 return [] 
    226  
    227         def get_contacts_from_jid(self, account, jid): 
    228                 '''we may have two or more resources on that jid''' 
    229                 if jid in self._contacts[account]: 
    230                         contacts_instances = self._contacts[account][jid] 
    231                         return contacts_instances 
    232                 return [] 
     235                return None 
     236 
     237        def get_contact_from_full_jid(self, account, fjid): 
     238                ''' Get Contact object for specific resource of given jid''' 
     239                barejid, resource = common.gajim.get_room_and_nick_from_fjid(fjid) 
     240                return self.get_contact(account, barejid, resource) 
    233241 
    234242        def get_highest_prio_contact_from_contacts(self, contacts): 
     
    242250 
    243251        def get_contact_with_highest_priority(self, account, jid): 
    244                 contacts = self.get_contacts_from_jid(account, jid) 
     252                contacts = self.get_contacts(account, jid) 
    245253                if not contacts and '/' in jid: 
    246254                        # jid may be a fake jid, try it 
     
    259267                group_contacts = [] 
    260268                for jid in self._contacts[account]: 
    261                         contacts = self.get_contacts_from_jid(account, jid) 
     269                        contacts = self.get_contacts(account, jid) 
    262270                        if group in contacts[0].groups: 
    263271                                group_contacts += contacts