don't show delivery error messages for automatic message stanzas. Fixes #8222
This commit is contained in:
parent
9fbd7efa2a
commit
0e80db2be6
4 changed files with 58 additions and 23 deletions
|
@ -808,7 +808,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
|||
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, correction_msg=correction_msg, automatic_message=False))
|
||||
|
||||
# Record the history of sent messages
|
||||
self.save_message(message, 'sent')
|
||||
|
|
|
@ -2135,17 +2135,42 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
if obj.account != self.name:
|
||||
return
|
||||
|
||||
# parameters of this function are packet into _cb_parameters for later usage in _nec_stanza_message_outgoing's cb()
|
||||
def cb(jid, msg, keyID, forward_from, session, original_message,
|
||||
subject, type_, msg_iq, xhtml):
|
||||
if isinstance(msg_iq, list):
|
||||
for iq in msg_iq:
|
||||
gajim.nec.push_incoming_event(StanzaMessageOutgoingEvent(
|
||||
None, conn=self, msg_iq=iq, now=obj.now))
|
||||
None, conn=self, msg_iq=iq, now=obj.now, automatic_message=obj.automatic_message,
|
||||
_cb_parameters={"jid":jid, "msg":msg, "keyID":keyID, "forward_from":forward_from,
|
||||
"session":session, "original_message":original_message, "subject":subject, "type_":type_,
|
||||
"msg_iq":msg_iq, "xhtml":xhtml, "obj":obj}))
|
||||
else:
|
||||
gajim.nec.push_incoming_event(StanzaMessageOutgoingEvent(None,
|
||||
conn=self, msg_iq=msg_iq, now=obj.now))
|
||||
conn=self, msg_iq=msg_iq, now=obj.now, automatic_message=obj.automatic_message,
|
||||
_cb_parameters={"jid":jid, "msg":msg, "keyID":keyID, "forward_from":forward_from,
|
||||
"session":session, "original_message":original_message, "subject":subject, "type_":type_,
|
||||
"msg_iq":msg_iq, "xhtml":xhtml, "obj":obj}))
|
||||
|
||||
self._prepare_message(obj.jid, obj.message, obj.keyID, type_=obj.type_,
|
||||
subject=obj.subject, chatstate=obj.chatstate, msg_id=obj.msg_id,
|
||||
resource=obj.resource, user_nick=obj.user_nick, xhtml=obj.xhtml,
|
||||
label=obj.label, session=obj.session, forward_from=obj.forward_from,
|
||||
form_node=obj.form_node, original_message=obj.original_message,
|
||||
delayed=obj.delayed, attention=obj.attention,
|
||||
correction_msg=obj.correction_msg, callback=cb)
|
||||
|
||||
def _nec_stanza_message_outgoing(self, obj):
|
||||
if obj.conn.name != self.name:
|
||||
return
|
||||
obj.msg_id = self.connection.send(obj.msg_iq, now=obj.now)
|
||||
|
||||
# obj in this function is the obj as seen in _nec_message_outgoing()
|
||||
def cb(obj, jid, msg, keyID, forward_from, session, original_message,
|
||||
subject, type_, msg_iq, xhtml, msg_id):
|
||||
gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
|
||||
jid=jid, message=msg, keyID=keyID, chatstate=obj.chatstate))
|
||||
jid=jid, message=msg, keyID=keyID, chatstate=obj.chatstate,
|
||||
automatic_message=obj.automatic_message, msg_id=msg_id))
|
||||
if obj.callback:
|
||||
obj.callback(msg_iq, *obj.callback_args)
|
||||
|
||||
|
@ -2160,19 +2185,8 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
else:
|
||||
self.log_message(jid, msg, forward_from, session,
|
||||
original_message, subject, type_, xhtml)
|
||||
|
||||
self._prepare_message(obj.jid, obj.message, obj.keyID, type_=obj.type_,
|
||||
subject=obj.subject, chatstate=obj.chatstate, msg_id=obj.msg_id,
|
||||
resource=obj.resource, user_nick=obj.user_nick, xhtml=obj.xhtml,
|
||||
label=obj.label, session=obj.session, forward_from=obj.forward_from,
|
||||
form_node=obj.form_node, original_message=obj.original_message,
|
||||
delayed=obj.delayed, attention=obj.attention,
|
||||
correction_msg=obj.correction_msg, callback=cb)
|
||||
|
||||
def _nec_stanza_message_outgoing(self, obj):
|
||||
if obj.conn.name != self.name:
|
||||
return
|
||||
obj.msg_id = self.connection.send(obj.msg_iq, now=obj.now)
|
||||
|
||||
cb(msg_id=obj.msg_id, **obj._cb_parameters)
|
||||
|
||||
def send_contacts(self, contacts, fjid, type_='message'):
|
||||
"""
|
||||
|
@ -2728,9 +2742,10 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
obj.correction_msg.setBody(obj.message)
|
||||
if obj.xhtml:
|
||||
obj.correction_msg.setXHTML(xhtml)
|
||||
self.connection.send(obj.correction_msg)
|
||||
obj.msg_id = self.connection.send(obj.correction_msg)
|
||||
gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
|
||||
jid=obj.jid, message=obj.message, keyID=None, chatstate=None))
|
||||
jid=obj.jid, message=obj.message, keyID=None, chatstate=None,
|
||||
automatic_message=obj.automatic_message, msg_id=obj.msg_id))
|
||||
if obj.callback:
|
||||
obj.callback(obj.correction_msg, obj.message)
|
||||
return
|
||||
|
@ -2741,9 +2756,10 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
xhtml=obj.xhtml)
|
||||
if obj.label is not None:
|
||||
msg_iq.addChild(node=label)
|
||||
self.connection.send(msg_iq)
|
||||
obj.msg_id = self.connection.send(msg_iq)
|
||||
gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
|
||||
jid=obj.jid, message=obj.message, keyID=None, chatstate=None))
|
||||
jid=obj.jid, message=obj.message, keyID=None, chatstate=None,
|
||||
automatic_message=obj.automatic_message, msg_id=obj.msg_id))
|
||||
if obj.callback:
|
||||
obj.callback(msg_iq, obj.message)
|
||||
|
||||
|
|
|
@ -1235,7 +1235,7 @@ class ConnectionHandlersBase:
|
|||
self.dispatch('DB_ERROR', (pritext, sectext))
|
||||
gajim.nec.push_incoming_event(MessageErrorEvent(None, conn=self,
|
||||
fjid=frm, error_code=msg.getErrorCode(), error_msg=error_msg,
|
||||
msg=msgtxt, time_=tim, session=session))
|
||||
msg=msgtxt, time_=tim, session=session, stanza=msg))
|
||||
|
||||
def _LastResultCB(self, con, iq_obj):
|
||||
log.debug('LastResultCB')
|
||||
|
@ -1423,6 +1423,8 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream):
|
|||
# ID of urn:xmpp:ping requests
|
||||
self.awaiting_xmpp_ping_id = None
|
||||
self.continue_connect_info = None
|
||||
# IDs of sent messages (https://trac.gajim.org/ticket/8222)
|
||||
self.sent_message_ids = []
|
||||
|
||||
try:
|
||||
self.sleeper = common.sleepy.Sleepy()
|
||||
|
|
|
@ -1580,14 +1580,30 @@ class GcConfigChangedReceivedEvent(nec.NetworkIncomingEvent):
|
|||
class MessageSentEvent(nec.NetworkIncomingEvent):
|
||||
name = 'message-sent'
|
||||
base_network_events = []
|
||||
|
||||
def generate(self):
|
||||
if not self.automatic_message:
|
||||
self.conn.sent_message_ids.append(self.msg_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:]
|
||||
return True
|
||||
|
||||
class MessageNotSentEvent(nec.NetworkIncomingEvent):
|
||||
name = 'message-not-sent'
|
||||
base_network_events = []
|
||||
|
||||
class MessageErrorEvent(nec.NetworkIncomingEvent):
|
||||
class MessageErrorEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||
name = 'message-error'
|
||||
base_network_events = []
|
||||
|
||||
def generate(self):
|
||||
self.get_id()
|
||||
#only alert for errors of explicitly sent messages (see https://trac.gajim.org/ticket/8222)
|
||||
if self.id_ in self.conn.sent_message_ids:
|
||||
self.conn.sent_message_ids.remove(self.id_)
|
||||
return True
|
||||
return False
|
||||
|
||||
class AnonymousAuthEvent(nec.NetworkIncomingEvent):
|
||||
name = 'anonymous-auth'
|
||||
|
@ -2622,6 +2638,7 @@ class MessageOutgoingEvent(nec.NetworkOutgoingEvent):
|
|||
self.control = None
|
||||
self.attention = False
|
||||
self.correction_msg = None
|
||||
self.automatic_message = True
|
||||
|
||||
def generate(self):
|
||||
return True
|
||||
|
|
Loading…
Add table
Reference in a new issue