* 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 self.private_storage_supported = True
if gajim.otr_module: if gajim.otr_module:
self.otr_userstates = gajim.otr_module.otrl_userstate_create() self.otr_userstates = \
gajim.otr_module.otrl_userstate_create()
# END __init__ # END __init__
def put_event(self, ev): def put_event(self, ev):

View file

@ -139,37 +139,47 @@ class MessageControl:
def send_message(self, message, keyID = '', type = 'chat', def send_message(self, message, keyID = '', type = 'chat',
chatstate = None, msg_id = None, composing_xep = None, resource = None, chatstate = None, msg_id = None, composing_xep = None, resource = None,
user_nick = 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 jid = self.contact.jid
original_message = message original_message = message
if gajim.otr_module: if gajim.otr_module and self.session.append_otr_tag:
if type == 'chat' and isinstance(message, unicode): if type == 'chat' and isinstance(message, unicode):
d = {'kwargs':{'keyID':keyID, 'type':type, d = {'kwargs': {'keyID': keyID, 'type': type,
'chatstate':chatstate, 'msg_id':msg_id, 'chatstate': chatstate,
'composing_xep':composing_xep, 'resource':self.resource, 'msg_id': msg_id,
'user_nick':user_nick, 'session':self.session, 'composing_xep': composing_xep,
'original_message':original_message}, 'account':self.account} '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( 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.otr_ui_ops, d),
gajim.get_jid_from_account(self.account).encode(), gajim.get_jid_from_account(
gajim.OTR_PROTO, self.contact.get_full_jid().encode(), self.account).encode(),
message.encode(), None, (gajim.otr_add_appdata, self.account)) 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( ctx = gajim.otr_module.otrl_context_find(
gajim.connections[self.account].otr_userstates, self.session.conn.otr_userstates,
self.contact.get_full_jid().encode(), self.contact.get_full_jid().encode(),
gajim.get_jid_from_account(self.account).encode(), gajim.get_jid_from_account(
gajim.OTR_PROTO, 1, (gajim.otr_add_appdata, self.account).encode(),
self.account))[0] 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_module.otrl_message_fragment_and_send(
(gajim.otr_ui_ops, d), (gajim.otr_ui_ops, d), ctx, new_msg,
context, new_msg, gajim.otr_module.OTRL_FRAGMENT_SEND_ALL) gajim.otr_module.OTRL_FRAGMENT_SEND_ALL)
return return
# Send and update history # 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') stanza_session.EncryptedStanzaSession.__init__(self, conn, jid, thread_id, type = 'chat')
self.control = None self.control = None
self.append_otr_tag = True
def acknowledge_termination(self): def acknowledge_termination(self):
# the other party terminated the session. we'll keep the control around, though. # the other party terminated the session. we'll keep the control around, though.
@ -151,6 +152,19 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
if msgtxt == '': if msgtxt == '':
return 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: else:
log_type = 'single_msg_recv' log_type = 'single_msg_recv'