* When we receive a plaintext, non-tagged message, don't append OTR

tag to outgoing messages anymore. Messages are not even passed to
  libotr anymore then.
* If we don't support OTR, strip OTR tags from the message before
  displaying it.
This commit is contained in:
js 2008-05-19 17:41:51 +00:00
parent 0deebd859d
commit 1cbe5678da
3 changed files with 47 additions and 22 deletions

View File

@ -167,7 +167,8 @@ class Connection(ConnectionHandlers):
self.private_storage_supported = True
if gajim.otr_module:
self.otr_userstates = gajim.otr_module.otrl_userstate_create()
self.otr_userstates = \
gajim.otr_module.otrl_userstate_create()
# END __init__
def put_event(self, ev):

View File

@ -139,37 +139,47 @@ class MessageControl:
def send_message(self, message, keyID = '', type = 'chat',
chatstate = None, msg_id = None, composing_xep = None, resource = None,
user_nick = None):
'''Send the given message to the active tab. Doesn't return None if error
'''
# Send the given message to the active tab.
# Doesn't return None if error
jid = self.contact.jid
original_message = message
if gajim.otr_module:
if gajim.otr_module and self.session.append_otr_tag:
if type == 'chat' and isinstance(message, unicode):
d = {'kwargs':{'keyID':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}, 'account':self.account}
d = {'kwargs': {'keyID': 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},
'account': self.account}
new_msg = gajim.otr_module.otrl_message_sending(
gajim.connections[self.account].otr_userstates,
self.session.conn.otr_userstates,
(gajim.otr_ui_ops, d),
gajim.get_jid_from_account(self.account).encode(),
gajim.OTR_PROTO, self.contact.get_full_jid().encode(),
message.encode(), None, (gajim.otr_add_appdata, self.account))
gajim.get_jid_from_account(
self.account).encode(),
gajim.OTR_PROTO,
self.contact.get_full_jid().encode(),
message.encode(), None,
(gajim.otr_add_appdata, self.account))
context = gajim.otr_module.otrl_context_find(
gajim.connections[self.account].otr_userstates,
self.contact.get_full_jid().encode(),
gajim.get_jid_from_account(self.account).encode(),
gajim.OTR_PROTO, 1, (gajim.otr_add_appdata,
self.account))[0]
ctx = gajim.otr_module.otrl_context_find(
self.session.conn.otr_userstates,
self.contact.get_full_jid().encode(),
gajim.get_jid_from_account(
self.account).encode(),
gajim.OTR_PROTO, 1,
(gajim.otr_add_appdata,
self.account))[0]
# we send all because inject_message can filter on HTML stuff then
# we send all because inject_message can filter
# on HTML stuff then
gajim.otr_module.otrl_message_fragment_and_send(
(gajim.otr_ui_ops, d),
context, new_msg, gajim.otr_module.OTRL_FRAGMENT_SEND_ALL)
(gajim.otr_ui_ops, d), ctx, new_msg,
gajim.otr_module.OTRL_FRAGMENT_SEND_ALL)
return
# Send and update history

View File

@ -18,6 +18,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
stanza_session.EncryptedStanzaSession.__init__(self, conn, jid, thread_id, type = 'chat')
self.control = None
self.append_otr_tag = True
def acknowledge_termination(self):
# the other party terminated the session. we'll keep the control around, though.
@ -151,6 +152,19 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
if msgtxt == '':
return
else:
self.append_otr_tag = False
# We're also here if we just don't support OTR.
# Thus, we should strip the tags from plaintext
# messages since they look ugly.
msgtxt = msgtxt.replace('\x20\x09\x20\x20\x09' \
'\x09\x09\x09\x20\x09\x20\x09\x20\x09' \
'\x20\x20', '')
msgtxt = msgtxt.replace('\x20\x09\x20\x09\x20' \
'\x20\x09\x20', '')
msgtxt = msgtxt.replace('\x20\x20\x09\x09\x20' \
'\x20\x09\x20', '')
else:
log_type = 'single_msg_recv'