diff --git a/src/chat_control.py b/src/chat_control.py index fa398d870..9598be4a2 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -678,7 +678,7 @@ class ChatControlBase(MessageControl): type_ = 'printed_' + self.type_id event = 'message_received' show_in_roster = notify.get_show_in_roster(event, - self.account, self.contact) + self.account, self.contact, self.session) show_in_systray = notify.get_show_in_systray(event, self.account, self.contact) if gc_message: @@ -1841,10 +1841,14 @@ class ChatControl(ChatControlBase): def shutdown(self): # destroy banner tooltip - bug #pygtk for that! self.status_tooltip.destroy() + # Send 'gone' chatstate self.send_chatstate('gone', self.contact) self.contact.chatstate = None self.contact.our_chatstate = None + + self.session.control = None + # Disconnect timer callbacks gobject.source_remove(self.possible_paused_timeout_id) gobject.source_remove(self.possible_inactive_timeout_id) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index f882ecbce..789877a3d 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1752,7 +1752,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, def delete_session(self, jid, thread_id): try: del self.sessions[jid][thread_id] - + if not self.sessions[jid]: del self.sessions[jid] except KeyError: diff --git a/src/message_control.py b/src/message_control.py index a81532bc1..e2e903824 100644 --- a/src/message_control.py +++ b/src/message_control.py @@ -145,6 +145,7 @@ class MessageControl: jid = self.contact.jid if not self.session: + print('uhoh new session') fjid = self.contact.get_full_jid() new_session = gajim.connections[self.account].make_new_session(fjid) diff --git a/src/notify.py b/src/notify.py index 6106227c3..a7f8d11ff 100644 --- a/src/notify.py +++ b/src/notify.py @@ -53,8 +53,7 @@ try: except: USER_HAS_GROWL = False - -def get_show_in_roster(event, account, contact): +def get_show_in_roster(event, account, contact, session = None): '''Return True if this event must be shown in roster, else False''' if event == 'gc_message_received': return True @@ -65,8 +64,10 @@ def get_show_in_roster(event, account, contact): if gajim.config.get_per('notifications', str(num), 'roster') == 'no': return False if event == 'message_received': - chat_control = helpers.get_chat_control(account, contact) - if chat_control: + if session: + if session.control: + return False + elif helpers.get_chat_control(account, contact): return False return True diff --git a/src/roster_window.py b/src/roster_window.py index 485b23cda..b64751e90 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1299,8 +1299,7 @@ class RosterWindow: for result in results: tim = time.localtime(float(result[2])) - self.on_message(jid, result[1], tim, account, msg_type = 'chat', - msg_id = result[0], session = session) + session.roster_message(jid, result[1], tim, msg_type='chat', msg_id=result[0]) def fill_contacts_and_groups_dicts(self, array, account): '''fill gajim.contacts and gajim.groups''' @@ -3960,12 +3959,13 @@ class RosterWindow: contact = self.add_to_not_in_the_roster(account, jid, resource = resource) + session = gajim.connections[account].get_session(fjid, None, 'chat') + if not gajim.interface.msg_win_mgr.has_window(fjid, account): - session = account.make_new_session(account, fjid) - self.control = self.new_chat(session, contact, account, resource = resource) + session.control = self.new_chat(session, contact, account, resource = resource) if len(gajim.events.get_events(account, fjid)): - chat_control.read_queue() + session.control.read_queue() mw = gajim.interface.msg_win_mgr.get_window(fjid, account) mw.set_active_tab(fjid, account) @@ -4292,16 +4292,25 @@ class RosterWindow: fjid = contact.jid if resource: fjid += '/' + resource + + conn = gajim.connections[account] + + if not session: + session = conn.get_session(fjid, None, 'chat') + win = gajim.interface.msg_win_mgr.get_window(fjid, account) if not win: - self.new_chat(session, contact, account, resource = resource) + session.control = self.new_chat(session, contact, account, resource=resource) + + if len(gajim.events.get_events(account, fjid)): + session.control.read_queue() + win = gajim.interface.msg_win_mgr.get_window(fjid, account) - ctrl = win.get_control(fjid, account) # last message is long time ago - gajim.last_message_time[account][ctrl.get_full_jid()] = 0 + gajim.last_message_time[account][session.control.get_full_jid()] = 0 + win.set_active_tab(fjid, account) - if gajim.connections[account].is_zeroconf and \ - gajim.connections[account].status in ('offline', 'invisible'): + if conn.is_zeroconf and conn.status in ('offline', 'invisible'): win.get_control(fjid, account).got_disconnected() win.window.present() diff --git a/src/session.py b/src/session.py index a07a520ff..494be99ef 100644 --- a/src/session.py +++ b/src/session.py @@ -51,7 +51,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): contact.chatstate = chatstate if contact.our_chatstate == 'ask': # we were jep85 disco? contact.our_chatstate = 'active' # no more - self.control.handle_incoming_chatstate() + #self.control.handle_incoming_chatstate() XXX elif contact.chatstate != 'active': # got no valid jep85 answer, peer does not support it contact.chatstate = False @@ -109,7 +109,10 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): first, nickname, msg, focused], advanced_notif_num) if gajim.interface.remote_ctrl: - gajim.interface.remote_ctrl.raise_signal('NewMessage', (self.conn.name, [full_jid_with_resource, message, tim, encrypted, msg_type, subject, chatstate, msg_id, composing_xep, user_nick, xhtml, form_node])) + gajim.interface.remote_ctrl.raise_signal('NewMessage', + (self.conn.name, [full_jid_with_resource, message, tim, + encrypted, msg_type, subject, chatstate, msg_id, + composing_xep, user_nick, xhtml, form_node])) def roster_message(self, jid, msg, tim, encrypted=False, msg_type='', subject=None, resource='', msg_id=None, user_nick='', @@ -188,7 +191,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): type_ = 'normal' event_type = 'single_message_received' - show_in_roster = notify.get_show_in_roster(event_type, self.conn.name, contact) + show_in_roster = notify.get_show_in_roster(event_type, self.conn.name, contact, self) show_in_systray = notify.get_show_in_systray(event_type, self.conn.name, contact) event = gajim.events.create_event(type_, (msg, subject, msg_type, tim, @@ -199,7 +202,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): if popup: if not self.control: - self.control = self.new_chat(self, contact, self.conn.name, resource=resource_for_chat) + self.control = gajim.interface.roster.new_chat(self, contact, self.conn.name, resource=resource_for_chat) if len(gajim.events.get_events(self.conn.name, fjid)): self.control.read_queue()