diff options
author | Yann Leboulanger <asterix@lagaule.org> | 2005-12-21 19:32:32 +0300 |
---|---|---|
committer | Yann Leboulanger <asterix@lagaule.org> | 2005-12-21 19:32:32 +0300 |
commit | a15a6e8e6e91ed94a1f9f8240bc89fac40d7f2d3 (patch) | |
tree | f6cfaef3e8b1d1d199e6922efa13a69c75496f78 | |
parent | 0af7e48bf1c284d01163960fd9a1b941d7e0c6ec (diff) |
move some functions from gajim to contacts, rename some functions
-rw-r--r-- | src/common/contacts.py | 42 | ||||
-rw-r--r-- | src/common/gajim.py | 23 |
2 files changed, 38 insertions, 27 deletions
diff --git a/src/common/contacts.py b/src/common/contacts.py index a2e7b54b8..59fcce4ee 100644 --- a/src/common/contacts.py +++ b/src/common/contacts.py @@ -76,6 +76,20 @@ class Contacts: self._gc_contacts = {} # list of contacts that are in gc {acct: {room_jid: {nick: C}}} self._sub_contacts = {} # {acct: {jid1: jid2}} means jid1 is sub of jid2 + def change_account_name(self, old_name, new_name): + self._contacts[new_name] = self._contacts[old_name] + self._gc_contacts[new_name] = self._gc_contacts[old_name] + self._contacts.remove(old_name) + self._gc_contacts.remove(old_name) + + def add_account(self, account): + self._contacts[account] = {} + self._gc_contacts[account] = {} + + def remove_account(self, account): + self._contacts.remove(account) + self._gc_contacts.remove(account) + def create_contact(self, jid='', name='', groups=[], show='', status='', sub='', ask='', resource='', priority=5, keyID='', our_chatstate=None, chatstate=None): @@ -151,7 +165,7 @@ class Contacts: if contact.jid in self._sub_contacts[account]: return True - def get_contact_instances_from_jid(self, account, jid): + def get_contacts_from_jid(self, account, jid): ''' we may have two or more resources on that jid ''' if jid in self._contacts[account]: contacts_instances = self._contacts[account][jid] @@ -167,16 +181,26 @@ class Contacts: prim_contact = contact return prim_contact - def get_contact_instance_with_highest_priority(self, account, jid): - contact_instances = self.get_contact_instances_from_jid(account, jid) - return self.get_highest_prio_contact_from_contacts(contact_instances) + def get_contact_with_highest_priority(self, account, jid): + contacts = self.get_contacts_from_jid(account, jid) + return self.get_highest_prio_contact_from_contacts(contacts) + + def get_first_contact_from_jid(self, account, jid): + if jid in self._contacts[account]: + return self._contacts[account][jid][0] + else: # it's fake jid + room, nick = gajim.get_room_and_nick_from_fjid(jid) + if self._gc_contacts[account].has_key(room) and \ + nick in self._gc_contacts[account][room]: + return self._gc_contacts[account][room][nick] + return None def get_parent_contact(self, account, contact): '''Returns the parent contact of contact if it's a sub-contact, else contact''' if is_subcontact(account, contact): parrent_jid = self._sub_contacts[account][contact.jid] - return self.get_contact_instance_with_highest_priority(account, + return self.get_contact_with_highest_priority(account, parrent_jid) return contact @@ -185,7 +209,7 @@ class Contacts: sub-contact, else contact''' while is_subcontact(account, contact): parrent_jid = self._sub_contacts[account][contact.jid] - contact = self.get_contact_instance_with_highest_priority(account, + contact = self.get_contact_with_highest_priority(account, parrent_jid) return contact @@ -194,3 +218,9 @@ class Contacts: return Contact(jid = gc_contact.get_full_jid(), name = gc_contact.nick, groups = ['none'], show = gc_contact.show, status = gc_contact.status, sub = 'none') + + def is_pm_from_jid(self, account, jid): + '''Returns True if the given jid is a private message jid''' + if jid in self._contacts[account]: + return False + return True diff --git a/src/common/gajim.py b/src/common/gajim.py index e138938a1..ed31c8775 100644 --- a/src/common/gajim.py +++ b/src/common/gajim.py @@ -29,7 +29,7 @@ import logging import mutex import config - +from contacts import Contacts interface = None # The actual interface (the gtk one for the moment) version = '0.9' @@ -77,8 +77,7 @@ last_message_time = {} # list of time of the latest incomming message # {acct1: {jid1: time1, jid2: time2}, } encrypted_chats = {} # list of encrypted chats {acct1: [jid1, jid2], ..} -contacts = {} # list of contacts {acct: {jid1: [C1, C2]}, } one Contact per resource -gc_contacts = {} # list of contacts that are in gc {acct: {room_jid: {nick: C}}} +contacts = Contacts gc_connected = {} # tell if we are connected to the room or not {acct: {room_jid: True}} gc_passwords = {} # list of the pass required to enter a room {room_jid: password} @@ -159,12 +158,6 @@ def get_real_jid_from_fjid(account, fjid): def get_room_from_fjid(jid): return get_room_and_nick_from_fjid(jid)[0] -def get_contact_instances_from_jid(account, jid): - ''' we may have two or more resources on that jid ''' - if jid in contacts[account]: - contacts_instances = contacts[account][jid] - return contacts_instances - def get_first_contact_instance_from_jid(account, jid): contact = None if jid in contacts[account]: @@ -178,21 +171,9 @@ def get_first_contact_instance_from_jid(account, jid): contact = gc_contacts[account][room][nick] return contact -def get_contact_instance_with_highest_priority(account, jid): - contact_instances = contacts[account][jid] - return get_highest_prio_contact_from_contacts(contact_instances) - def get_contact_name_from_jid(account, jid): return contacts[account][jid][0].name -def get_highest_prio_contact_from_contacts(contacts): - prim_contact = None # primary contact - for contact in contacts: - if prim_contact == None or int(contact.priority) > \ - int(prim_contact.priority): - prim_contact = contact - return prim_contact - def get_jid_without_resource(jid): return jid.split('/')[0] |