Author: asterix
Date: 2007-07-04 18:33:40 +0200 (Wed, 04 Jul 2007)
New Revision: 8357
Modified:
trunk/src/common/contacts.py
trunk/src/gajim.py
Log:
use get_contact() when we give the resource. see #3275
Modified: trunk/src/common/contacts.py
===================================================================
--- trunk/src/common/contacts.py 2007-07-04 13:29:06 UTC (rev 8356)
+++ trunk/src/common/contacts.py 2007-07-04 16:33:40 UTC (rev 8357)
@@ -218,10 +218,12 @@
else:
return []
- def get_contact(self, account, jid, resource):
- '''Returns the contact instance for the given resource if it's given
- or None if there is not'''
+ def get_contact(self, account, jid, resource = None):
+ '''Returns the contact instance for the given resource if it's given else
+ the first contact is no resource is given or None if there is not'''
if jid in self._contacts[account]:
+ if not resource:
+ return self._contacts[account][jid][0]
for c in self._contacts[account][jid]:
if c.resource == resource:
return c
Modified: trunk/src/gajim.py
===================================================================
--- trunk/src/gajim.py 2007-07-04 13:29:06 UTC (rev 8356)
+++ trunk/src/gajim.py 2007-07-04 16:33:40 UTC (rev 8357)
@@ -727,9 +727,7 @@
chat_control = self.msg_win_mgr.get_control(jid, account)
# Handle chat states
- contact = gajim.contacts.get_contacts(account, jid, resource)
- if contact and isinstance(contact, list):
- contact = contact[0]
+ contact = gajim.contacts.get_contact(account, jid, resource)
if contact:
if contact.composing_xep != 'XEP-0085': # We cache xep85 support
contact.composing_xep = composing_xep
@@ -1053,11 +1051,7 @@
elif self.instances[account]['infos'].has_key(array[0] + '/' + array[1]):
win = self.instances[account]['infos'][array[0] + '/' + array[1]]
if win:
- c = gajim.contacts.get_contacts(account, array[0], array[1])
- # c is a list when no resource is given. it probably means that contact
- # is offline, so only on Contact instance
- if isinstance(c, list) and len(c):
- c = c[0]
+ c = gajim.contacts.get_contact(account, array[0], array[1])
if c: # c can be none if it's a gc contact
c.last_status_time = time.localtime(time.time() - array[2])
if array[3]:
@@ -2190,8 +2184,10 @@
gajim.events.change_jid(account, fjid, jid)
resource = None
fjid = jid
- contact = gajim.contacts.get_contacts(account, jid, resource)
- if not contact or isinstance(contact, list):
+ contact = None
+ if resource:
+ contact = gajim.contacts.get_contact(account, jid, resource)
+ if not contact:
contact = highest_contact
self.roster.new_chat(contact, account, resource = resource)
w = self.msg_win_mgr.get_window(fjid, account)