2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/session.py
|
|
|
|
##
|
2014-01-02 09:33:54 +01:00
|
|
|
## Copyright (C) 2008-2014 Yann Leboulanger <asterix AT lagaule.org>
|
2010-03-11 16:52:36 +01:00
|
|
|
## Copyright (C) 2008 Brendan Taylor <whateley AT gmail.com>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Jonathan Schleifer <js-gajim AT webkeks.org>
|
|
|
|
## Stephan Erb <steve-e AT h3c.de>
|
|
|
|
##
|
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 3 only.
|
|
|
|
##
|
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
## You should have received a copy of the GNU General Public License
|
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
##
|
|
|
|
|
2017-08-08 16:44:03 +02:00
|
|
|
import nbxmpp
|
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import helpers
|
2008-02-06 02:40:51 +01:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import events
|
|
|
|
from gajim.common import exceptions
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import stanza_session
|
|
|
|
from gajim.common import contacts
|
|
|
|
from gajim.common import ged
|
|
|
|
from gajim.common.connection_handlers_events import ChatstateReceivedEvent, \
|
2011-11-22 20:08:08 +01:00
|
|
|
InformationEvent
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common.logger import KindConstant
|
2008-02-06 02:40:51 +01:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import message_control
|
2008-02-06 02:40:51 +01:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import notify
|
2008-02-06 02:40:51 +01:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import dialogs
|
|
|
|
from gajim import negotiation
|
2008-06-21 21:12:47 +02:00
|
|
|
|
2008-02-06 02:40:51 +01:00
|
|
|
class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, conn, jid, thread_id, type_='chat'):
|
|
|
|
stanza_session.EncryptedStanzaSession.__init__(self, conn, jid, thread_id,
|
|
|
|
type_='chat')
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('decrypted-message-received', ged.GUI1,
|
2010-12-08 21:58:13 +01:00
|
|
|
self._nec_decrypted_message_received)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.control = None
|
|
|
|
|
|
|
|
def detach_from_control(self):
|
|
|
|
if self.control:
|
|
|
|
self.control.set_session(None)
|
|
|
|
|
|
|
|
def acknowledge_termination(self):
|
|
|
|
self.detach_from_control()
|
|
|
|
stanza_session.EncryptedStanzaSession.acknowledge_termination(self)
|
|
|
|
|
|
|
|
def terminate(self, send_termination = True):
|
|
|
|
stanza_session.EncryptedStanzaSession.terminate(self, send_termination)
|
|
|
|
self.detach_from_control()
|
|
|
|
|
2010-12-08 21:58:13 +01:00
|
|
|
def _nec_decrypted_message_received(self, obj):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Dispatch a received <message> stanza
|
|
|
|
"""
|
2010-12-08 21:58:13 +01:00
|
|
|
if obj.session != self:
|
|
|
|
return
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.get_contact(self.conn.name, obj.jid,
|
2015-05-17 15:40:42 +02:00
|
|
|
obj.resource)
|
2016-01-17 20:54:20 +01:00
|
|
|
if not contact:
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.get_gc_contact(self.conn.name, obj.jid,
|
2016-01-17 20:54:20 +01:00
|
|
|
obj.resource)
|
2010-12-08 21:58:13 +01:00
|
|
|
if self.resource != obj.resource:
|
|
|
|
self.resource = obj.resource
|
2015-05-17 15:40:42 +02:00
|
|
|
if self.control:
|
2016-01-17 20:54:20 +01:00
|
|
|
if isinstance(contact, contacts.GC_Contact):
|
|
|
|
self.control.gc_contact = contact
|
|
|
|
self.control.contact = contact.as_contact()
|
|
|
|
else:
|
|
|
|
self.control.contact = contact
|
2015-05-17 15:40:42 +02:00
|
|
|
if self.control.resource:
|
|
|
|
self.control.change_resource(self.resource)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2010-12-08 21:58:13 +01:00
|
|
|
if obj.mtype == 'chat':
|
2016-07-17 14:23:22 +02:00
|
|
|
if not obj.msgtxt and obj.chatstate is None:
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
|
|
|
|
2017-08-08 16:44:03 +02:00
|
|
|
log_type = KindConstant.CHAT_MSG_RECV
|
|
|
|
if obj.forwarded and obj.sent:
|
|
|
|
log_type = KindConstant.CHAT_MSG_SENT
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-08-08 16:44:03 +02:00
|
|
|
log_type = KindConstant.SINGLE_MSG_RECV
|
|
|
|
if obj.forwarded and obj.sent:
|
|
|
|
log_type = KindConstant.SINGLE_MSG_SENT
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
treat_as = app.config.get('treat_incoming_messages')
|
2010-12-11 18:51:34 +01:00
|
|
|
if treat_as:
|
|
|
|
obj.mtype = treat_as
|
2010-02-08 15:08:40 +01:00
|
|
|
pm = False
|
2010-12-08 21:58:13 +01:00
|
|
|
if obj.gc_control and obj.resource:
|
2010-02-08 15:08:40 +01:00
|
|
|
# It's a Private message
|
|
|
|
pm = True
|
2010-12-08 21:58:13 +01:00
|
|
|
obj.mtype = 'pm'
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-08 16:44:03 +02:00
|
|
|
if self.is_loggable() and obj.msgtxt:
|
2017-08-13 13:18:56 +02:00
|
|
|
if obj.xhtml and app.config.get('log_xhtml_messages'):
|
2017-08-08 16:44:03 +02:00
|
|
|
msg_to_log = obj.xhtml
|
|
|
|
else:
|
|
|
|
msg_to_log = obj.msgtxt
|
|
|
|
|
|
|
|
jid = obj.fjid
|
|
|
|
if not pm:
|
|
|
|
jid = obj.jid
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
obj.msg_log_id = app.logger.insert_into_logs(
|
2017-11-17 21:42:44 +01:00
|
|
|
self.conn.name, jid, obj.timestamp, log_type,
|
2017-08-08 16:44:03 +02:00
|
|
|
message=msg_to_log,
|
|
|
|
subject=obj.subject,
|
2017-10-22 23:27:47 +02:00
|
|
|
additional_data=obj.additional_data,
|
|
|
|
stanza_id=obj.unique_id)
|
2017-08-08 16:44:03 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# Handle chat states
|
2011-11-06 17:20:58 +01:00
|
|
|
if contact and (not obj.forwarded or not obj.sent):
|
2010-12-08 21:58:13 +01:00
|
|
|
if self.control and self.control.type_id == \
|
|
|
|
message_control.TYPE_CHAT:
|
|
|
|
if obj.chatstate is not None:
|
2010-02-08 15:08:40 +01:00
|
|
|
# other peer sent us reply, so he supports jep85 or jep22
|
2010-12-08 21:58:13 +01:00
|
|
|
contact.chatstate = obj.chatstate
|
2010-02-08 15:08:40 +01:00
|
|
|
if contact.our_chatstate == 'ask': # we were jep85 disco?
|
|
|
|
contact.our_chatstate = 'active' # no more
|
2017-08-13 13:18:56 +02:00
|
|
|
app.nec.push_incoming_event(ChatstateReceivedEvent(None,
|
2010-12-08 21:58:13 +01:00
|
|
|
conn=obj.conn, msg_obj=obj))
|
2010-02-08 15:08:40 +01:00
|
|
|
elif contact.chatstate != 'active':
|
|
|
|
# got no valid jep85 answer, peer does not support it
|
|
|
|
contact.chatstate = False
|
2010-12-08 21:58:13 +01:00
|
|
|
elif obj.chatstate == 'active':
|
2010-02-08 15:08:40 +01:00
|
|
|
# Brand new message, incoming.
|
2010-12-08 21:58:13 +01:00
|
|
|
contact.our_chatstate = obj.chatstate
|
|
|
|
contact.chatstate = obj.chatstate
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# THIS MUST BE AFTER chatstates handling
|
2016-09-05 00:01:29 +02:00
|
|
|
# AND BEFORE playsound (else we hear sounding on chatstates!)
|
2010-12-08 21:58:13 +01:00
|
|
|
if not obj.msgtxt: # empty message text
|
2011-05-01 22:09:50 +02:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.config.get_per('accounts', self.conn.name,
|
|
|
|
'ignore_unknown_contacts') and not app.contacts.get_contacts(
|
2010-12-08 21:58:13 +01:00
|
|
|
self.conn.name, obj.jid) and not pm:
|
2011-05-01 22:09:50 +02:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
highest_contact = app.contacts.get_contact_with_highest_priority(
|
2011-05-01 22:09:50 +02:00
|
|
|
self.conn.name, obj.jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2011-05-01 22:09:50 +02:00
|
|
|
# does this resource have the highest priority of any available?
|
|
|
|
is_highest = not highest_contact or not highest_contact.resource or \
|
|
|
|
obj.resource == highest_contact.resource or highest_contact.show ==\
|
|
|
|
'offline'
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if not self.control:
|
2017-08-13 13:18:56 +02:00
|
|
|
ctrl = app.interface.msg_win_mgr.search_control(obj.jid,
|
2011-08-21 09:51:57 +02:00
|
|
|
obj.conn.name, obj.resource)
|
2010-02-08 15:08:40 +01:00
|
|
|
if ctrl:
|
|
|
|
self.control = ctrl
|
|
|
|
self.control.set_session(self)
|
2016-01-17 20:54:20 +01:00
|
|
|
if isinstance(contact, contacts.GC_Contact):
|
|
|
|
self.control.gc_contact = contact
|
|
|
|
self.control.contact = contact.as_contact()
|
|
|
|
else:
|
|
|
|
self.control.contact = contact
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2011-05-01 22:09:50 +02:00
|
|
|
if not pm:
|
|
|
|
self.roster_message2(obj)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.interface.remote_ctrl:
|
|
|
|
app.interface.remote_ctrl.raise_signal('NewMessage', (
|
2010-12-08 21:58:13 +01:00
|
|
|
self.conn.name, [obj.fjid, obj.msgtxt, obj.timestamp,
|
2011-10-16 11:14:40 +02:00
|
|
|
obj.encrypted, obj.mtype, obj.subject, obj.chatstate,
|
2016-02-27 19:52:46 +01:00
|
|
|
obj.msg_log_id, obj.user_nick, obj.xhtml, obj.form_node]))
|
2010-12-08 21:58:13 +01:00
|
|
|
|
2011-05-01 22:09:50 +02:00
|
|
|
def roster_message2(self, obj):
|
|
|
|
"""
|
|
|
|
Display the message or show notification in the roster
|
|
|
|
"""
|
|
|
|
contact = None
|
|
|
|
jid = obj.jid
|
|
|
|
resource = obj.resource
|
|
|
|
|
|
|
|
fjid = jid
|
|
|
|
|
|
|
|
# Try to catch the contact with correct resource
|
|
|
|
if resource:
|
|
|
|
fjid = jid + '/' + resource
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.get_contact(obj.conn.name, jid, resource)
|
2011-05-01 22:09:50 +02:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
highest_contact = app.contacts.get_contact_with_highest_priority(
|
2011-05-01 22:09:50 +02:00
|
|
|
obj.conn.name, jid)
|
|
|
|
if not contact:
|
|
|
|
# If there is another resource, it may be a message from an
|
|
|
|
# invisible resource
|
2017-08-13 13:18:56 +02:00
|
|
|
lcontact = app.contacts.get_contacts(obj.conn.name, jid)
|
2011-05-01 22:09:50 +02:00
|
|
|
if (len(lcontact) > 1 or (lcontact and lcontact[0].resource and \
|
|
|
|
lcontact[0].show != 'offline')) and jid.find('@') > 0:
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.copy_contact(highest_contact)
|
2011-05-01 22:09:50 +02:00
|
|
|
contact.resource = resource
|
|
|
|
contact.priority = 0
|
|
|
|
contact.show = 'offline'
|
|
|
|
contact.status = ''
|
2017-08-13 13:18:56 +02:00
|
|
|
app.contacts.add_contact(obj.conn.name, contact)
|
2011-05-01 22:09:50 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
# Default to highest prio
|
|
|
|
fjid = jid
|
|
|
|
contact = highest_contact
|
|
|
|
|
|
|
|
if not contact:
|
|
|
|
# contact is not in roster
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.interface.roster.add_to_not_in_the_roster(
|
2011-05-01 22:09:50 +02:00
|
|
|
obj.conn.name, jid, obj.user_nick)
|
|
|
|
|
|
|
|
if not self.control:
|
2017-08-13 13:18:56 +02:00
|
|
|
ctrl = app.interface.msg_win_mgr.search_control(obj.jid,
|
2011-08-21 09:51:57 +02:00
|
|
|
obj.conn.name, obj.resource)
|
2011-05-01 22:09:50 +02:00
|
|
|
if ctrl:
|
|
|
|
self.control = ctrl
|
|
|
|
self.control.set_session(self)
|
|
|
|
else:
|
2011-08-21 09:51:57 +02:00
|
|
|
fjid = jid
|
2011-05-01 22:09:50 +02:00
|
|
|
|
|
|
|
obj.popup = helpers.allow_popup_window(self.conn.name)
|
|
|
|
|
2016-02-29 21:04:08 +01:00
|
|
|
event_t = events.ChatEvent
|
2011-05-01 22:09:50 +02:00
|
|
|
event_type = 'message_received'
|
|
|
|
|
|
|
|
if obj.mtype == 'normal':
|
2016-02-29 21:04:08 +01:00
|
|
|
event_t = events.NormalEvent
|
2011-05-01 22:09:50 +02:00
|
|
|
event_type = 'single_message_received'
|
|
|
|
|
|
|
|
if self.control and obj.mtype != 'normal':
|
2017-03-14 22:17:16 +01:00
|
|
|
# We have a ChatControl open
|
|
|
|
obj.show_in_roster = False
|
|
|
|
obj.show_in_systray = False
|
2017-08-13 23:03:11 +02:00
|
|
|
do_event = False
|
2017-03-14 22:17:16 +01:00
|
|
|
elif obj.forwarded and obj.sent:
|
|
|
|
# Its a Carbon Copied Message we sent
|
2011-05-01 22:09:50 +02:00
|
|
|
obj.show_in_roster = False
|
|
|
|
obj.show_in_systray = False
|
2017-09-29 12:41:26 +02:00
|
|
|
unread_events = app.events.get_events(
|
|
|
|
self.conn.name, fjid, types=['chat'])
|
|
|
|
read_ids = []
|
|
|
|
for msg in unread_events:
|
|
|
|
read_ids.append(msg.msg_log_id)
|
|
|
|
app.logger.set_read_messages(read_ids)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.events.remove_events(self.conn.name, fjid, types=['chat'])
|
2017-08-13 23:03:11 +02:00
|
|
|
do_event = False
|
2011-05-01 22:09:50 +02:00
|
|
|
else:
|
2017-03-14 22:17:16 +01:00
|
|
|
# Everything else
|
2011-05-01 22:09:50 +02:00
|
|
|
obj.show_in_roster = notify.get_show_in_roster(event_type,
|
|
|
|
self.conn.name, contact, self)
|
|
|
|
obj.show_in_systray = notify.get_show_in_systray(event_type,
|
|
|
|
self.conn.name, contact)
|
2017-11-10 18:09:36 +01:00
|
|
|
if obj.mtype == 'normal' and obj.popup:
|
2017-08-13 23:03:11 +02:00
|
|
|
do_event = False
|
|
|
|
else:
|
|
|
|
do_event = True
|
|
|
|
if do_event:
|
2016-02-29 21:04:08 +01:00
|
|
|
event = event_t(obj.msgtxt, obj.subject, obj.mtype, obj.timestamp,
|
2016-02-29 21:29:20 +01:00
|
|
|
obj.encrypted, obj.resource, obj.msg_log_id,
|
|
|
|
correct_id=(obj.id_, obj.correct_id), xhtml=obj.xhtml,
|
2016-02-29 21:04:08 +01:00
|
|
|
session=self, form_node=obj.form_node,
|
|
|
|
displaymarking=obj.displaymarking,
|
|
|
|
sent_forwarded=obj.forwarded and obj.sent,
|
2011-05-01 22:09:50 +02:00
|
|
|
show_in_roster=obj.show_in_roster,
|
2017-11-01 23:14:47 +01:00
|
|
|
show_in_systray=obj.show_in_systray,
|
|
|
|
additional_data=obj.additional_data)
|
2011-05-01 22:09:50 +02:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.events.add_event(self.conn.name, fjid, event)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def roster_message(self, jid, msg, tim, encrypted=False, msg_type='',
|
2016-02-27 19:52:46 +01:00
|
|
|
subject=None, resource='', msg_log_id=None, user_nick='', xhtml=None,
|
2017-02-08 03:12:41 +01:00
|
|
|
form_node=None, displaymarking=None, additional_data=None):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Display the message or show notification in the roster
|
|
|
|
"""
|
|
|
|
contact = None
|
|
|
|
fjid = jid
|
|
|
|
|
2017-02-08 03:12:41 +01:00
|
|
|
if additional_data is None:
|
|
|
|
additional_data = {}
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# Try to catch the contact with correct resource
|
|
|
|
if resource:
|
|
|
|
fjid = jid + '/' + resource
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.get_contact(self.conn.name, jid, resource)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
highest_contact = app.contacts.get_contact_with_highest_priority(
|
2010-02-08 15:08:40 +01:00
|
|
|
self.conn.name, jid)
|
|
|
|
if not contact:
|
|
|
|
# If there is another resource, it may be a message from an invisible
|
|
|
|
# resource
|
2017-08-13 13:18:56 +02:00
|
|
|
lcontact = app.contacts.get_contacts(self.conn.name, jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
if (len(lcontact) > 1 or (lcontact and lcontact[0].resource and \
|
|
|
|
lcontact[0].show != 'offline')) and jid.find('@') > 0:
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.copy_contact(highest_contact)
|
2010-02-08 15:08:40 +01:00
|
|
|
contact.resource = resource
|
|
|
|
if resource:
|
|
|
|
fjid = jid + '/' + resource
|
|
|
|
contact.priority = 0
|
|
|
|
contact.show = 'offline'
|
|
|
|
contact.status = ''
|
2017-08-13 13:18:56 +02:00
|
|
|
app.contacts.add_contact(self.conn.name, contact)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
else:
|
|
|
|
# Default to highest prio
|
|
|
|
fjid = jid
|
|
|
|
contact = highest_contact
|
|
|
|
|
|
|
|
if not contact:
|
|
|
|
# contact is not in roster
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.interface.roster.add_to_not_in_the_roster(
|
2010-02-08 15:08:40 +01:00
|
|
|
self.conn.name, jid, user_nick)
|
|
|
|
|
|
|
|
if not self.control:
|
2017-08-13 13:18:56 +02:00
|
|
|
ctrl = app.interface.msg_win_mgr.get_control(fjid, self.conn.name)
|
2010-02-08 15:08:40 +01:00
|
|
|
if ctrl:
|
|
|
|
self.control = ctrl
|
|
|
|
self.control.set_session(self)
|
|
|
|
else:
|
2011-08-21 09:51:57 +02:00
|
|
|
fjid = jid
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# Do we have a queue?
|
2017-08-13 13:18:56 +02:00
|
|
|
no_queue = len(app.events.get_events(self.conn.name, fjid)) == 0
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2011-06-13 23:06:43 +02:00
|
|
|
popup = helpers.allow_popup_window(self.conn.name)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if msg_type == 'normal' and popup: # it's single message to be autopopuped
|
|
|
|
dialogs.SingleMessageWindow(self.conn.name, contact.jid,
|
|
|
|
action='receive', from_whom=jid, subject=subject, message=msg,
|
2010-06-09 10:39:36 +02:00
|
|
|
resource=resource, session=self, form_node=form_node)
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
# We print if window is opened and it's not a single message
|
|
|
|
if self.control and msg_type != 'normal':
|
|
|
|
typ = ''
|
|
|
|
|
|
|
|
if msg_type == 'error':
|
|
|
|
typ = 'error'
|
|
|
|
|
|
|
|
self.control.print_conversation(msg, typ, tim=tim, encrypted=encrypted,
|
2016-09-05 23:07:31 +02:00
|
|
|
subject=subject, xhtml=xhtml, displaymarking=displaymarking,
|
|
|
|
additional_data=additional_data)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-02-27 19:52:46 +01:00
|
|
|
if msg_log_id:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.logger.set_read_messages([msg_log_id])
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
# We save it in a queue
|
2016-02-29 21:04:08 +01:00
|
|
|
event_t = events.ChatEvent
|
2010-02-08 15:08:40 +01:00
|
|
|
event_type = 'message_received'
|
|
|
|
|
|
|
|
if msg_type == 'normal':
|
2016-02-29 21:04:08 +01:00
|
|
|
event_t = events.NormalEvent
|
2010-02-08 15:08:40 +01:00
|
|
|
event_type = 'single_message_received'
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2016-02-29 21:04:08 +01:00
|
|
|
event = event_t(msg, subject, msg_type, tim, encrypted, resource,
|
|
|
|
msg_log_id, xhtml=xhtml, session=self, form_node=form_node,
|
|
|
|
displaymarking=displaymarking, sent_forwarded=False,
|
2016-09-05 23:07:31 +02:00
|
|
|
show_in_roster=show_in_roster, show_in_systray=show_in_systray,
|
|
|
|
additional_data=additional_data)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.events.add_event(self.conn.name, fjid, event)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if popup:
|
|
|
|
if not self.control:
|
2017-08-13 13:18:56 +02:00
|
|
|
self.control = app.interface.new_chat(contact,
|
2011-08-21 09:51:57 +02:00
|
|
|
self.conn.name, session=self)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if len(app.events.get_events(self.conn.name, fjid)):
|
2010-02-08 15:08:40 +01:00
|
|
|
self.control.read_queue()
|
|
|
|
else:
|
|
|
|
if no_queue: # We didn't have a queue: we change icons
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.draw_contact(jid, self.conn.name)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.show_title() # we show the * or [n]
|
2010-02-08 15:08:40 +01:00
|
|
|
# Select the big brother contact in roster, it's visible because it has
|
|
|
|
# events.
|
2017-08-13 13:18:56 +02:00
|
|
|
family = app.contacts.get_metacontacts_family(self.conn.name, jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
if family:
|
|
|
|
nearby_family, bb_jid, bb_account = \
|
2017-08-13 13:18:56 +02:00
|
|
|
app.contacts.get_nearby_family_and_big_brother(family,
|
2010-02-08 15:08:40 +01:00
|
|
|
self.conn.name)
|
|
|
|
else:
|
|
|
|
bb_jid, bb_account = jid, self.conn.name
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.select_contact(bb_jid, bb_account)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# ---- ESessions stuff ---
|
|
|
|
|
|
|
|
def handle_negotiation(self, form):
|
|
|
|
if form.getField('accept') and not form['accept'] in ('1', 'true'):
|
|
|
|
self.cancelled_negotiation()
|
|
|
|
return
|
|
|
|
|
|
|
|
# encrypted session states. these are described in stanza_session.py
|
|
|
|
|
|
|
|
try:
|
|
|
|
if form.getType() == 'form' and 'security' in form.asDict():
|
2010-05-25 16:33:40 +02:00
|
|
|
security_options = [x[1] for x in form.getField('security').\
|
|
|
|
getOptions()]
|
2010-02-10 17:59:17 +01:00
|
|
|
if security_options == ['none']:
|
|
|
|
self.respond_archiving(form)
|
|
|
|
else:
|
|
|
|
# bob responds
|
|
|
|
|
|
|
|
# we don't support 3-message negotiation as the responder
|
|
|
|
if 'dhkeys' in form.asDict():
|
2010-05-25 16:33:40 +02:00
|
|
|
self.fail_bad_negotiation('3 message negotiation not '
|
|
|
|
'supported when responding', ('dhkeys',))
|
2010-02-10 17:59:17 +01:00
|
|
|
return
|
|
|
|
|
2010-05-25 16:33:40 +02:00
|
|
|
negotiated, not_acceptable, ask_user = \
|
|
|
|
self.verify_options_bob(form)
|
2010-02-10 17:59:17 +01:00
|
|
|
|
|
|
|
if ask_user:
|
|
|
|
def accept_nondefault_options(is_checked):
|
|
|
|
self.dialog.destroy()
|
|
|
|
negotiated.update(ask_user)
|
2010-05-25 16:33:40 +02:00
|
|
|
self.respond_e2e_bob(form, negotiated,
|
|
|
|
not_acceptable)
|
2010-02-10 17:59:17 +01:00
|
|
|
|
|
|
|
def reject_nondefault_options():
|
|
|
|
self.dialog.destroy()
|
|
|
|
for key in ask_user.keys():
|
|
|
|
not_acceptable.append(key)
|
2010-05-25 16:33:40 +02:00
|
|
|
self.respond_e2e_bob(form, negotiated,
|
|
|
|
not_acceptable)
|
2010-02-10 17:59:17 +01:00
|
|
|
|
2010-05-25 16:33:40 +02:00
|
|
|
self.dialog = dialogs.YesNoDialog(_('Confirm these '
|
2011-09-28 17:43:59 +02:00
|
|
|
'session options'),
|
|
|
|
_('The remote client wants to negotiate a session '
|
|
|
|
'with these features:\n\n%s\n\nAre these options '
|
|
|
|
'acceptable?''') % (
|
|
|
|
negotiation.describe_features(ask_user)),
|
2010-02-08 15:08:40 +01:00
|
|
|
on_response_yes=accept_nondefault_options,
|
2013-08-15 23:14:42 +02:00
|
|
|
on_response_no=reject_nondefault_options,
|
|
|
|
transient_for=self.control.parent_win.window)
|
2010-02-10 17:59:17 +01:00
|
|
|
else:
|
|
|
|
self.respond_e2e_bob(form, negotiated, not_acceptable)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
elif self.status == 'requested-archiving' and form.getType() == \
|
|
|
|
'submit':
|
|
|
|
try:
|
|
|
|
self.archiving_accepted(form)
|
2013-01-01 23:18:36 +01:00
|
|
|
except exceptions.NegotiationError as details:
|
2010-02-10 17:59:17 +01:00
|
|
|
self.fail_bad_negotiation(details)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
# alice accepts
|
|
|
|
elif self.status == 'requested-e2e' and form.getType() == 'submit':
|
|
|
|
negotiated, not_acceptable, ask_user = self.verify_options_alice(
|
|
|
|
form)
|
|
|
|
|
|
|
|
if ask_user:
|
|
|
|
def accept_nondefault_options(is_checked):
|
2011-09-28 17:43:59 +02:00
|
|
|
if dialog:
|
|
|
|
dialog.destroy()
|
|
|
|
|
|
|
|
if is_checked:
|
2017-08-13 13:18:56 +02:00
|
|
|
allow_no_log_for = app.config.get_per(
|
2011-09-28 17:43:59 +02:00
|
|
|
'accounts', self.conn.name,
|
|
|
|
'allow_no_log_for').split()
|
|
|
|
jid = str(self.jid)
|
|
|
|
if jid not in allow_no_log_for:
|
|
|
|
allow_no_log_for.append(jid)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set_per('accounts', self.conn.name,
|
2011-09-28 17:43:59 +02:00
|
|
|
'allow_no_log_for', ' '.join(allow_no_log_for))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
negotiated.update(ask_user)
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.accept_e2e_alice(form, negotiated)
|
2013-01-01 23:18:36 +01:00
|
|
|
except exceptions.NegotiationError as details:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.fail_bad_negotiation(details)
|
|
|
|
|
|
|
|
def reject_nondefault_options():
|
|
|
|
self.reject_negotiation()
|
|
|
|
dialog.destroy()
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
allow_no_log_for = app.config.get_per('accounts',
|
2011-09-28 17:43:59 +02:00
|
|
|
self.conn.name, 'allow_no_log_for').split()
|
|
|
|
if str(self.jid) in allow_no_log_for:
|
|
|
|
dialog = None
|
|
|
|
accept_nondefault_options(False)
|
|
|
|
else:
|
|
|
|
dialog = dialogs.YesNoDialog(_('Confirm these session '
|
|
|
|
'options'),
|
|
|
|
_('The remote client selected these options:\n\n%s'
|
|
|
|
'\n\nContinue with the session?') % (
|
2010-02-08 15:08:40 +01:00
|
|
|
negotiation.describe_features(ask_user)),
|
2011-09-28 17:43:59 +02:00
|
|
|
_('Always accept for this contact'),
|
2010-02-08 15:08:40 +01:00
|
|
|
on_response_yes = accept_nondefault_options,
|
2013-08-15 23:16:38 +02:00
|
|
|
on_response_no = reject_nondefault_options,
|
|
|
|
transient_for=self.control.parent_win.window)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
self.accept_e2e_alice(form, negotiated)
|
2013-01-01 23:18:36 +01:00
|
|
|
except exceptions.NegotiationError as details:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.fail_bad_negotiation(details)
|
|
|
|
|
2010-02-10 17:59:17 +01:00
|
|
|
return
|
|
|
|
elif self.status == 'responded-archiving' and form.getType() == \
|
|
|
|
'result':
|
|
|
|
try:
|
|
|
|
self.we_accept_archiving(form)
|
2013-01-01 23:18:36 +01:00
|
|
|
except exceptions.NegotiationError as details:
|
2010-02-10 17:59:17 +01:00
|
|
|
self.fail_bad_negotiation(details)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
|
|
|
elif self.status == 'responded-e2e' and form.getType() == 'result':
|
|
|
|
try:
|
|
|
|
self.accept_e2e_bob(form)
|
2013-01-01 23:18:36 +01:00
|
|
|
except exceptions.NegotiationError as details:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.fail_bad_negotiation(details)
|
|
|
|
|
|
|
|
return
|
|
|
|
elif self.status == 'identified-alice' and form.getType() == 'result':
|
|
|
|
try:
|
|
|
|
self.final_steps_alice(form)
|
2013-01-01 23:18:36 +01:00
|
|
|
except exceptions.NegotiationError as details:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.fail_bad_negotiation(details)
|
|
|
|
|
|
|
|
return
|
|
|
|
except exceptions.Cancelled:
|
|
|
|
# user cancelled the negotiation
|
|
|
|
|
|
|
|
self.reject_negotiation()
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
if form.getField('terminate') and\
|
|
|
|
form.getField('terminate').getValue() in ('1', 'true'):
|
|
|
|
self.acknowledge_termination()
|
|
|
|
|
|
|
|
self.conn.delete_session(str(self.jid), self.thread_id)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
# non-esession negotiation. this isn't very useful, but i'm keeping it
|
|
|
|
# around to test my test suite.
|
|
|
|
if form.getType() == 'form':
|
|
|
|
if not self.control:
|
2017-08-13 13:18:56 +02:00
|
|
|
jid, resource = app.get_room_and_nick_from_fjid(str(self.jid))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
account = self.conn.name
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.get_contact(account, str(self.jid),
|
2011-07-23 23:03:46 +02:00
|
|
|
resource)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if not contact:
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.create_contact(jid=jid, account=account,
|
2010-02-08 15:08:40 +01:00
|
|
|
resource=resource, show=self.conn.get_status())
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.new_chat(contact, account, resource=resource,
|
2010-02-08 15:08:40 +01:00
|
|
|
session=self)
|
|
|
|
|
2011-07-23 23:03:46 +02:00
|
|
|
negotiation.FeatureNegotiationWindow(account, str(self.jid), self,
|
|
|
|
form)
|