Display outgoing messages

This commit is contained in:
Bohdan Horbeshko 2022-11-15 03:15:52 +02:00
parent 75cc62153c
commit 7c6d87080c
2 changed files with 19 additions and 9 deletions

27
otr.py
View file

@ -20,9 +20,9 @@ import string
import random
import itertools
import logging
from inspect import signature
from gajim.common import const, app, helpers, configpaths
from gajim.common.const import EncryptionData
from gajim.common.structs import OutgoingMessage
from nbxmpp.protocol import Message, JID
import pathlib
@ -51,8 +51,8 @@ class OTRChannel(context.Context):
# print some text to chat window
def printl(self,line):
println = self.user.getControl(self.peer) and self.user.getControl(self.peer).conv_textview.print_conversation_line
println and println("OTR: "+line,kind='status',name='',tim='',**('jid' in signature(println).parameters and {'jid':None} or {}))
control = app.window.get_control()
control and control.add_message("OTR: "+line,kind='status',tim=0.0)
@staticmethod
def getPolicy(policy): return OTR.DEFAULT_POLICY.get(policy)
@ -98,8 +98,7 @@ class OTR(context.Account):
# get chat control
def getControl(self,peer):
ctl = app.interface.msg_win_mgr.get_control(peer.getStripped(),self.account)
return ctl
return app.window.get_control()
# get OTR context (encrypted dialog between Alice and Bob)
def getContext(self,peer):
@ -107,6 +106,18 @@ class OTR(context.Account):
self.ctxs[peer] = self.ctxs.get(peer) or OTRChannel(self,peer)
return self.ctxs[peer]
# factory for Gajim 1.4+
def makeOutgoingMessage(self,message,control,peer):
contact = control.client.get_module('Contacts').get_contact(peer, groupchat=False)
chatstate = control.client.get_module('Chatstate').get_active_chatstate(contact)
return OutgoingMessage(account=self.account,
contact=contact,
message=message,
type_='chat',
chatstate=chatstate,
label=None,
correct_id=None)
# load my private key
def loadPrivkey(self):
my = self.keystore.load(jid=str(self.jid))
@ -139,13 +150,13 @@ class OTR(context.Account):
stanza.setBody(text and text.decode() or "")
properties.encrypted = EncryptionData({'name': OTR.ENCRYPTION_NAME})
finally:
if channel.mayRetransmit and channel.state and ctl: channel.mayRetransmit = ctl.send_message(channel.lastMessage.decode())
if channel.mayRetransmit and channel.state and ctl: channel.mayRetransmit = ctl.client.send_message(self.makeOutgoingMessage(channel.lastMessage.decode(), ctl, peer))
# encrypt message
def encrypt(self,event,callback):
peer = event.msg_iq.getTo().new_as_bare()
channel, ctl = self.getContext(peer), event.control
if event.xhtml: return ctl.send_message(event.message) # skip xhtml messages
channel, ctl = self.getContext(peer), self.getControl(peer)
if event.xhtml: return ctl.client.send_message(self.makeOutgoingMessage(event.message, ctl, peer)) # skip xhtml messages
try:
encrypted = channel.sendMessage(context.FRAGMENT_SEND_ALL_BUT_LAST,event.message.encode(),appdata=event.msg_iq.getThread()) or b''
message = (encrypted != self.getDefaultQueryMessage(OTR.DEFAULT_POLICY.get)) and event.message or ""

View file

@ -22,7 +22,6 @@ ERROR = None
import logging
from gajim.plugins import GajimPlugin
from gajim.common import app
from gajim.common.modules.contacts import BareContact
from gajim.gtk.util import make_menu_item
from gi.repository import Gtk, Gio