detach sessions from controls when the highest priority contact changes.
this way we don't get multiple tabs when the remote user moves to another resource.
This commit is contained in:
parent
3ec61df48b
commit
399233f293
3 changed files with 37 additions and 14 deletions
|
@ -1323,7 +1323,7 @@ sent a message to.'''
|
||||||
orphaned = filter(lambda s: not s.control, chat_sessions)
|
orphaned = filter(lambda s: not s.control, chat_sessions)
|
||||||
|
|
||||||
return orphaned[0]
|
return orphaned[0]
|
||||||
except KeyError:
|
except (KeyError, IndexError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def make_new_session(self, jid, thread_id=None, type='chat', cls=None):
|
def make_new_session(self, jid, thread_id=None, type='chat', cls=None):
|
||||||
|
@ -2104,6 +2104,13 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
||||||
self.dispatch('ERROR_ANSWER', ('', jid_stripped,
|
self.dispatch('ERROR_ANSWER', ('', jid_stripped,
|
||||||
errmsg, errcode))
|
errmsg, errcode))
|
||||||
|
|
||||||
|
if ptype == 'unavailable' and jid_stripped in self.sessions:
|
||||||
|
# automatically terminate sessions that they haven't sent a thread ID in
|
||||||
|
for sess in self.sessions[jid_stripped].values():
|
||||||
|
if not sess.received_thread_id:
|
||||||
|
sess.terminate()
|
||||||
|
del self.sessions[jid_stripped][sess.thread_id]
|
||||||
|
|
||||||
if avatar_sha and ptype != 'error':
|
if avatar_sha and ptype != 'error':
|
||||||
if not self.vcard_shas.has_key(jid_stripped):
|
if not self.vcard_shas.has_key(jid_stripped):
|
||||||
cached_vcard = self.get_cached_vcard(jid_stripped)
|
cached_vcard = self.get_cached_vcard(jid_stripped)
|
||||||
|
|
16
src/gajim.py
16
src/gajim.py
|
@ -621,7 +621,7 @@ class Interface:
|
||||||
jid = array[0].split('/')[0]
|
jid = array[0].split('/')[0]
|
||||||
keyID = array[5]
|
keyID = array[5]
|
||||||
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)
|
||||||
|
@ -647,6 +647,20 @@ class Interface:
|
||||||
if c.resource == resource:
|
if c.resource == resource:
|
||||||
contact1 = c
|
contact1 = c
|
||||||
break
|
break
|
||||||
|
|
||||||
|
highest = gajim.contacts.get_highest_prio_contact_from_contacts(lcontact)
|
||||||
|
if not highest or \
|
||||||
|
(highest.priority < priority and highest.resource != resource) or \
|
||||||
|
(highest.resource == resource and highest.priority > priority):
|
||||||
|
# either this contact is the new highest priority contact or it was the
|
||||||
|
# highest and dropped in priority (so may no longer be the highest)
|
||||||
|
|
||||||
|
# disconnect sessions from this contact's chat controls so we
|
||||||
|
# don't have to open a new tab if a new session comes in
|
||||||
|
|
||||||
|
for ctrl in self.msg_win_mgr.get_chat_controls(jid, account):
|
||||||
|
ctrl.set_session(None)
|
||||||
|
|
||||||
if contact1:
|
if contact1:
|
||||||
if contact1.show in statuss:
|
if contact1.show in statuss:
|
||||||
old_show = statuss.index(contact1.show)
|
old_show = statuss.index(contact1.show)
|
||||||
|
|
|
@ -125,15 +125,12 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
pm = True
|
pm = True
|
||||||
msg_type = 'pm'
|
msg_type = 'pm'
|
||||||
|
|
||||||
jid_of_control = full_jid_with_resource
|
|
||||||
|
|
||||||
highest_contact = gajim.contacts.get_contact_with_highest_priority(
|
highest_contact = gajim.contacts.get_contact_with_highest_priority(
|
||||||
self.conn.name, jid)
|
self.conn.name, jid)
|
||||||
|
|
||||||
if not pm:
|
# does this resource have the highest priority of any available?
|
||||||
if not highest_contact or not highest_contact.resource or \
|
is_highest = not highest_contact or not highest_contact.resource or \
|
||||||
resource == highest_contact.resource or highest_contact.show == 'offline':
|
resource == highest_contact.resource or highest_contact.show == 'offline'
|
||||||
jid_of_control = jid
|
|
||||||
|
|
||||||
# Handle chat states
|
# Handle chat states
|
||||||
contact = gajim.contacts.get_contact(self.conn.name, jid, resource)
|
contact = gajim.contacts.get_contact(self.conn.name, jid, resource)
|
||||||
|
@ -174,11 +171,10 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
advanced_notif_num = notify.get_advanced_notification('message_received',
|
advanced_notif_num = notify.get_advanced_notification('message_received',
|
||||||
self.conn.name, contact)
|
self.conn.name, contact)
|
||||||
|
|
||||||
# Is it a first or next message received ?
|
if not pm and is_highest:
|
||||||
first = False
|
jid_of_control = jid
|
||||||
if not self.control and not gajim.events.get_events(self.conn.name,
|
else:
|
||||||
jid_of_control, [msg_type]):
|
jid_of_control = full_jid_with_resource
|
||||||
first = True
|
|
||||||
|
|
||||||
if not self.control:
|
if not self.control:
|
||||||
# look for an existing chat control without a session
|
# look for an existing chat control without a session
|
||||||
|
@ -186,7 +182,6 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
if ctrl:
|
if ctrl:
|
||||||
self.control = ctrl
|
self.control = ctrl
|
||||||
self.control.set_session(self)
|
self.control.set_session(self)
|
||||||
first = False
|
|
||||||
|
|
||||||
if pm:
|
if pm:
|
||||||
nickname = resource
|
nickname = resource
|
||||||
|
@ -198,17 +193,24 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
xhtml=xhtml, form_node=form_node)
|
xhtml=xhtml, form_node=form_node)
|
||||||
|
|
||||||
nickname = gajim.get_name_from_jid(self.conn.name, jid)
|
nickname = gajim.get_name_from_jid(self.conn.name, jid)
|
||||||
|
|
||||||
# Check and do wanted notifications
|
# Check and do wanted notifications
|
||||||
msg = msgtxt
|
msg = msgtxt
|
||||||
if subject:
|
if subject:
|
||||||
msg = _('Subject: %s') % subject + '\n' + msg
|
msg = _('Subject: %s') % subject + '\n' + msg
|
||||||
focused = False
|
focused = False
|
||||||
|
|
||||||
|
# Is it a first or next message received ?
|
||||||
|
first = False
|
||||||
|
|
||||||
if self.control:
|
if self.control:
|
||||||
parent_win = self.control.parent_win
|
parent_win = self.control.parent_win
|
||||||
if self.control == parent_win.get_active_control() and \
|
if self.control == parent_win.get_active_control() and \
|
||||||
parent_win.window.has_focus:
|
parent_win.window.has_focus:
|
||||||
focused = True
|
focused = True
|
||||||
|
elif not gajim.events.get_events(self.conn.name, \
|
||||||
|
jid_of_control, [msg_type]):
|
||||||
|
first = True
|
||||||
|
|
||||||
notify.notify('new_message', jid_of_control, self.conn.name, [msg_type,
|
notify.notify('new_message', jid_of_control, self.conn.name, [msg_type,
|
||||||
first, nickname, msg, focused], advanced_notif_num)
|
first, nickname, msg, focused], advanced_notif_num)
|
||||||
|
|
Loading…
Add table
Reference in a new issue