fix some archiving session negotiation bugs

print archving negotiation result in chat control
This commit is contained in:
Yann Leboulanger 2009-12-02 11:52:49 +01:00
parent 3d4688e9fa
commit 5a3ef285a5
5 changed files with 46 additions and 17 deletions

View File

@ -46,6 +46,7 @@ from common import exceptions
from message_control import MessageControl
from conversation_textview import ConversationTextview
from message_textview import MessageTextView
from common.stanza_session import EncryptedStanzaSession, ArchivingStanzaSession
from common.contacts import GC_Contact
from common.logger import constants
from common.pep import MOODS, ACTIVITIES
@ -1394,7 +1395,7 @@ class ChatControl(ChatControlBase):
self.session = session
if session.enable_encryption:
self.print_esession_details()
self.print_session_details()
# Enable encryption if needed
self.no_autonegotiation = False
@ -2055,6 +2056,17 @@ class ChatControl(ChatControlBase):
msg = _('Session negotiation cancelled')
ChatControlBase.print_conversation_line(self, msg, 'status', '', None)
def print_archiving_session_details(self):
"""
Print esession settings to textview
"""
archiving = bool(self.session) and self.session.archiving
if archiving:
msg = _('This session WILL be archived on server')
else:
msg = _('This session WILL NOT be archived on server')
ChatControlBase.print_conversation_line(self, msg, 'status', '', None)
def print_esession_details(self):
"""
Print esession settings to textview
@ -2079,6 +2091,12 @@ class ChatControl(ChatControlBase):
self._show_lock_image(e2e_is_active, 'E2E', e2e_is_active, self.session and \
self.session.is_loggable(), self.session and self.session.verified_identity)
def print_session_details(self):
if isinstance(self.session, EncryptedStanzaSession):
self.print_esession_details()
elif isinstance(self.session, ArchivingStanzaSession):
self.print_archiving_session_details()
def print_conversation(self, text, frm='', tim=None, encrypted=False,
subject=None, xhtml=None, simple=False, xep0184_id=None):
"""
@ -2511,7 +2529,7 @@ class ChatControl(ChatControlBase):
if want_e2e and not self.no_autonegotiation \
and gajim.HAVE_PYCRYPTO and self.contact.supports(NS_ESESSION):
self.begin_e2e_negotiation()
elif not self.session.accepted:
elif not self.session or not self.session.status:
self.begin_archiving_negotiation()
else:
self.send_chatstate('active', self.contact)

View File

@ -1297,10 +1297,7 @@ class ConnectionVcard:
count = 0
if count > index + nb:
# Request the next page
try:
after = int(element.getTagData('last'))
except TypeError:
after = index + nb
after = element.getTagData('last')
self.request_collection_page(with_, start_, after=after)
elif self.awaiting_answers[id_][0] == ARCHIVING_MODIFICATIONS_ARRIVED:

View File

@ -177,7 +177,7 @@ class StanzaSession(object):
class ArchivingStanzaSession(StanzaSession):
def __init__(self, conn, jid, thread_id, type_='chat'):
StanzaSession.__init__(self, conn, jid, thread_id, type_='chat')
self.accepted = False
self.archiving = False
def archiving_logging_preference(self, initiator_options=None):
return self.conn.logging_preference(self.jid, initiator_options)
@ -206,7 +206,7 @@ class ArchivingStanzaSession(StanzaSession):
feature.addChild(node=x)
self.status = 'requested'
self.status = 'requested-archiving'
self.send(request)
@ -229,7 +229,7 @@ class ArchivingStanzaSession(StanzaSession):
x.addChild(node=xmpp.DataField(name='logging', value=logging))
self.status = 'responded'
self.status = 'responded-archiving'
feature.addChild(node=x)
@ -250,7 +250,10 @@ class ArchivingStanzaSession(StanzaSession):
if self.negotiated['logging'] == 'mustnot':
self.loggable = False
print 'SESSION ACCEPTED', self.loggable
self.accepted = True
self.status = 'active'
self.archiving = True
if self.control:
self.control.print_archiving_session_details()
def accept_archiving_alice(self, form):
negotiated = {}
@ -278,7 +281,10 @@ class ArchivingStanzaSession(StanzaSession):
if self.negotiated['logging'] == 'mustnot':
self.loggable = False
print 'SESSION ACCEPTED', self.loggable
self.accepted = True
self.status = 'active'
self.archiving = True
if self.control:
self.control.print_archiving_session_details()
class EncryptedStanzaSession(ArchivingStanzaSession):
@ -307,7 +313,7 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
handle_session_negotiation method.
'''
def __init__(self, conn, jid, thread_id, type_='chat'):
StanzaSession.__init__(self, conn, jid, thread_id, type_='chat')
ArchivingStanzaSession.__init__(self, conn, jid, thread_id, type_='chat')
self.xes = {}
self.es = {}

View File

@ -30,6 +30,7 @@ import gtkgui_helpers
from common import gajim
from common import helpers
from common.stanza_session import EncryptedStanzaSession, ArchivingStanzaSession
# Derived types MUST register their type IDs here if custom behavor is required
TYPE_CHAT = 'chat'
@ -163,11 +164,16 @@ class MessageControl:
if self.resource:
jid += '/' + self.resource
crypto_changed = bool(session and session.enable_encryption) != \
crypto_changed = bool(session and isinstance(session,
EncryptedStanzaSession) and session.enable_encryption) != \
bool(oldsession and oldsession.enable_encryption)
if crypto_changed:
self.print_esession_details()
archiving_changed = bool(session and isinstance(session,
ArchivingStanzaSession) and session.archiving) != \
bool(oldsession and oldsession.archiving)
if crypto_changed or archiving_changed:
self.print_session_details()
def send_message(self, message, keyID='', type_='chat', chatstate=None,
msg_id=None, composing_xep=None, resource=None, user_nick=None, xhtml=None,

View File

@ -440,7 +440,8 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
return
elif self.status == 'requested' and form.getType() == 'submit':
elif self.status == 'requested-archiving' and form.getType() == \
'submit':
try:
self.accept_archiving_alice(form)
except exceptions.NegotiationError, details:
@ -481,7 +482,8 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
self.fail_bad_negotiation(details)
return
elif self.status == 'responded' and form.getType() == 'result':
elif self.status == 'responded-archiving' and form.getType() == \
'result':
try:
self.accept_archiving_bob(form)
except exceptions.NegotiationError, details: