don't assign a session to a control until it's needed
This commit is contained in:
parent
7b6b6de1c5
commit
d19cb43ee0
|
@ -1112,7 +1112,9 @@ class ChatControl(ChatControlBase):
|
|||
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
|
||||
|
|
51
src/gajim.py
51
src/gajim.py
|
@ -2041,7 +2041,7 @@ class Interface:
|
|||
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 @@ class Interface:
|
|||
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 @@ class Interface:
|
|||
# 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 @@ class Interface:
|
|||
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 @@ class Interface:
|
|||
if resource:
|
||||
fjid += '/' + resource
|
||||
|
||||
conn = gajim.connections[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()
|
||||
win = self.msg_win_mgr.get_window(fjid, account)
|
||||
|
||||
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()
|
||||
|
||||
|
|
|
@ -134,12 +134,17 @@ class MessageControl:
|
|||
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 @@ class MessageControl:
|
|||
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
|
||||
|
||||
|
|
|
@ -186,7 +186,6 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
|||
if ctrl:
|
||||
self.control = ctrl
|
||||
self.control.set_session(self)
|
||||
self.control.parent_win.move_from_sessionless(self.control)
|
||||
first = False
|
||||
|
||||
if pm:
|
||||
|
|
Loading…
Reference in New Issue