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

View file

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