Implement XEP-0359 Stable Stanza IDs
- This allows us to better deduplicate Messages on MAM syncs
This commit is contained in:
parent
8558a43651
commit
9bca51eb69
|
@ -1187,7 +1187,7 @@ class ChatControl(ChatControlBase):
|
|||
|
||||
gajim.nec.push_outgoing_event(MessageOutgoingEvent(None,
|
||||
account=self.account, jid=self.contact.jid, chatstate=state,
|
||||
msg_id=contact.msg_log_id, control=self))
|
||||
control=self))
|
||||
|
||||
contact.our_chatstate = state
|
||||
if state == 'active':
|
||||
|
|
|
@ -732,7 +732,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
|||
return label
|
||||
|
||||
def send_message(self, message, keyID='', type_='chat', chatstate=None,
|
||||
msg_id=None, resource=None, xhtml=None, callback=None, callback_args=None,
|
||||
resource=None, xhtml=None, callback=None, callback_args=None,
|
||||
process_commands=True, attention=False):
|
||||
"""
|
||||
Send the given message to the active tab. Doesn't return None if error
|
||||
|
@ -757,7 +757,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
|||
label = self.get_seclabel()
|
||||
|
||||
def _cb(obj, msg, cb, *cb_args):
|
||||
self.last_sent_msg = obj.msg_id
|
||||
self.last_sent_msg = obj.stanza_id
|
||||
if cb:
|
||||
cb(obj, msg, *cb_args)
|
||||
|
||||
|
@ -768,7 +768,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
|||
|
||||
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,
|
||||
keyID=keyID, type_=type_, chatstate=chatstate,
|
||||
resource=resource, user_nick=self.user_nick, xhtml=xhtml,
|
||||
label=label, callback=_cb, callback_args=[callback] + callback_args,
|
||||
control=self, attention=attention, correct_id=correct_id,
|
||||
|
|
|
@ -317,8 +317,11 @@ class CommonConnection:
|
|||
msg_iq.setTag('replace', attrs={'id': obj.correct_id},
|
||||
namespace=nbxmpp.NS_CORRECT)
|
||||
|
||||
if obj.msg_id:
|
||||
msg_iq.setID(obj.msg_id)
|
||||
# XEP-0359
|
||||
obj.stanza_id = self.connection.getAnID()
|
||||
msg_iq.setID(obj.stanza_id)
|
||||
if obj.message:
|
||||
msg_iq.setOriginID(obj.stanza_id)
|
||||
|
||||
if obj.form_node:
|
||||
msg_iq.addChild(node=obj.form_node)
|
||||
|
@ -2056,12 +2059,12 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
self.send_message(obj)
|
||||
|
||||
def send_message(self, obj):
|
||||
obj.msg_id = self.connection.send(obj.msg_iq, now=obj.now)
|
||||
obj.stanza_id = self.connection.send(obj.msg_iq, now=obj.now)
|
||||
|
||||
gajim.nec.push_incoming_event(MessageSentEvent(
|
||||
None, conn=self, jid=obj.jid, message=obj.message, keyID=obj.keyID,
|
||||
chatstate=obj.chatstate, automatic_message=obj.automatic_message,
|
||||
msg_id=obj.msg_id, additional_data=obj.additional_data))
|
||||
stanza_id=obj.stanza_id, additional_data=obj.additional_data))
|
||||
if obj.callback:
|
||||
obj.callback(obj, obj.msg_iq, *obj.callback_args)
|
||||
|
||||
|
@ -2628,6 +2631,11 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
msg_iq = nbxmpp.Message(obj.jid, obj.message, typ='groupchat',
|
||||
xhtml=obj.xhtml)
|
||||
|
||||
obj.stanza_id = self.connection.getAnID()
|
||||
msg_iq.setID(obj.stanza_id)
|
||||
if obj.message:
|
||||
msg_iq.setOriginID(obj.stanza_id)
|
||||
|
||||
if obj.correct_id:
|
||||
msg_iq.setTag('replace', attrs={'id': obj.correct_id},
|
||||
namespace=nbxmpp.NS_CORRECT)
|
||||
|
@ -2654,11 +2662,11 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
self.send_gc_message(obj)
|
||||
|
||||
def send_gc_message(self, obj):
|
||||
obj.msg_id = self.connection.send(obj.msg_iq)
|
||||
obj.stanza_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))
|
||||
stanza_id=obj.stanza_id, additional_data=obj.additional_data))
|
||||
if obj.callback:
|
||||
obj.callback(obj)
|
||||
|
||||
|
|
|
@ -1637,7 +1637,7 @@ class MessageSentEvent(nec.NetworkIncomingEvent):
|
|||
|
||||
def generate(self):
|
||||
if not self.automatic_message:
|
||||
self.conn.sent_message_ids.append(self.msg_id)
|
||||
self.conn.sent_message_ids.append(self.stanza_id)
|
||||
# only record the last 20000 message ids (should be about 1MB [36 byte per uuid]
|
||||
# and about 24 hours if you send out a message every 5 seconds)
|
||||
self.conn.sent_message_ids = self.conn.sent_message_ids[-20000:]
|
||||
|
@ -2709,7 +2709,7 @@ class MessageOutgoingEvent(nec.NetworkOutgoingEvent):
|
|||
self.type_ = 'chat'
|
||||
self.subject = ''
|
||||
self.chatstate = None
|
||||
self.msg_id = None
|
||||
self.stanza_id = None
|
||||
self.resource = None
|
||||
self.user_nick = None
|
||||
self.xhtml = None
|
||||
|
@ -2762,6 +2762,7 @@ class GcMessageOutgoingEvent(nec.NetworkOutgoingEvent):
|
|||
self.message = ''
|
||||
self.chatstate = None
|
||||
self.xhtml = None
|
||||
self.stanza_id = None
|
||||
self.label = None
|
||||
self.callback = None
|
||||
self.callback_args = []
|
||||
|
|
|
@ -334,11 +334,11 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
|||
|
||||
def _nec_stanza_message_outgoing(self, obj):
|
||||
|
||||
def on_send_ok(msg_id):
|
||||
def on_send_ok(stanza_id):
|
||||
gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
|
||||
jid=obj.jid, message=obj.message, keyID=obj.keyID,
|
||||
automatic_message=obj.automatic_message, chatstate=None,
|
||||
msg_id=msg_id))
|
||||
stanza_id=stanza_id))
|
||||
if obj.callback:
|
||||
obj.callback(obj.msg_iq, *obj.callback_args)
|
||||
|
||||
|
|
|
@ -2042,7 +2042,7 @@ class GroupchatControl(ChatControlBase):
|
|||
def _cb(obj):
|
||||
# we'll save sent message text when we'll receive it in
|
||||
# _nec_gc_message_received
|
||||
self.last_sent_msg = obj.msg_id
|
||||
self.last_sent_msg = obj.stanza_id
|
||||
if self.correcting:
|
||||
self.correcting = False
|
||||
gtkgui_helpers.remove_css_class(
|
||||
|
|
Loading…
Reference in New Issue