don't create uneccessary sessions (eg. for groupchat messages), bugfix for pms

This commit is contained in:
Brendan Taylor 2007-08-20 17:33:12 +00:00
parent 59b7e83fd5
commit 88e49ffa46
6 changed files with 17 additions and 17 deletions

View File

@ -1356,7 +1356,7 @@ class ChatControl(ChatControlBase):
name = ''
else:
# ESessions
if self.session.enable_encryption:
if self.session and self.session.enable_encryption:
if not self.esessioned:
msg = _('Encryption enabled')
ChatControlBase.print_conversation_line(self, msg,

View File

@ -1429,7 +1429,8 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
if not mtype:
mtype = 'normal'
session = self.get_session(frm, thread_id, mtype)
if not mtype == 'groupchat':
session = self.get_session(frm, thread_id, mtype)
if thread_id and not session.received_thread_id:
session.received_thread_id = True
@ -1545,7 +1546,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
if not self.last_history_line.has_key(jid):
return
self.dispatch('GC_MSG', (frm, msgtxt, tim, has_timestamp, msghtml))
if session.is_loggable() and not int(float(time.mktime(tim)))\
if not int(float(time.mktime(tim)))\
<= self.last_history_line[jid] and msgtxt:
gajim.logger.write('gc_msg', frm, msgtxt, tim = tim)
return
@ -1577,8 +1578,6 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
def get_session(self, jid, thread_id, type):
'''returns an existing session between this connection and 'jid', returns a new one if none exist.'''
print repr(self.sessions)
session = self.find_session(jid, thread_id, type)
if session:

View File

@ -769,7 +769,6 @@ class EncryptedStanzaSession(StanzaSession):
k = self.sha256(k + srs + oss)
# XXX I can skip generating ks_o here
self.kc_s, self.km_s, self.ks_s = self.generate_responder_keys(k)
self.kc_o, self.km_o, self.ks_o = self.generate_initiator_keys(k)

View File

@ -776,7 +776,7 @@ class Interface:
if pm:
nickname = resource
groupchat_control.on_private_message(nickname, message, array[2],
xhtml)
xhtml, session)
else:
# array: (jid, msg, time, encrypted, msg_type, subject)
if encrypted:

View File

@ -97,12 +97,12 @@ def tree_cell_data_func(column, renderer, model, iter, tv=None):
class PrivateChatControl(ChatControl):
TYPE_ID = message_control.TYPE_PM
def __init__(self, parent_win, gc_contact, contact, acct):
def __init__(self, parent_win, gc_contact, contact, acct, session):
room_jid = contact.jid.split('/')[0]
room_ctrl = gajim.interface.msg_win_mgr.get_control(room_jid, acct)
self.room_name = room_ctrl.name
self.gc_contact = gc_contact
ChatControl.__init__(self, parent_win, contact, acct)
ChatControl.__init__(self, parent_win, contact, acct, session)
self.TYPE_ID = 'pm'
def send_message(self, message):
@ -519,7 +519,7 @@ class GroupchatControl(ChatControlBase):
else:
self.print_conversation(msg, nick, tim, xhtml)
def on_private_message(self, nick, msg, tim, xhtml):
def on_private_message(self, nick, msg, tim, xhtml, session):
# Do we have a queue?
fjid = self.room_jid + '/' + nick
no_queue = len(gajim.events.get_events(self.account, fjid)) == 0
@ -531,7 +531,7 @@ class GroupchatControl(ChatControlBase):
return
event = gajim.events.create_event('pm', (msg, '', 'incoming', tim,
False, '', None, xhtml))
False, '', None, xhtml, session))
gajim.events.add_event(self.account, fjid, event)
autopopup = gajim.config.get('autopopup')
@ -551,7 +551,7 @@ class GroupchatControl(ChatControlBase):
self.parent_win.show_title()
self.parent_win.redraw_tab(self)
else:
self._start_private_message(nick)
self._start_private_message(nick, session)
# Scroll to line
self.list_treeview.expand_row(path[0:1], False)
self.list_treeview.scroll_to_cell(path)
@ -1812,7 +1812,7 @@ class GroupchatControl(ChatControlBase):
menu.show_all()
menu.popup(None, None, None, event.button, event.time)
def _start_private_message(self, nick):
def _start_private_message(self, nick, session = None):
gc_c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick)
nick_jid = gc_c.get_full_jid()

View File

@ -1191,8 +1191,10 @@ class RosterWindow:
for jid in gajim.contacts.get_jid_list(account):
results = gajim.logger.get_unread_msgs_for_jid(jid)
# XXX unread messages should probably have their session with them
session = gajim.connections[account].make_new_session(jid)
# XXX unread messages should probably have their session saved with them
if results:
session = gajim.connections[account].make_new_session(jid)
for result in results:
tim = time.localtime(float(result[2]))
self.on_message(jid, result[1], tim, account, msg_type = 'chat',
@ -3466,7 +3468,7 @@ class RosterWindow:
self.actions_menu_needs_rebuild = True
self.update_status_combobox()
def new_private_chat(self, gc_contact, account):
def new_private_chat(self, gc_contact, account, session = None):
contact = gajim.contacts.contact_from_gc_contact(gc_contact)
type_ = message_control.TYPE_PM
fjid = gc_contact.room_jid + '/' + gc_contact.name
@ -3474,7 +3476,7 @@ class RosterWindow:
if not mw:
mw = gajim.interface.msg_win_mgr.create_window(contact, account, type_)
chat_control = PrivateChatControl(mw, gc_contact, contact, account)
chat_control = PrivateChatControl(mw, gc_contact, contact, account, session)
mw.new_tab(chat_control)
if len(gajim.events.get_events(account, fjid)):
# We call this here to avoid race conditions with widget validation