Dont save sent MessageStanza for LMC use

There are mutliple reasons why this is not a good idea

1. It places work on encryption Plugins, as many encryption attributes inside the
stanza can not be resend again (OMEMO, OTR), so the plugins have to make sure none of
these attr are inside the LMC stanza

2. In general its not obvious for plugin devs that a stanza issued after LMC has to be
treated differently. There should be no negative effects, even when a contributor not knowing
about LMC at all.

This commit saves only the stanza id, and adds the replace tag on the new message.
This results also in less code.
This commit is contained in:
Philipp Hörist 2017-06-02 01:29:41 +02:00
parent f803b544bc
commit ef8229615a
5 changed files with 29 additions and 59 deletions

View File

@ -931,7 +931,7 @@ class ChatControl(ChatControlBase):
self.print_conversation(message, self.contact.jid,
encrypted=encrypted, xep0184_id=xep0184_id, xhtml=xhtml,
displaymarking=displaymarking, msg_stanza_id=id_,
correct_id=msg_stanza.getTagAttr('replace', 'id'),
correct_id=obj.correct_id,
additional_data=obj.additional_data)
ChatControlBase.send_message(self, message, keyID, type_='chat',

View File

@ -752,21 +752,21 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
label = self.get_seclabel()
def _cb(obj, msg, cb, *cb_args):
self.last_sent_msg = msg
self.last_sent_msg = obj.msg_id
if cb:
cb(obj, msg, *cb_args)
if self.correcting and self.last_sent_msg:
correction_msg = self.last_sent_msg
correct_id = self.last_sent_msg
else:
correction_msg = None
correct_id = None
gajim.nec.push_outgoing_event(MessageOutgoingEvent(None,
account=self.account, jid=self.contact.jid, message=message,
keyID=keyID, type_=type_, chatstate=chatstate, msg_id=msg_id,
resource=resource, user_nick=self.user_nick, xhtml=xhtml,
label=label, callback=_cb, callback_args=[callback] + callback_args,
control=self, attention=attention, correction_msg=correction_msg,
control=self, attention=attention, correct_id=correct_id,
automatic_message=False, encryption=self.encryption))
# Record the history of sent messages

View File

@ -304,24 +304,6 @@ class CommonConnection:
else:
fjid = obj.get_full_jid()
if obj.correction_msg:
id_ = obj.correction_msg.getID()
if obj.correction_msg.getTag('replace'):
obj.correction_msg.delChild('replace')
obj.correction_msg.setTag('replace', attrs={'id': id_},
namespace=nbxmpp.NS_CORRECT)
id2 = self.connection.getAnID()
obj.correction_msg.setID(id2)
obj.correction_msg.setBody(obj.message)
if obj.xhtml:
obj.correction_msg.setXHTML(obj.xhtml)
if obj.session:
obj.session.last_send = time.time()
self._push_stanza_message_outgoing(obj, obj.correction_msg)
return
if obj.type_ == 'chat':
msg_iq = nbxmpp.Message(body=obj.message, typ=obj.type_,
xhtml=obj.xhtml)
@ -333,6 +315,10 @@ class CommonConnection:
msg_iq = nbxmpp.Message(body=obj.message, typ='normal',
xhtml=obj.xhtml)
if obj.correct_id:
msg_iq.setTag('replace', attrs={'id': obj.correct_id},
namespace=nbxmpp.NS_CORRECT)
if obj.msg_id:
msg_iq.setID(obj.msg_id)
@ -2637,39 +2623,25 @@ class Connection(CommonConnection, ConnectionHandlers):
if not gajim.account_is_connected(self.name):
return
if obj.correction_msg:
id_ = obj.correction_msg.getID()
if obj.correction_msg.getTag('replace'):
obj.correction_msg.delChild('replace')
obj.correction_msg.setTag('replace', attrs={'id': id_},
namespace=nbxmpp.NS_CORRECT)
id2 = self.connection.getAnID()
obj.correction_msg.setID(id2)
obj.correction_msg.setBody(obj.message)
if obj.xhtml:
obj.correction_msg.setXHTML(xhtml)
gajim.nec.push_incoming_event(GcStanzaMessageOutgoingEvent(
None, conn=self, automatic_message=obj.automatic_message,
jid=obj.jid, message=obj.message,
correction_msg=obj.correction_msg, additional_data=obj.additional_data))
if obj.callback:
obj.callback(obj.correction_msg, obj.message)
return
if not obj.xhtml and gajim.config.get('rst_formatting_outgoing_messages'):
from common.rst_xhtml_generator import create_xhtml
obj.xhtml = create_xhtml(obj.message)
msg_iq = nbxmpp.Message(obj.jid, obj.message, typ='groupchat',
xhtml=obj.xhtml)
if obj.correct_id:
msg_iq.setTag('replace', attrs={'id': obj.correct_id},
namespace=nbxmpp.NS_CORRECT)
if obj.chatstate:
msg_iq.setTag(obj.chatstate, namespace=nbxmpp.NS_CHATSTATES)
if obj.label is not None:
msg_iq.addChild(node=obj.label)
gajim.nec.push_incoming_event(GcStanzaMessageOutgoingEvent(
None, conn=self, msg_iq=msg_iq,
automatic_message=obj.automatic_message,
jid=obj.jid, message=obj.message, correction_msg=None, additional_data=obj.additional_data))
if obj.callback:
obj.callback(msg_iq, obj.message)
obj.msg_iq = msg_iq
obj.conn = self
gajim.nec.push_incoming_event(GcStanzaMessageOutgoingEvent(None, **vars(obj)))
def _nec_gc_stanza_message_outgoing(self, obj):
if obj.conn.name != self.name:
@ -2684,14 +2656,13 @@ class Connection(CommonConnection, ConnectionHandlers):
self.send_gc_message(obj)
def send_gc_message(self, obj):
if obj.correction_msg:
obj.msg_id = self.connection.send(obj.correction_msg)
else:
obj.msg_id = self.connection.send(obj.msg_iq)
obj.msg_id = self.connection.send(obj.msg_iq)
gajim.nec.push_incoming_event(MessageSentEvent(
None, conn=self, jid=obj.jid, message=obj.message, keyID=None,
chatstate=None, automatic_message=obj.automatic_message,
msg_id=obj.msg_id, additional_data=obj.additional_data))
if obj.callback:
obj.callback(obj)
def send_gc_subject(self, jid, subject):
if not gajim.account_is_connected(self.name):

View File

@ -2749,7 +2749,7 @@ class MessageOutgoingEvent(nec.NetworkOutgoingEvent):
self.is_loggable = True
self.control = None
self.attention = False
self.correction_msg = None
self.correct_id = None
self.automatic_message = True
self.encryption = ''
@ -2791,7 +2791,7 @@ class GcMessageOutgoingEvent(nec.NetworkOutgoingEvent):
self.callback_args = []
self.is_loggable = True
self.control = None
self.correction_msg = None
self.correct_id = None
self.automatic_message = True
def generate(self):

View File

@ -2035,24 +2035,23 @@ class GroupchatControl(ChatControlBase):
if message != '' or message != '\n':
self.save_message(message, 'sent')
def _cb(msg, msg_txt):
def _cb(obj):
# we'll save sent message text when we'll receive it in
# _nec_gc_message_received
self.last_sent_msg = msg
self.last_sent_msg = obj.msg_id
if self.correcting:
self.correcting = False
gtkgui_helpers.remove_css_class(
self.msg_textview, 'msgcorrectingcolor')
if self.correcting and self.last_sent_msg:
correction_msg = self.last_sent_msg
correct_id = self.last_sent_msg
else:
correction_msg = None
correct_id = None
# Send the message
gajim.nec.push_outgoing_event(GcMessageOutgoingEvent(None,
account=self.account, jid=self.room_jid, message=message,
xhtml=xhtml, label=label, callback=_cb,
callback_args=[_cb] + [message], correction_msg=correction_msg,
xhtml=xhtml, label=label, callback=_cb, correct_id=correct_id,
automatic_message=False))
self.msg_textview.get_buffer().set_text('')
self.msg_textview.grab_focus()