Author: bct Date: 2008-06-03 01:26:32 +0200 (Tue, 03 Jun 2008) New Revision: 9747
Modified: trunk/src/chat_control.py trunk/src/gajim.py trunk/src/message_control.py trunk/src/session.py Log: don't assign a session to a control until it's needed
Modified: trunk/src/chat_control.py =================================================================== --- trunk/src/chat_control.py 2008-06-02 23:26:23 UTC (rev 9746) +++ trunk/src/chat_control.py 2008-06-02 23:26:32 UTC (rev 9747) @@ -1112,7 +1112,9 @@ self.on_avatar_eventbox_button_press_event) self.handlers[id] = widget
- self.set_session(session) + self.session = session + if session: + session.control = self
# Enable ecryption if needed e2e_is_active = hasattr(self, 'session') and self.session and self.session.enable_encryption
Modified: trunk/src/gajim.py =================================================================== --- trunk/src/gajim.py 2008-06-02 23:26:23 UTC (rev 9746) +++ trunk/src/gajim.py 2008-06-02 23:26:32 UTC (rev 9747) @@ -2041,7 +2041,7 @@ connection = gajim.connections[account] contact = gajim.contacts.create_contact(jid = jid.getStripped(), resource = resource, show = connection.get_status()) - self.new_chat(session, contact, account, resource = resource) + self.new_chat(contact, account, resource = resource, session = session)
negotiation.FeatureNegotiationWindow(account, jid, session, form)
@@ -2446,7 +2446,7 @@ if not session: session = gajim.connections[account].get_or_create_session(fjid, None)
- self.new_chat(session, contact, account, resource = resource) + self.new_chat(contact, account, resource = resource, session = session) ctrl = session.control
gajim.last_message_time[account][jid] = 0 # long time ago @@ -2843,7 +2843,7 @@ # We call this here to avoid race conditions with widget validation session.control.read_queue()
- def new_chat(self, session, contact, account, resource = None): + def new_chat(self, contact, account, resource = None, session = None): # Get target window, create a control, and associate it with the window type_ = message_control.TYPE_CHAT
@@ -2877,8 +2877,8 @@ session = gajim.connections[account].get_or_create_session(fjid, None)
if not self.msg_win_mgr.has_window(fjid, account): - session.control = self.new_chat(session, contact, account, - resource=resource) + session.control = self.new_chat(contact, account, + resource=resource, session=session) if len(gajim.events.get_events(account, fjid)): session.control.read_queue()
@@ -2898,41 +2898,20 @@ if resource: fjid += '/' + resource
- conn = gajim.connections[account] + win = self.msg_win_mgr.get_window(fjid, account)
- if not session and fjid in conn.sessions: - sessions = filter(lambda s: isinstance(s, ChatControlSession), - conn.sessions[fjid].values()) - - # look for an existing session with a chat control - for s in sessions: - if s.control: - session = s - break - - if not session and not len(sessions) == 0: - # there are no sessions with chat controls, just take the first one - session = sessions[0] - - if not session: - # couldn't find an existing ChatControlSession, just make a new one - session = conn.make_new_session(fjid, None, 'chat') - - if not session.control: - # open a new chat control - session.control = self.new_chat(session, contact, account, - resource=resource) - - if len(gajim.events.get_events(account, fjid)): - session.control.read_queue() - + if win: + ctrl = win.get_controls(fjid, account) + else: + ctrl = self.new_chat(contact, account, resource = resource) + win = self.msg_win_mgr.get_window(fjid, account) # last message is long time ago - gajim.last_message_time[account][session.control.get_full_jid()] = 0 + gajim.last_message_time[account][ctrl.get_full_jid()] = 0
- win = session.control.parent_win - win.set_active_tab(session.control) + win.set_active_tab(ctrl)
- if conn.is_zeroconf and conn.status in ('offline', 'invisible'): + if gajim.connections[account].is_zeroconf and \ + gajim.connections[account].status in ('offline', 'invisible'): for ctrl in win.get_controls(fjid, account): ctrl.got_disconnected()
Modified: trunk/src/message_control.py =================================================================== --- trunk/src/message_control.py 2008-06-02 23:26:23 UTC (rev 9746) +++ trunk/src/message_control.py 2008-06-02 23:26:32 UTC (rev 9747) @@ -134,12 +134,17 @@ new_key = session.thread_id
if oldsession: - self.parent_win.change_thread_key( - self.contact.jid, self.account, + jid = self.contact.jid + if self.resource: + jid += '/' + self.resource + + self.parent_win.change_thread_key(jid, self.account, oldsession.thread_id, new_key)
if oldsession.enable_encryption: self.print_esession_details() + else: + self.parent_win.move_from_sessionless(self)
def send_message(self, message, keyID = '', type = 'chat', chatstate = None, msg_id = None, composing_xep = None, resource = None, @@ -152,7 +157,6 @@ if not self.session: sess = gajim.connections[self.account].make_new_session(jid) self.set_session(sess) - self.parent_win.move_from_sessionless(self)
xep_200 = bool(self.session) and self.session.enable_encryption
Modified: trunk/src/session.py =================================================================== --- trunk/src/session.py 2008-06-02 23:26:23 UTC (rev 9746) +++ trunk/src/session.py 2008-06-02 23:26:32 UTC (rev 9747) @@ -186,7 +186,6 @@ if ctrl: self.control = ctrl self.control.set_session(self) - self.control.parent_win.move_from_sessionless(self.control) first = False
if pm: