-Use a method to get_shown_groups (possibly more work to do (special group attribute))
-Show contact only if contact.ask, not according to modified xep 0162 logic. (I don't get neither the xep
meaning, neither this modified logic, can you explain steve-e ?)
-Remove contact before we modify it req_sub(). Else we can't remove it because iter is not found.
-When removing a contact and we let him in see us (observer), manually set show to offline, so he is not set as
visible.
-Remove observer from observer group if we asked him auth (I mean before he answer). Xep 0162 say he is not an
observer then. Fix contact staying in observer group when we get auth later.
-Renaming groups seems fixed (it's an accident :p )

More work on group to follow
This commit is contained in:
Jean-Marie Traissard 2008-06-15 21:48:13 +00:00
parent 18d8f98f3c
commit ca457a7ac2
3 changed files with 50 additions and 39 deletions

View file

@ -32,7 +32,7 @@ class Contact:
self.jid = jid self.jid = jid
self.name = name self.name = name
self.contact_name = '' # nick choosen by contact self.contact_name = '' # nick choosen by contact
self.groups = groups # See below for what we do if it's empty self.groups = groups
self.show = show self.show = show
self.status = status self.status = status
self.sub = sub self.sub = sub
@ -63,11 +63,6 @@ class Contact:
# this is contact's chatstate # this is contact's chatstate
self.chatstate = chatstate self.chatstate = chatstate
self.last_status_time = last_status_time self.last_status_time = last_status_time
if not self.groups:
if self.is_observer():
self.groups = [_('Observers')]
else:
self.groups = [_('General')]
self.mood = mood.copy() self.mood = mood.copy()
self.tune = tune.copy() self.tune = tune.copy()
self.activity = activity.copy() self.activity = activity.copy()
@ -84,6 +79,20 @@ class Contact:
return self.contact_name return self.contact_name
return self.jid.split('@')[0] return self.jid.split('@')[0]
def get_shown_groups(self):
'''
'''
if self.is_observer():
return [_('Observers')]
elif self.is_groupchat():
return [_('Groupchats')]
elif self.is_transport():
return [_('Transports')]
elif not self.groups:
return [_('General')]
else:
return self.groups
def is_hidden_from_roster(self): def is_hidden_from_roster(self):
'''if contact should not be visible in roster''' '''if contact should not be visible in roster'''
# XEP-0162: http://www.xmpp.org/extensions/xep-0162.html # XEP-0162: http://www.xmpp.org/extensions/xep-0162.html
@ -316,7 +325,7 @@ class Contacts:
in_groups = True in_groups = True
else: else:
for group in groups: for group in groups:
if group in contact.groups: if group in contact.get_shown_groups():
in_groups = True in_groups = True
break break

View file

@ -1425,7 +1425,9 @@ class Interface:
else: else:
re_add = False re_add = False
# if sub changed: remove and re-add, maybe observer status changed # if sub changed: remove and re-add, maybe observer status changed
if contacts[0].sub != sub: # according to xep 0162, contact is not an observer anymore when
# we asked him is auth, so also remove him if ask changed
if contacts[0].sub != sub or contacts[0].ask != ask:
self.roster.remove_contact(contacts[0].jid, account, force = True) self.roster.remove_contact(contacts[0].jid, account, force = True)
re_add = True re_add = True
for contact in contacts: for contact in contacts:

View file

@ -183,7 +183,7 @@ class RosterWindow:
acct = self._get_account_iter(account, model) acct = self._get_account_iter(account, model)
found = [] # the contact iters. One per group found = [] # the contact iters. One per group
for group in contact.groups: for group in contact.get_shown_groups():
group_iter = self._get_group_iter(group, account, acct, model) group_iter = self._get_group_iter(group, account, acct, model)
contact_iter = model.iter_children(group_iter) contact_iter = model.iter_children(group_iter)
@ -329,9 +329,11 @@ class RosterWindow:
Keyword arguments: Keyword arguments:
contact -- the contact to add contact -- the contact to add
account -- the contacts account account -- the contacts account
groups -- list of groups to add the contact to. (default groups in contact.groups). groups -- list of groups to add the contact to. (default groups in
contact.get_shown_groups()).
Parameter ignored when big_brother_contact is specified. Parameter ignored when big_brother_contact is specified.
big_brother_contact -- if specified contact is added as child big_brother_contact. (default None) big_brother_contact -- if specified contact is added as child
big_brother_contact. (default None)
''' '''
added_iters = [] added_iters = []
if big_brother_contact: if big_brother_contact:
@ -344,7 +346,7 @@ class RosterWindow:
# Do not confuse get_contact_iter # Do not confuse get_contact_iter
# Sync groups of family members # Sync groups of family members
contact.groups = big_brother_contact.groups[:] contact.groups = big_brother_contact.get_shown_groups()[:]
for child_iter in parent_iters: for child_iter in parent_iters:
it = self.model.append(child_iter, (None, contact.get_shown_name(), it = self.model.append(child_iter, (None, contact.get_shown_name(),
@ -353,7 +355,7 @@ class RosterWindow:
else: else:
# We are a normal contact. Add us to our groups. # We are a normal contact. Add us to our groups.
if not groups: if not groups:
groups = contact.groups groups = contact.get_shown_groups()
for group in groups: for group in groups:
child_iterG = self._get_group_iter(group, account, model=self.model) child_iterG = self._get_group_iter(group, account, model=self.model)
if not child_iterG: if not child_iterG:
@ -398,8 +400,7 @@ class RosterWindow:
Keyword arguments: Keyword arguments:
contact -- the contact to add contact -- the contact to add
account -- the contacts account account -- the contacts account
groups -- list of groups to remove the contact from. (default groups in contact.groups). groups -- list of groups to remove the contact from.
''' '''
iters = self._get_contact_iter(contact.jid, account, contact, self.model) iters = self._get_contact_iter(contact.jid, account, contact, self.model)
assert iters, '%s shall be removed but is not in roster' % contact.jid assert iters, '%s shall be removed but is not in roster' % contact.jid
@ -662,7 +663,7 @@ class RosterWindow:
for c, acc in contacts: for c, acc in contacts:
self.draw_contact(c.jid, acc) self.draw_contact(c.jid, acc)
self.draw_avatar(c.jid, acc) self.draw_avatar(c.jid, acc)
for group in contact.groups: for group in contact.get_shown_groups():
self.draw_group(group, account) self.draw_group(group, account)
self.draw_account(account) self.draw_account(account)
@ -714,7 +715,7 @@ class RosterWindow:
# numbers will still be show # numbers will still be show
gajim.contacts.remove_jid(account, jid) gajim.contacts.remove_jid(account, jid)
for group in contact.groups: for group in contact.get_shown_groups():
self.draw_group(group, account) self.draw_group(group, account)
self.draw_account(account) self.draw_account(account)
@ -777,7 +778,6 @@ class RosterWindow:
''' '''
self.remove_contact(jid, account, force = True) self.remove_contact(jid, account, force = True)
for contact in gajim.contacts.get_contacts(account, jid): for contact in gajim.contacts.get_contacts(account, jid):
for group in groups: for group in groups:
if group not in contact.groups: if group not in contact.groups:
@ -804,7 +804,6 @@ class RosterWindow:
''' '''
self.remove_contact(jid, account, force = True) self.remove_contact(jid, account, force = True)
for contact in gajim.contacts.get_contacts(account, jid): for contact in gajim.contacts.get_contacts(account, jid):
for group in groups: for group in groups:
if group in contact.groups: if group in contact.groups:
@ -963,7 +962,7 @@ class RosterWindow:
if jid in gajim.connections[account].blocked_contacts: if jid in gajim.connections[account].blocked_contacts:
strike = True strike = True
else: else:
for group in contact.groups: for group in contact.get_shown_groups():
if group in gajim.connections[account].blocked_groups: if group in gajim.connections[account].blocked_groups:
strike = True strike = True
break break
@ -1072,7 +1071,7 @@ class RosterWindow:
if family and not is_big_brother and not self.starting: if family and not is_big_brother and not self.starting:
self.draw_parent_contact(jid, account) self.draw_parent_contact(jid, account)
for group in contact.groups: for group in contact.get_shown_groups():
# We need to make sure that _visible_func is called for # We need to make sure that _visible_func is called for
# our groups otherwise we might not be shown # our groups otherwise we might not be shown
iterG = self._get_group_iter(group, account, model = self.model) iterG = self._get_group_iter(group, account, model = self.model)
@ -1157,7 +1156,7 @@ class RosterWindow:
self.draw_contact(jid, account) self.draw_contact(jid, account)
self.draw_account(account) self.draw_account(account)
for group in contact.groups: for group in contact.get_shown_groups():
self.draw_group(group, account) self.draw_group(group, account)
self._adjust_group_expand_collapse_state(group, account) self._adjust_group_expand_collapse_state(group, account)
@ -1279,13 +1278,11 @@ class RosterWindow:
def contact_is_visible(self, contact, account): def contact_is_visible(self, contact, account):
if self.contact_has_pending_roster_events(contact, account): if self.contact_has_pending_roster_events(contact, account):
return True return True
# XEP-0162
hide = contact.is_hidden_from_roster()
if hide and contact.sub != 'from':
return False
showOffline = gajim.config.get('showoffline') if contact.ask:
if (contact.show in ('offline', 'error') or hide) and not showOffline: return True
if contact.show in ('offline', 'error'):
if contact.jid in gajim.to_be_removed[account]: if contact.jid in gajim.to_be_removed[account]:
return True return True
return False return False
@ -1327,7 +1324,7 @@ class RosterWindow:
for contact in gajim.contacts.iter_contacts(_acc): for contact in gajim.contacts.iter_contacts(_acc):
# Is this contact in this group ? (last part of if check if it's # Is this contact in this group ? (last part of if check if it's
# self contact) # self contact)
if group in contact.groups: if group in contact.get_shown_groups():
if self.contact_is_visible(contact, _acc): if self.contact_is_visible(contact, _acc):
return True return True
return False return False
@ -1716,15 +1713,15 @@ class RosterWindow:
sub = 'subscribe', keyID = keyID) sub = 'subscribe', keyID = keyID)
gajim.contacts.add_contact(account, contact) gajim.contacts.add_contact(account, contact)
else: else:
if not _('Not in Roster') in contact.groups: if not _('Not in Roster') in contact.get_shown_groups():
dialogs.InformationDialog(_('Subscription request has been sent'), dialogs.InformationDialog(_('Subscription request has been sent'),
_('If "%s" accepts this request you will know his or her status.' _('If "%s" accepts this request you will know his or her status.'
) % jid) ) % jid)
return return
self.remove_contact(contact.jid, account)
contact.groups = groups contact.groups = groups
if nickname: if nickname:
contact.name = nickname contact.name = nickname
self.remove_contact(contact.jid, account)
self.add_contact(jid, account) self.add_contact(jid, account)
def revoke_auth(self, widget, jid, account): def revoke_auth(self, widget, jid, account):
@ -2516,9 +2513,10 @@ class RosterWindow:
if row_type in ('contact', 'agent'): if row_type in ('contact', 'agent'):
if old_text == new_text: if old_text == new_text:
return return
for u in gajim.contacts.get_contacts(account, jid): for contact in gajim.contacts.get_contacts(account, jid):
u.name = new_text contact.name = new_text
gajim.connections[account].update_contact(jid, new_text, u.groups) gajim.connections[account].update_contact(jid, new_text, \
contact.groups)
self.draw_contact(jid, account) self.draw_contact(jid, account)
# Update opened chats # Update opened chats
for ctrl in gajim.interface.msg_win_mgr.get_controls(jid, account): for ctrl in gajim.interface.msg_win_mgr.get_controls(jid, account):
@ -2666,7 +2664,7 @@ class RosterWindow:
ctrl.shutdown() ctrl.shutdown()
contact = gajim.contacts.get_contact_with_highest_priority(account, jid) contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
if contact.groups == [_('Groupchats')]: if contact.get_shown_groups() == [_('Groupchats')]:
self.remove_groupchat(contact.jid, account) self.remove_groupchat(contact.jid, account)
def on_send_single_message_menuitem_activate(self, widget, account, def on_send_single_message_menuitem_activate(self, widget, account,
@ -2947,6 +2945,8 @@ class RosterWindow:
contact.name = '' contact.name = ''
contact.groups = [] contact.groups = []
contact.sub = 'from' contact.sub = 'from'
# we can't see him, but have to set it manually in contact
contact.show = 'offline'
gajim.contacts.add_contact(account, contact) gajim.contacts.add_contact(account, contact)
self.add_contact(contact.jid, account) self.add_contact(contact.jid, account)
def on_ok2(list_): def on_ok2(list_):
@ -4659,7 +4659,7 @@ class RosterWindow:
for jid in gajim.contacts.get_jid_list(account): for jid in gajim.contacts.get_jid_list(account):
contact = gajim.contacts.get_contact_with_highest_priority(account, contact = gajim.contacts.get_contact_with_highest_priority(account,
jid) jid)
if group in contact.groups: if group in contact.get_shown_groups():
if contact.show not in ('offline', 'error'): if contact.show not in ('offline', 'error'):
list_online.append((contact, account)) list_online.append((contact, account))
list_.append((contact, account)) list_.append((contact, account))
@ -4880,7 +4880,7 @@ class RosterWindow:
history_menuitem.connect('activate', self.on_history, contact, history_menuitem.connect('activate', self.on_history, contact,
account) account)
if _('Not in Roster') not in contact.groups: if _('Not in Roster') not in contact.get_shown_groups():
# contact is in normal group # contact is in normal group
edit_groups_menuitem.set_no_show_all(False) edit_groups_menuitem.set_no_show_all(False)
assign_openpgp_key_menuitem.set_no_show_all(False) assign_openpgp_key_menuitem.set_no_show_all(False)
@ -4950,7 +4950,7 @@ class RosterWindow:
if jid in gajim.connections[account].blocked_contacts: if jid in gajim.connections[account].blocked_contacts:
blocked = True blocked = True
else: else:
for group in contact.groups: for group in contact.get_shown_groups():
if group in gajim.connections[account].blocked_groups: if group in gajim.connections[account].blocked_groups:
blocked = True blocked = True
break break
@ -5048,7 +5048,7 @@ class RosterWindow:
history_menuitem.connect('activate', self.on_history, contact, history_menuitem.connect('activate', self.on_history, contact,
account) account)
if _('Not in Roster') not in contact.groups: if _('Not in Roster') not in contact.get_shown_groups():
# contact is in normal group # contact is in normal group
add_to_roster_menuitem.hide() add_to_roster_menuitem.hide()
add_to_roster_menuitem.set_no_show_all(True) add_to_roster_menuitem.set_no_show_all(True)