[Lukas] split get_contact into get_contacts and get_contact. get_contact_from_full_jid uses get_contact. Maybe could be merged with optional argument, but it's clearer this way. Fixes #3275
This commit is contained in:
parent
070369fc2a
commit
8abd062365
7 changed files with 56 additions and 55 deletions
|
@ -4,6 +4,7 @@
|
|||
## Copyright (C) 2006-2007 Nikos Kouremenos <kourem@gmail.com>
|
||||
## Copyright (C) 2006 Travis Shirk <travis@pobox.com>
|
||||
## Copyright (C) 2006 Dimitur Kirov <dkirov@gmail.com>
|
||||
## Copyright (C) 2007 Lukas Petrovicky <lukas@petrovicky.net>
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published
|
||||
|
@ -1838,7 +1839,7 @@ class ChatControl(ChatControlBase):
|
|||
show_transports = gajim.config.get('show_transports_group')
|
||||
if (not show_transports and gajim.jid_is_transport(jid)) or \
|
||||
(not show_offline and typ == 'chat' and \
|
||||
len(gajim.contacts.get_contact(self.account, jid)) < 2):
|
||||
len(gajim.contacts.get_contacts(self.account, jid)) < 2):
|
||||
gajim.interface.roster.really_remove_contact(self.contact,
|
||||
self.account)
|
||||
elif typ == 'pm':
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
##
|
||||
## Copyright (C) 2006 Yann Le Boulanger <asterix@lagaule.org>
|
||||
## Copyright (C) 2006 Nikos Kouremenos <kourem@gmail.com>
|
||||
## Copyright (C) 2007 Lukas Petrovicky <lukas@petrovicky.net>
|
||||
##
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
|
@ -210,31 +211,26 @@ class Contacts:
|
|||
# remove metacontacts info
|
||||
self.remove_metacontact(account, jid)
|
||||
|
||||
def get_contact(self, account, jid, resource = None):
|
||||
'''Returns the list of contact instances for this jid (one per resource)
|
||||
or [] if no resource is given
|
||||
returns the contact instance for the given resource if it's given
|
||||
def get_contacts(self, account, jid):
|
||||
'''Returns the list of contact instances for this jid.'''
|
||||
if jid in self._contacts[account]:
|
||||
return self._contacts[account][jid]
|
||||
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'''
|
||||
if jid in self._contacts[account]:
|
||||
contacts = self._contacts[account][jid]
|
||||
if not resource:
|
||||
return contacts
|
||||
for c in contacts:
|
||||
for c in self._contacts[account][jid]:
|
||||
if c.resource == resource:
|
||||
return c
|
||||
if resource:
|
||||
return None
|
||||
return []
|
||||
return None
|
||||
|
||||
def get_contact_from_full_jid(self, account, fjid):
|
||||
''' Get Contact object for specific resource of given jid'''
|
||||
barejid, resource = common.gajim.get_room_and_nick_from_fjid(fjid)
|
||||
if barejid in self._contacts[account]:
|
||||
contacts = self._contacts[account][barejid]
|
||||
for c in contacts:
|
||||
if c.resource==resource:
|
||||
return c
|
||||
return None
|
||||
return self.get_contact(account, barejid, resource)
|
||||
|
||||
def get_highest_prio_contact_from_contacts(self, contacts):
|
||||
if not contacts:
|
||||
|
@ -246,7 +242,7 @@ class Contacts:
|
|||
return prim_contact
|
||||
|
||||
def get_contact_with_highest_priority(self, account, jid):
|
||||
contacts = self.get_contact(account, jid)
|
||||
contacts = self.get_contacts(account, jid)
|
||||
if not contacts and '/' in jid:
|
||||
# jid may be a fake jid, try it
|
||||
room, nick = jid.split('/', 1)
|
||||
|
@ -263,7 +259,7 @@ class Contacts:
|
|||
'''Returns all contacts in the given group'''
|
||||
group_contacts = []
|
||||
for jid in self._contacts[account]:
|
||||
contacts = self.get_contact(account, jid)
|
||||
contacts = self.get_contacts(account, jid)
|
||||
if group in contacts[0].groups:
|
||||
group_contacts += contacts
|
||||
return group_contacts
|
||||
|
|
|
@ -115,7 +115,7 @@ class EditGroupsDialog:
|
|||
if not gajim.interface.roster.regroup and _account != account:
|
||||
continue
|
||||
for _jid in all_jid[_account]:
|
||||
contacts = gajim.contacts.get_contact(_account, _jid)
|
||||
contacts = gajim.contacts.get_contacts(_account, _jid)
|
||||
for c in contacts:
|
||||
if group in c.groups:
|
||||
c.groups.remove(group)
|
||||
|
@ -133,7 +133,7 @@ class EditGroupsDialog:
|
|||
if not gajim.interface.roster.regroup and _account != account:
|
||||
continue
|
||||
for _jid in all_jid[_account]:
|
||||
contacts = gajim.contacts.get_contact(_account, _jid)
|
||||
contacts = gajim.contacts.get_contacts(_account, _jid)
|
||||
for c in contacts:
|
||||
if not group in c.groups:
|
||||
c.groups.append(group)
|
||||
|
|
13
src/gajim.py
13
src/gajim.py
|
@ -6,6 +6,7 @@
|
|||
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com>
|
||||
## Copyright (C) 2005-2006 Dimitur Kirov <dkirov@gmail.com>
|
||||
## Copyright (C) 2005 Travis Shirk <travis@pobox.com>
|
||||
## Copyright (C) 2007 Lukas Petrovicky <lukas@petrovicky.net>
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published
|
||||
|
@ -543,7 +544,7 @@ class Interface:
|
|||
# Update contact
|
||||
jid_list = gajim.contacts.get_jid_list(account)
|
||||
if ji in jid_list or jid == gajim.get_jid_from_account(account):
|
||||
lcontact = gajim.contacts.get_contact(account, ji)
|
||||
lcontact = gajim.contacts.get_contacts(account, ji)
|
||||
contact1 = None
|
||||
resources = []
|
||||
for c in lcontact:
|
||||
|
@ -726,7 +727,7 @@ class Interface:
|
|||
chat_control = self.msg_win_mgr.get_control(jid, account)
|
||||
|
||||
# Handle chat states
|
||||
contact = gajim.contacts.get_contact(account, jid, resource)
|
||||
contact = gajim.contacts.get_contacts(account, jid, resource)
|
||||
if contact and isinstance(contact, list):
|
||||
contact = contact[0]
|
||||
if contact:
|
||||
|
@ -755,7 +756,7 @@ class Interface:
|
|||
return
|
||||
|
||||
if gajim.config.get('ignore_unknown_contacts') and \
|
||||
not gajim.contacts.get_contact(account, jid) and not pm:
|
||||
not gajim.contacts.get_contacts(account, jid) and not pm:
|
||||
return
|
||||
if not contact:
|
||||
# contact is not in the roster, create a fake one to display
|
||||
|
@ -1052,7 +1053,7 @@ class Interface:
|
|||
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_contact(account, array[0], array[1])
|
||||
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):
|
||||
|
@ -1274,7 +1275,7 @@ class Interface:
|
|||
sub = array[2]
|
||||
ask = array[3]
|
||||
groups = array[4]
|
||||
contacts = gajim.contacts.get_contact(account, jid)
|
||||
contacts = gajim.contacts.get_contacts(account, jid)
|
||||
# contact removes us.
|
||||
if (not sub or sub == 'none') and (not ask or ask == 'none') and \
|
||||
not name and not groups:
|
||||
|
@ -2189,7 +2190,7 @@ class Interface:
|
|||
gajim.events.change_jid(account, fjid, jid)
|
||||
resource = None
|
||||
fjid = jid
|
||||
contact = gajim.contacts.get_contact(account, jid, resource)
|
||||
contact = gajim.contacts.get_contacts(account, jid, resource)
|
||||
if not contact or isinstance(contact, list):
|
||||
contact = highest_contact
|
||||
self.roster.new_chat(contact, account, resource = resource)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com>
|
||||
## Copyright (C) 2005-2006 Dimitur Kirov <dkirov@gmail.com>
|
||||
## Copyright (C) 2005-2006 Andrew Sayman <lorien420@myrealbox.com>
|
||||
## Copyright (C) 2007 Lukas Petrovicky <lukas@petrovicky.net>
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published
|
||||
|
@ -410,7 +411,7 @@ class SignalObject(dbus.service.Object):
|
|||
if acct in accounts:
|
||||
for jid in gajim.contacts.get_jid_list(acct):
|
||||
item = self._contacts_as_dbus_structure(
|
||||
gajim.contacts.get_contact(acct, jid))
|
||||
gajim.contacts.get_contacts(acct, jid))
|
||||
if item:
|
||||
result.append(item)
|
||||
return result
|
||||
|
@ -503,7 +504,7 @@ class SignalObject(dbus.service.Object):
|
|||
accounts = [account]
|
||||
contact_exists = False
|
||||
for account in accounts:
|
||||
contacts = gajim.contacts.get_contact(account, jid)
|
||||
contacts = gajim.contacts.get_contacts(account, jid)
|
||||
if contacts:
|
||||
gajim.connections[account].unsubscribe(jid)
|
||||
for contact in contacts:
|
||||
|
@ -531,12 +532,12 @@ class SignalObject(dbus.service.Object):
|
|||
nick_in_roster = None # Is jid a nick ?
|
||||
for account in accounts:
|
||||
# Does jid exists in roster of one account ?
|
||||
if gajim.contacts.get_contact(account, jid):
|
||||
if gajim.contacts.get_contacts(account, jid):
|
||||
return jid
|
||||
if not nick_in_roster:
|
||||
# look in all contact if one has jid as nick
|
||||
for jid_ in gajim.contacts.get_jid_list(account):
|
||||
c = gajim.contacts.get_contact(account, jid_)
|
||||
c = gajim.contacts.get_contacts(account, jid_)
|
||||
if c[0].name == jid:
|
||||
nick_in_roster = jid_
|
||||
break
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org>
|
||||
## Copyright (C) 2005-2007 Nikos Kouremenos <kourem@gmail.com>
|
||||
## Copyright (C) 2005-2006 Dimitur Kirov <dkirov@gmail.com>
|
||||
## Copyright (C) 2007 Lukas Petrovicky <lukas@petrovicky.net>
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published
|
||||
|
@ -260,7 +261,7 @@ class RosterWindow:
|
|||
contact = gajim.contacts.get_first_contact_from_jid(account, jid)
|
||||
nb_events = gajim.events.get_nb_roster_events(account, contact.jid)
|
||||
# count events from all resources
|
||||
for contact_ in gajim.contacts.get_contact(account, jid):
|
||||
for contact_ in gajim.contacts.get_contacts(account, jid):
|
||||
if contact_.resource:
|
||||
nb_events += gajim.events.get_nb_roster_events(account,
|
||||
contact_.get_full_jid())
|
||||
|
@ -337,14 +338,14 @@ class RosterWindow:
|
|||
if (contact.show in ('offline', 'error') or hide) and \
|
||||
not showOffline and (not _('Transports') in contact.groups or \
|
||||
gajim.connections[account].connected < 2) and \
|
||||
len(gajim.contacts.get_contact(account, jid)) == 1 and nb_events == 0 and\
|
||||
len(gajim.contacts.get_contacts(account, jid)) == 1 and nb_events == 0 and\
|
||||
not _('Not in Roster') in contact.groups:
|
||||
return
|
||||
|
||||
# Remove brother contacts that are already in roster to add them
|
||||
# under this iter
|
||||
for data in shown_family:
|
||||
contacts = gajim.contacts.get_contact(data['account'],
|
||||
contacts = gajim.contacts.get_contacts(data['account'],
|
||||
data['jid'])
|
||||
for c in contacts:
|
||||
self.remove_contact(c, data['account'])
|
||||
|
@ -390,7 +391,7 @@ class RosterWindow:
|
|||
self.draw_avatar(jid, account)
|
||||
# put the children under this iter
|
||||
for data in shown_family:
|
||||
contacts = gajim.contacts.get_contact(data['account'],
|
||||
contacts = gajim.contacts.get_contacts(data['account'],
|
||||
data['jid'])
|
||||
self.add_contact_to_roster(data['jid'], data['account'])
|
||||
|
||||
|
@ -589,7 +590,7 @@ class RosterWindow:
|
|||
iters = self.get_contact_iter(jid, account)
|
||||
if len(iters) == 0:
|
||||
return
|
||||
contact_instances = gajim.contacts.get_contact(account, jid)
|
||||
contact_instances = gajim.contacts.get_contacts(account, jid)
|
||||
contact = gajim.contacts.get_highest_prio_contact_from_contacts(
|
||||
contact_instances)
|
||||
if not contact:
|
||||
|
@ -1281,7 +1282,7 @@ class RosterWindow:
|
|||
|
||||
def chg_contact_status(self, contact, show, status, account):
|
||||
'''When a contact changes his or her status'''
|
||||
contact_instances = gajim.contacts.get_contact(account, contact.jid)
|
||||
contact_instances = gajim.contacts.get_contacts(account, contact.jid)
|
||||
contact.show = show
|
||||
contact.status = status
|
||||
if show in ('offline', 'error') and \
|
||||
|
@ -1399,7 +1400,7 @@ class RosterWindow:
|
|||
jid = model[iter][C_JID].decode('utf-8')
|
||||
if self.tooltip.timeout == 0 or self.tooltip.id != props[0]:
|
||||
self.tooltip.id = row
|
||||
contacts = gajim.contacts.get_contact(account, jid)
|
||||
contacts = gajim.contacts.get_contacts(account, jid)
|
||||
connected_contacts = []
|
||||
for c in contacts:
|
||||
if c.show not in ('offline', 'error'):
|
||||
|
@ -1415,7 +1416,7 @@ class RosterWindow:
|
|||
jid = model[iter][C_JID].decode('utf-8')
|
||||
if self.tooltip.timeout == 0 or self.tooltip.id != props[0]:
|
||||
self.tooltip.id = row
|
||||
contact = gajim.contacts.get_contact(account, jid)
|
||||
contact = gajim.contacts.get_contacts(account, jid)
|
||||
self.tooltip.account = account
|
||||
self.tooltip.timeout = gobject.timeout_add(500,
|
||||
self.show_tooltip, contact)
|
||||
|
@ -1706,7 +1707,7 @@ class RosterWindow:
|
|||
if row_type in ('contact', 'agent'):
|
||||
if old_text == new_text:
|
||||
return
|
||||
for u in gajim.contacts.get_contact(account, jid):
|
||||
for u in gajim.contacts.get_contacts(account, jid):
|
||||
u.name = new_text
|
||||
gajim.connections[account].update_contact(jid, new_text, u.groups)
|
||||
self.draw_contact(jid, account)
|
||||
|
@ -1787,7 +1788,7 @@ class RosterWindow:
|
|||
self.add_contact_to_roster(contact.jid, account)
|
||||
else:
|
||||
gajim.connections[account].unsubscribe(contact.jid)
|
||||
for c in gajim.contacts.get_contact(account, contact.jid):
|
||||
for c in gajim.contacts.get_contacts(account, contact.jid):
|
||||
self.remove_contact(c, account)
|
||||
gajim.contacts.remove_jid(account, c.jid)
|
||||
self.readd_if_needed(contact, account)
|
||||
|
@ -1815,11 +1816,11 @@ class RosterWindow:
|
|||
if keyID[0] == _('None'):
|
||||
if contact.jid in keys:
|
||||
del keys[contact.jid]
|
||||
for u in gajim.contacts.get_contact(account, contact.jid):
|
||||
for u in gajim.contacts.get_contacts(account, contact.jid):
|
||||
u.keyID = ''
|
||||
else:
|
||||
keys[contact.jid] = keyID[0]
|
||||
for u in gajim.contacts.get_contact(account, contact.jid):
|
||||
for u in gajim.contacts.get_contacts(account, contact.jid):
|
||||
u.keyID = keyID[0]
|
||||
if gajim.interface.msg_win_mgr.has_window(contact.jid, account):
|
||||
ctrl = gajim.interface.msg_win_mgr.get_control(contact.jid, account)
|
||||
|
@ -1920,7 +1921,7 @@ class RosterWindow:
|
|||
information_menuitem = xml.get_widget('information_menuitem')
|
||||
history_menuitem = xml.get_widget('history_menuitem')
|
||||
|
||||
contacts = gajim.contacts.get_contact(account, jid)
|
||||
contacts = gajim.contacts.get_contacts(account, jid)
|
||||
if len(contacts) > 1: # several resources
|
||||
sub_menu = gtk.Menu()
|
||||
start_chat_menuitem.set_submenu(sub_menu)
|
||||
|
@ -2081,7 +2082,7 @@ class RosterWindow:
|
|||
information_menuitem = xml.get_widget('information_menuitem')
|
||||
history_menuitem = xml.get_widget('history_menuitem')
|
||||
|
||||
contacts = gajim.contacts.get_contact(account, jid)
|
||||
contacts = gajim.contacts.get_contacts(account, jid)
|
||||
|
||||
# Invite to
|
||||
invite_to_submenu = gtk.Menu()
|
||||
|
@ -3189,7 +3190,7 @@ class RosterWindow:
|
|||
remove_auth = False
|
||||
for (contact, account) in list_:
|
||||
gajim.connections[account].unsubscribe(contact.jid, remove_auth)
|
||||
for c in gajim.contacts.get_contact(account, contact.jid):
|
||||
for c in gajim.contacts.get_contacts(account, contact.jid):
|
||||
self.remove_contact(c, account)
|
||||
gajim.contacts.remove_jid(account, contact.jid)
|
||||
# redraw group rows for contact numbers
|
||||
|
@ -3625,7 +3626,7 @@ class RosterWindow:
|
|||
if gajim.con_types.has_key(account):
|
||||
gajim.con_types[account] = None
|
||||
for jid in gajim.contacts.get_jid_list(account):
|
||||
lcontact = gajim.contacts.get_contact(account, jid)
|
||||
lcontact = gajim.contacts.get_contacts(account, jid)
|
||||
lcontact_copy = []
|
||||
for contact in lcontact:
|
||||
lcontact_copy.append(contact)
|
||||
|
@ -3717,7 +3718,7 @@ class RosterWindow:
|
|||
if not contact:
|
||||
# If there is another resource, it may be a message from an invisible
|
||||
# resource
|
||||
lcontact = gajim.contacts.get_contact(account, jid)
|
||||
lcontact = gajim.contacts.get_contacts(account, jid)
|
||||
if (len(lcontact) > 1 or (lcontact and lcontact[0].resource and \
|
||||
lcontact[0].show != 'offline')) and jid.find('@') > 0:
|
||||
contact = gajim.contacts.copy_contact(highest_contact)
|
||||
|
@ -4121,7 +4122,7 @@ class RosterWindow:
|
|||
first_ev = gajim.events.get_first_event(account, jid)
|
||||
if not first_ev:
|
||||
# look in other resources
|
||||
for c in gajim.contacts.get_contact(account, jid):
|
||||
for c in gajim.contacts.get_contacts(account, jid):
|
||||
fjid = c.get_full_jid()
|
||||
first_ev = gajim.events.get_first_event(account, fjid)
|
||||
if first_ev:
|
||||
|
@ -4570,13 +4571,13 @@ class RosterWindow:
|
|||
jid1 = model[iter1][C_JID].decode('utf-8')
|
||||
jid2 = model[iter2][C_JID].decode('utf-8')
|
||||
if type1 == 'contact':
|
||||
lcontact1 = gajim.contacts.get_contact(account1, jid1)
|
||||
lcontact1 = gajim.contacts.get_contacts(account1, jid1)
|
||||
contact1 = gajim.contacts.get_first_contact_from_jid(account1, jid1)
|
||||
if not contact1:
|
||||
return 0
|
||||
name1 = contact1.get_shown_name()
|
||||
if type2 == 'contact':
|
||||
lcontact2 = gajim.contacts.get_contact(account2, jid2)
|
||||
lcontact2 = gajim.contacts.get_contacts(account2, jid2)
|
||||
contact2 = gajim.contacts.get_first_contact_from_jid(account2, jid2)
|
||||
if not contact2:
|
||||
return 0
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org>
|
||||
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com>
|
||||
## Copyright (C) 2006 Stefan Bethge <stefan@lanpartei.de>
|
||||
## Copyright (C) 2007 Lukas Petrovicky <lukas@petrovicky.net>
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published
|
||||
|
@ -334,7 +335,7 @@ class VcardWindow:
|
|||
def fill_status_label(self):
|
||||
if self.xml.get_widget('information_notebook').get_n_pages() < 5:
|
||||
return
|
||||
contact_list = gajim.contacts.get_contact(self.account, self.contact.jid)
|
||||
contact_list = gajim.contacts.get_contacts(self.account, self.contact.jid)
|
||||
connected_contact_list = []
|
||||
for c in contact_list:
|
||||
if c.show not in ('offline', 'error'):
|
||||
|
@ -429,7 +430,7 @@ class VcardWindow:
|
|||
self.os_info = {0: {'resource': self.contact.resource, 'client': '',
|
||||
'os': ''}}
|
||||
i = 1
|
||||
contact_list = gajim.contacts.get_contact(self.account, self.contact.jid)
|
||||
contact_list = gajim.contacts.get_contacts(self.account, self.contact.jid)
|
||||
if contact_list:
|
||||
for c in contact_list:
|
||||
if c.resource != self.contact.resource:
|
||||
|
@ -522,7 +523,7 @@ class ZeroconfVcardWindow:
|
|||
def fill_status_label(self):
|
||||
if self.xml.get_widget('information_notebook').get_n_pages() < 2:
|
||||
return
|
||||
contact_list = gajim.contacts.get_contact(self.account, self.contact.jid)
|
||||
contact_list = gajim.contacts.get_contacts(self.account, self.contact.jid)
|
||||
# stats holds show and status message
|
||||
stats = ''
|
||||
one = True # Are we adding the first line ?
|
||||
|
|
Loading…
Add table
Reference in a new issue