update correctly self contact when we get PEP info. fixes #4145

This commit is contained in:
Yann Leboulanger 2008-08-04 22:44:48 +00:00
parent e13c472e2c
commit d6f20965a9
2 changed files with 59 additions and 102 deletions

View file

@ -163,11 +163,10 @@ def user_mood(items, name, jid):
if jid == gajim.get_jid_from_account(name): if jid == gajim.get_jid_from_account(name):
gajim.interface.roster.draw_account(name) gajim.interface.roster.draw_account(name)
else: gajim.interface.roster.draw_mood(user, name)
gajim.interface.roster.draw_mood(user, name) ctrl = gajim.interface.msg_win_mgr.get_control(user, name)
ctrl = gajim.interface.msg_win_mgr.get_control(user, name) if ctrl:
if ctrl: ctrl.update_mood()
ctrl.update_mood()
def user_tune(items, name, jid): def user_tune(items, name, jid):
has_child = False has_child = False
@ -268,11 +267,10 @@ def user_tune(items, name, jid):
if jid == gajim.get_jid_from_account(name): if jid == gajim.get_jid_from_account(name):
gajim.interface.roster.draw_account(name) gajim.interface.roster.draw_account(name)
else: gajim.interface.roster.draw_tune(user, name)
gajim.interface.roster.draw_tune(user, name) ctrl = gajim.interface.msg_win_mgr.get_control(user, name)
ctrl = gajim.interface.msg_win_mgr.get_control(user, name) if ctrl:
if ctrl: ctrl.update_tune()
ctrl.update_tune()
def user_geoloc(items, name, jid): def user_geoloc(items, name, jid):
pass pass
@ -346,8 +344,7 @@ def user_activity(items, name, jid):
if jid == gajim.get_jid_from_account(name): if jid == gajim.get_jid_from_account(name):
gajim.interface.roster.draw_account(name) gajim.interface.roster.draw_account(name)
else: gajim.interface.roster.draw_activity(user, name)
gajim.interface.roster.draw_activity(user, name)
ctrl = gajim.interface.msg_win_mgr.get_control(user, name) ctrl = gajim.interface.msg_win_mgr.get_control(user, name)
if ctrl: if ctrl:
ctrl.update_activity() ctrl.update_activity()
@ -468,4 +465,4 @@ def user_retract_tune(account):
def user_retract_nickname(account): def user_retract_nickname(account):
gajim.connections[account].send_pb_retract('', xmpp.NS_NICK, '0') gajim.connections[account].send_pb_retract('', xmpp.NS_NICK, '0')
# vim: se ts=3: # vim: se ts=3:

View file

@ -655,8 +655,8 @@ class Interface:
# FIXME: Drop and rewrite... # FIXME: Drop and rewrite...
statuss = ['offline', 'error', 'online', 'chat', 'away', 'xa', statuss = ['offline', 'error', 'online', 'chat', 'away', 'xa', 'dnd',
'dnd', 'invisible'] 'invisible']
# Ignore invalid show # Ignore invalid show
if array[1] not in statuss: if array[1] not in statuss:
return return
@ -668,8 +668,7 @@ class Interface:
contact_nickname = array[7] contact_nickname = array[7]
# Get the proper keyID # Get the proper keyID
keyID = helpers.prepare_and_validate_gpg_keyID(account, keyID = helpers.prepare_and_validate_gpg_keyID(account, jid, keyID)
jid, keyID)
resource = array[3] resource = array[3]
if not resource: if not resource:
@ -685,6 +684,8 @@ class Interface:
get_contact_with_highest_priority(account, jid) get_contact_with_highest_priority(account, jid)
was_highest = (highest and highest.resource == resource) was_highest = (highest and highest.resource == resource)
conn = gajim.connections[account]
# Update contact # Update contact
jid_list = gajim.contacts.get_jid_list(account) jid_list = gajim.contacts.get_jid_list(account)
if ji in jid_list or jid == gajim.get_jid_from_account(account): if ji in jid_list or jid == gajim.get_jid_from_account(account):
@ -706,42 +707,32 @@ class Interface:
contact1.contact_name = contact_nickname contact1.contact_name = contact_nickname
self.roster.draw_contact(jid, account) self.roster.draw_contact(jid, account)
if old_show == new_show and \ if old_show == new_show and contact1.status == status_message and \
contact1.status == status_message and \
contact1.priority == priority: # no change contact1.priority == priority: # no change
return return
else: else:
contact1 = gajim.contacts. \ contact1 = gajim.contacts.get_first_contact_from_jid(account, ji)
get_first_contact_from_jid(account, ji)
if not contact1: if not contact1:
# Presence of another resource of our # Presence of another resource of our
# jid # jid
# Create self contact and add to roster # Create self contact and add to roster
if resource == gajim.connections \ if resource == conn.server_resource:
[account].server_resource:
return return
contact1 = gajim.contacts. \ contact1 = gajim.contacts.create_contact(jid=ji,
create_contact(jid=ji, name=gajim.nicks[account], groups=['self_contact'],
name=gajim.nicks[account], show=array[1], status=status_message, sub='both', ask='none',
groups=['self_contact'], priority=priority, keyID=keyID, resource=resource,
show=array[1], mood=conn.mood, tune=conn.tune, activity=conn.activity)
status=status_message,
sub='both', ask='none',
priority=priority, keyID=keyID,
resource=resource)
old_show = 0 old_show = 0
gajim.contacts.add_contact(account, gajim.contacts.add_contact(account, contact1)
contact1)
lcontact.append(contact1) lcontact.append(contact1)
elif contact1.show in statuss: elif contact1.show in statuss:
old_show = statuss.index(contact1.show) old_show = statuss.index(contact1.show)
# FIXME: What am I? # FIXME: What am I?
if (resources != [''] and (len(lcontact) != 1 or if (resources != [''] and (len(lcontact) != 1 or \
lcontact[0].show != 'offline')) and \ lcontact[0].show != 'offline')) and jid.find('@') > 0:
jid.find('@') > 0:
old_show = 0 old_show = 0
contact1 = gajim.contacts. \ contact1 = gajim.contacts.copy_contact(contact1)
copy_contact(contact1)
lcontact.append(contact1) lcontact.append(contact1)
contact1.resource = resource contact1.resource = resource
@ -750,31 +741,19 @@ class Interface:
if contact1.jid.find('@') > 0 and len(lcontact) == 1: if contact1.jid.find('@') > 0 and len(lcontact) == 1:
# It's not an agent # It's not an agent
if old_show == 0 and new_show > 1: if old_show == 0 and new_show > 1:
if not contact1.jid in \ if not contact1.jid in gajim.newly_added[account]:
gajim.newly_added[account]: gajim.newly_added[account].append(contact1.jid)
gajim.newly_added[account]. \ if contact1.jid in gajim.to_be_removed[account]:
append(contact1.jid) gajim.to_be_removed[account].remove(contact1.jid)
if contact1.jid in \ gobject.timeout_add_seconds(5, self.roster.remove_newly_added,
gajim.to_be_removed[account]:
gajim.to_be_removed[account]. \
remove(contact1.jid)
gobject.timeout_add_seconds(5, self. \
roster.remove_newly_added,
contact1.jid, account) contact1.jid, account)
elif old_show > 1 and new_show == 0 and \ elif old_show > 1 and new_show == 0 and conn.connected > 1:
gajim.connections[account].connected > 1: if not contact1.jid in gajim.to_be_removed[account]:
if not contact1.jid in \ gajim.to_be_removed[account].append(contact1.jid)
gajim.to_be_removed[account]: if contact1.jid in gajim.newly_added[account]:
gajim.to_be_removed[account]. \ gajim.newly_added[account].remove(contact1.jid)
append(contact1.jid) self.roster.draw_contact(contact1.jid, account)
if contact1.jid in \ gobject.timeout_add_seconds(5, self.roster.remove_to_be_removed,
gajim.newly_added[account]:
gajim.newly_added[account]. \
remove(contact1.jid)
self.roster.draw_contact(contact1.jid,
account)
gobject.timeout_add_seconds(5, self. \
roster.remove_to_be_removed,
contact1.jid, account) contact1.jid, account)
contact1.show = array[1] contact1.show = array[1]
contact1.status = status_message contact1.status = status_message
@ -794,33 +773,25 @@ class Interface:
# Update existing iter and group counting # Update existing iter and group counting
self.roster.draw_contact(ji, account) self.roster.draw_contact(ji, account)
self.roster.draw_group(_('Transports'), account) self.roster.draw_group(_('Transports'), account)
if new_show > 1 and ji in \ if new_show > 1 and ji in gajim.transport_avatar[account]:
gajim.transport_avatar[account]:
# transport just signed in. # transport just signed in.
# request avatars # request avatars
for jid_ in gajim.transport_avatar \ for jid_ in gajim.transport_avatar[account][ji]:
[account][ji]: conn.request_vcard(jid_)
gajim.connections[account]. \
request_vcard(jid_)
# transport just signed in/out, don't show # transport just signed in/out, don't show
# popup notifications for 30s # popup notifications for 30s
account_ji = account + '/' + ji account_ji = account + '/' + ji
gajim.block_signed_in_notifications \ gajim.block_signed_in_notifications[account_ji] = True
[account_ji] = True
gobject.timeout_add_seconds(30, gobject.timeout_add_seconds(30,
self.unblock_signed_in_notifications, self.unblock_signed_in_notifications, account_ji)
account_ji)
locations = (self.instances, self.instances[account]) locations = (self.instances, self.instances[account])
for location in locations: for location in locations:
if location.has_key('add_contact'): if location.has_key('add_contact'):
if old_show == 0 and new_show > 1: if old_show == 0 and new_show > 1:
location['add_contact']. \ location['add_contact'].transport_signed_in(jid)
transport_signed_in(jid)
break break
elif old_show > 1 and new_show == 0: elif old_show > 1 and new_show == 0:
location['add_contact']. \ location['add_contact'].transport_signed_out(jid)
transport_signed_out(
jid)
break break
elif ji in jid_list: elif ji in jid_list:
# It isn't an agent # It isn't an agent
@ -830,8 +801,6 @@ class Interface:
contact1.our_chatstate = contact1.chatstate = \ contact1.our_chatstate = contact1.chatstate = \
contact1.composing_xep = None contact1.composing_xep = None
conn = gajim.connections[account]
# TODO: This causes problems when another # TODO: This causes problems when another
# resource signs off! # resource signs off!
conn.remove_transfers_for_contact(contact1) conn.remove_transfers_for_contact(contact1)
@ -855,44 +824,35 @@ class Interface:
conn.delete_session(jid, conn.delete_session(jid,
sess.thread_id) sess.thread_id)
self.roster.chg_contact_status(contact1, array[1], self.roster.chg_contact_status(contact1, array[1], status_message,
status_message, account) account)
# Notifications # Notifications
if old_show < 2 and new_show > 1: if old_show < 2 and new_show > 1:
notify.notify('contact_connected', jid, notify.notify('contact_connected', jid, account, status_message)
account, status_message)
if self.remote_ctrl: if self.remote_ctrl:
self.remote_ctrl.raise_signal( self.remote_ctrl.raise_signal('ContactPresence', (account,
'ContactPresence', array))
(account, array))
elif old_show > 1 and new_show < 2: elif old_show > 1 and new_show < 2:
notify.notify('contact_disconnected', jid, notify.notify('contact_disconnected', jid, account, status_message)
account, status_message)
if self.remote_ctrl: if self.remote_ctrl:
self.remote_ctrl.raise_signal( self.remote_ctrl.raise_signal('ContactAbsence', (account, array))
'ContactAbsence',
(account, array))
# FIXME: stop non active file transfers # FIXME: stop non active file transfers
# Status change (not connected/disconnected or # Status change (not connected/disconnected or
# error (<1)) # error (<1))
elif new_show > 1: elif new_show > 1:
notify.notify('status_change', jid, account, notify.notify('status_change', jid, account, [new_show,
[new_show, status_message]) status_message])
if self.remote_ctrl: if self.remote_ctrl:
self.remote_ctrl.raise_signal( self.remote_ctrl.raise_signal('ContactStatus', (account, array))
'ContactStatus',
(account, array))
else: else:
# FIXME: MSN transport (CMSN1.2.1 and PyMSN) don't # FIXME: MSN transport (CMSN1.2.1 and PyMSN) don't
# follow the XEP, still the case in 2008. # follow the XEP, still the case in 2008.
# It's maybe a GC_NOTIFY (specialy for MSN gc) # It's maybe a GC_NOTIFY (specialy for MSN gc)
self.handle_event_gc_notify(account, (jid, array[1], self.handle_event_gc_notify(account, (jid, array[1], status_message,
status_message, array[3], None, None, None, array[3], None, None, None, None, None, [], None, None))
None, None, [], None, None))
highest = gajim.contacts.get_contact_with_highest_priority( highest = gajim.contacts.get_contact_with_highest_priority(account, jid)
account, jid)
is_highest = (highest and highest.resource == resource) is_highest = (highest and highest.resource == resource)
if was_highest and not is_highest: if was_highest and not is_highest: