-Set General and Observer group directly in contact instance, instead of calculating it each time

-When creating self-contact contact instance, store it with group 'self_contact', so it never goes in General
-Make general group not be seen visible because of self contact even if self.regroup
-Remove the self contact instance itself too when WE deconnect or when IT deconnect, so we will
not see it as offline if refilling roster (regroup account for example)
This commit is contained in:
Jean-Marie Traissard 2008-06-08 21:27:31 +00:00
parent d0b15bf5fd
commit f9c981df5d
4 changed files with 29 additions and 70 deletions

View file

@ -1496,7 +1496,7 @@ class ChatControl(ChatControlBase):
# if peer supports jep85 and we are not 'ask', send 'active' # if peer supports jep85 and we are not 'ask', send 'active'
# NOTE: first active and 'ask' is set in gajim.py # NOTE: first active and 'ask' is set in gajim.py
elif composing_xep is not False: elif composing_xep is not False:
#send active chatstate on every message (as JEP says) # send active chatstate on every message (as XEP says)
chatstate_to_send = 'active' chatstate_to_send = 'active'
contact.our_chatstate = 'active' contact.our_chatstate = 'active'

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 self.groups = groups # See below for what we do if it's empty
self.show = show self.show = show
self.status = status self.status = status
self.sub = sub self.sub = sub
@ -63,7 +63,11 @@ 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()
@ -311,18 +315,8 @@ class Contacts:
if groups == []: if groups == []:
in_groups = True in_groups = True
else: else:
contact_groups = contact.groups
if not contact_groups:
# Contact is not in a group, so count it in General or
# Transports group
if common.gajim.jid_is_transport(jid):
contact_groups = [_('Transports')]
if contact.is_observer():
contact_groups = [_('Observers')]
else:
contact_groups = [_('General')]
for group in groups: for group in groups:
if group in contact_groups: if group in contact.groups:
in_groups = True in_groups = True
break break

View file

@ -664,7 +664,7 @@ class Interface:
if resource == gajim.connections[account].server_resource: if resource == gajim.connections[account].server_resource:
return return
contact1 = gajim.contacts.create_contact(jid = ji, contact1 = gajim.contacts.create_contact(jid = ji,
name = gajim.nicks[account], groups = [], name = gajim.nicks[account], groups = ['self_contact'],
show = array[1], status = status_message, sub = 'both', show = array[1], status = status_message, sub = 'both',
ask = 'none', priority = priority, keyID = keyID, ask = 'none', priority = priority, keyID = keyID,
resource = resource) resource = resource)

View file

@ -181,12 +181,9 @@ class RosterWindow:
# We don't know this contact # We don't know this contact
return return
groups = contact.groups
if not groups:
groups = [_('General')]
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 groups: for group in contact.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)
@ -356,11 +353,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:
if contact.is_observer():
contact.groups = [_('Observers')]
groups = contact.groups groups = contact.groups
if not groups:
groups = [_('General')]
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:
@ -630,16 +623,11 @@ class RosterWindow:
self._add_entity(contact, account) self._add_entity(contact, account)
# Draw the contact and its groups contact # Draw the contact and its groups contact
if is_observer:
contact.groups = [_('Observers')]
groups = contact.groups
if not groups:
groups = [_('General')]
if not self.starting: if not self.starting:
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 groups: for group in contact.groups:
self.draw_group(group, account) self.draw_group(group, account)
self.draw_account(account) self.draw_account(account)
@ -685,18 +673,13 @@ class RosterWindow:
self._remove_entity(contact, account) self._remove_entity(contact, account)
# Draw all groups of the contact # Draw all groups of the contact
groups = contact.groups
if contact.is_observer():
contact.groups = [_('Observers')]
if not groups:
groups = [_('General')]
if backend: if backend:
# Remove contact before redrawing, otherwise the old # Remove contact before redrawing, otherwise the old
# 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 groups: for group in contact.groups:
self.draw_group(group, account) self.draw_group(group, account)
self.draw_account(account) self.draw_account(account)
@ -950,14 +933,6 @@ class RosterWindow:
name = gobject.markup_escape_text(contact.get_shown_name()) name = gobject.markup_escape_text(contact.get_shown_name())
groups = contact.groups
if contact.is_observer():
groups = [_('Observers')]
elif not groups and \
not contact.jid == gajim.get_jid_from_account(account):
# no group, and not self contact
groups = [_('General')]
# gets number of unread gc marked messages # gets number of unread gc marked messages
if jid in gajim.interface.minimized_controls[account]: if jid in gajim.interface.minimized_controls[account]:
nb_unread = len(gajim.events.get_events(account, jid, nb_unread = len(gajim.events.get_events(account, jid,
@ -975,7 +950,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 groups: for group in contact.groups:
if group in gajim.connections[account].blocked_groups: if group in gajim.connections[account].blocked_groups:
strike = True strike = True
break break
@ -1126,10 +1101,12 @@ class RosterWindow:
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 groups: for group in contact.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)
if iterG:
# it's not self contact
self.model[iterG][C_JID] = self.model[iterG][C_JID] self.model[iterG][C_JID] = self.model[iterG][C_JID]
return False return False
@ -1199,16 +1176,10 @@ class RosterWindow:
''' '''
contact = gajim.contacts.get_first_contact_from_jid(account, jid) contact = gajim.contacts.get_first_contact_from_jid(account, jid)
groups = contact.groups
if contact.is_observer():
contact.groups = [_('Observers')]
if not groups:
groups = [_('General')]
self.draw_contact(jid, account) self.draw_contact(jid, account)
self.draw_account(account) self.draw_account(account)
for group in groups: for group in contact.groups:
self.draw_group(group, account) self.draw_group(group, account)
# FIXME: Is this needed, Jim? # FIXME: Is this needed, Jim?
#self._adjust_group_expand_collapse_state(group, account) #self._adjust_group_expand_collapse_state(group, account)
@ -1379,9 +1350,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 or (group == _('General') and not \ if group in contact.groups:
contact.groups and \
not contact.jid == gajim.get_jid_from_account(account)):
if self.contact_is_visible(contact, _acc): if self.contact_is_visible(contact, _acc):
return True return True
return False return False
@ -1889,9 +1858,9 @@ class RosterWindow:
gajim.contacts.remove_contact(account, contact) gajim.contacts.remove_contact(account, contact)
elif contact.jid == gajim.get_jid_from_account(account) and \ elif contact.jid == gajim.get_jid_from_account(account) and \
show == 'offline': show == 'offline':
# Our SelfContact went offline. Remove him # Our SelfContact went offline. Remove him from roster and contacts
self.remove_contact(contact.jid, account) self.remove_contact(contact.jid, account)
gajim.contacts.remove_contact(account, contact)
# print status in chat window and update status/GPG image # print status in chat window and update status/GPG image
if gajim.interface.msg_win_mgr.has_window(contact.jid, account): if gajim.interface.msg_win_mgr.has_window(contact.jid, account):
win = gajim.interface.msg_win_mgr.get_window(contact.jid, account) win = gajim.interface.msg_win_mgr.get_window(contact.jid, account)
@ -1943,9 +1912,11 @@ class RosterWindow:
for contact in [c for c in lcontact if (c.show != 'offline' or \ for contact in [c for c in lcontact if (c.show != 'offline' or \
c.is_transport())]: c.is_transport())]:
self.chg_contact_status(contact, 'offline', '', account) self.chg_contact_status(contact, 'offline', '', account)
# Remove SelfContact from roster. It might be gone when we return # Remove SelfContact from roster and remove it.
self.remove_contact(gajim.get_jid_from_account(account), account) # It might be gone when we return
self_jid = gajim.get_jid_from_account(account)
self.remove_contact(self_jid, account)
gajim.contacts.remove_jid(account, self_jid)
self.actions_menu_needs_rebuild = True self.actions_menu_needs_rebuild = True
self.update_status_combobox() self.update_status_combobox()
# Force the rebuild now since the on_activates on the menu itself does # Force the rebuild now since the on_activates on the menu itself does
@ -2323,7 +2294,7 @@ class RosterWindow:
if not show: if not show:
show = 'online' show = 'online'
contact = gajim.contacts.create_contact(jid = jid, contact = gajim.contacts.create_contact(jid = jid,
name = account, show = show, name = account, groups = ['self_contact'], show = show,
status = roster.getStatus(jid+'/'+resource), status = roster.getStatus(jid+'/'+resource),
resource = resource, resource = resource,
priority = roster.getPriority(jid+'/'+resource)) priority = roster.getPriority(jid+'/'+resource))
@ -4704,8 +4675,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 or (contact.groups == [] and group == \ if group in contact.groups:
_('General')):
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))
@ -4996,12 +4966,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:
groups = contact.groups for group in contact.groups:
if contact.is_observer():
groups = [_('Observers')]
elif not groups:
groups = [_('General')]
for group in groups:
if group in gajim.connections[account].blocked_groups: if group in gajim.connections[account].blocked_groups:
blocked = True blocked = True
break break