fix lazy session binding to reuse sessions and pick them up from pending events

This commit is contained in:
Brendan Taylor 2008-06-02 23:26:40 +00:00
parent d19cb43ee0
commit dc89b61d37
3 changed files with 43 additions and 14 deletions

View File

@ -51,6 +51,8 @@ if dbus_support.supported:
from session import ChatControlSession
gajim.default_session_type = ChatControlSession
STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd',
'invisible', 'error']
# kind of events we can wait for an answer
@ -1300,8 +1302,9 @@ sent a message to.'''
# sessions that we haven't received a thread ID in
idless = filter(lambda s: not s.received_thread_id, sessions)
# filter out everything exceptthe default session type
chat_sessions = filter(lambda s: isinstance(s, ChatControlSession), idless)
# filter out everything except the default session type
p = lambda s: isinstance(s, gajim.default_session_type)
chat_sessions = filter(p, idless)
if chat_sessions:
# return the session that we last sent a message in
@ -1310,10 +1313,25 @@ sent a message to.'''
else:
return None
# if deferred is true, the thread ID we're generating is tem
def find_controlless_session(self, jid):
'''find an active session that doesn't have a control attached'''
try:
sessions = self.sessions[jid].values()
# filter out everything except the default session type
p = lambda s: isinstance(s, gajim.default_session_type)
chat_sessions = filter(p, sessions)
orphaned = filter(lambda s: not s.control, chat_sessions)
return orphaned[0]
except KeyError:
return None
def make_new_session(self, jid, thread_id=None, type='chat', cls=None):
if not cls:
cls = ChatControlSession
cls = gajim.default_session_type
# determine if this session is a pm session
# if not, discard the resource

View File

@ -2898,16 +2898,24 @@ class Interface:
if resource:
fjid += '/' + resource
win = self.msg_win_mgr.get_window(fjid, account)
ctrl = None
if win:
ctrl = win.get_controls(fjid, account)
if session:
ctrl = session.control
else:
ctrl = self.new_chat(contact, account, resource = resource)
win = self.msg_win_mgr.get_window(fjid, account)
if win:
ctrl = win.get_controls(fjid, account)[0]
if not ctrl:
ctrl = self.new_chat(contact, account,
resource = resource, session = session)
# last message is long time ago
gajim.last_message_time[account][ctrl.get_full_jid()] = 0
win = ctrl.parent_win
win.set_active_tab(ctrl)
if gajim.connections[account].is_zeroconf and \

View File

@ -153,9 +153,14 @@ class MessageControl:
# Doesn't return None if error
jid = self.contact.jid
original_message = message
conn = gajim.connections[self.account]
if not self.session:
sess = gajim.connections[self.account].make_new_session(jid)
sess = conn.find_controlless_session(jid)
if not sess:
sess = conn.make_new_session(jid)
self.set_session(sess)
xep_200 = bool(self.session) and self.session.enable_encryption
@ -199,9 +204,7 @@ class MessageControl:
return
# Send and update history
return gajim.connections[self.account].send_message(jid,
message, keyID, type = type, chatstate = chatstate,
msg_id = msg_id, composing_xep = composing_xep,
return conn.send_message(jid, message, keyID, type = type,
chatstate = chatstate, msg_id = msg_id, composing_xep = composing_xep,
resource = self.resource, user_nick = user_nick,
session = self.session,
original_message = original_message)
session = self.session, original_message = original_message)