parent
1f975df8a4
commit
42c1909d3b
|
@ -49,61 +49,5 @@ class Carbons:
|
||||||
log.warning('Carbons deactivated (user setting)')
|
log.warning('Carbons deactivated (user setting)')
|
||||||
|
|
||||||
|
|
||||||
def parse_carbon(con, stanza):
|
|
||||||
carbon = stanza.getTag(
|
|
||||||
'received', namespace=nbxmpp.NS_CARBONS, protocol=True)
|
|
||||||
if carbon is None:
|
|
||||||
carbon = stanza.getTag(
|
|
||||||
'sent', namespace=nbxmpp.NS_CARBONS, protocol=True)
|
|
||||||
if carbon is None:
|
|
||||||
return stanza, False, False
|
|
||||||
|
|
||||||
# Carbon must be from our bare jid
|
|
||||||
own_jid = con.get_own_jid()
|
|
||||||
if not stanza.getFrom().bareMatch(own_jid):
|
|
||||||
log.warning('Ignore message because from is invalid %s',
|
|
||||||
stanza.getFrom())
|
|
||||||
raise nbxmpp.NodeProcessed
|
|
||||||
|
|
||||||
forwarded = carbon.getTag('forwarded',
|
|
||||||
namespace=nbxmpp.NS_FORWARD,
|
|
||||||
protocol=True)
|
|
||||||
message = forwarded.getTag('message', protocol=True)
|
|
||||||
|
|
||||||
type_ = carbon.getName()
|
|
||||||
to = message.getTo()
|
|
||||||
frm = message.getFrom()
|
|
||||||
log.info('Received type: %s, from: %s', type_, frm)
|
|
||||||
|
|
||||||
if type_ == 'received':
|
|
||||||
sent = False
|
|
||||||
if message.getFrom().bareMatch(own_jid):
|
|
||||||
# Drop 'received' Carbons from ourself, we already
|
|
||||||
# got the message with the 'sent' Carbon or via the
|
|
||||||
# message itself
|
|
||||||
log.info('Drop "received"-Carbon from ourself: %s')
|
|
||||||
raise nbxmpp.NodeProcessed
|
|
||||||
if message.getTag('x', namespace=nbxmpp.NS_MUC_USER) is not None:
|
|
||||||
# A MUC broadcasts messages sent to us to all resources
|
|
||||||
# there is no need to process carbons for these messages
|
|
||||||
log.info('Drop MUC-PM "received"-Carbon')
|
|
||||||
raise nbxmpp.NodeProcessed
|
|
||||||
|
|
||||||
elif type_ == 'sent':
|
|
||||||
if frm is None:
|
|
||||||
frm = own_jid.getStripped()
|
|
||||||
message.setTo(frm)
|
|
||||||
if to is None:
|
|
||||||
to = own_jid.getStripped()
|
|
||||||
message.setFrom(to)
|
|
||||||
sent = True
|
|
||||||
|
|
||||||
else:
|
|
||||||
log.warning('Ignore invalid carbon: %s', stanza)
|
|
||||||
raise nbxmpp.NodeProcessed
|
|
||||||
|
|
||||||
return message, sent, True
|
|
||||||
|
|
||||||
|
|
||||||
def get_instance(*args, **kwargs):
|
def get_instance(*args, **kwargs):
|
||||||
return Carbons(*args, **kwargs), 'Carbons'
|
return Carbons(*args, **kwargs), 'Carbons'
|
||||||
|
|
|
@ -27,7 +27,6 @@ from gajim.common.nec import NetworkEvent
|
||||||
from gajim.common.helpers import AdditionalDataDict
|
from gajim.common.helpers import AdditionalDataDict
|
||||||
from gajim.common.modules.security_labels import parse_securitylabel
|
from gajim.common.modules.security_labels import parse_securitylabel
|
||||||
from gajim.common.modules.user_nickname import parse_nickname
|
from gajim.common.modules.user_nickname import parse_nickname
|
||||||
from gajim.common.modules.carbons import parse_carbon
|
|
||||||
from gajim.common.modules.misc import parse_delay
|
from gajim.common.modules.misc import parse_delay
|
||||||
from gajim.common.modules.misc import parse_eme
|
from gajim.common.modules.misc import parse_eme
|
||||||
from gajim.common.modules.misc import parse_correction
|
from gajim.common.modules.misc import parse_correction
|
||||||
|
@ -60,24 +59,7 @@ class Message:
|
||||||
nbxmpp.NS_IBB,
|
nbxmpp.NS_IBB,
|
||||||
nbxmpp.NS_CAPTCHA,])
|
nbxmpp.NS_CAPTCHA,])
|
||||||
|
|
||||||
def _message_received(self, _con, stanza):
|
def _message_received(self, _con, stanza, properties):
|
||||||
# https://tools.ietf.org/html/rfc6120#section-8.1.1.1
|
|
||||||
# If the stanza does not include a 'to' address then the client MUST
|
|
||||||
# treat it as if the 'to' address were included with a value of the
|
|
||||||
# client's full JID.
|
|
||||||
#
|
|
||||||
# Implementation Note: However, if the client does
|
|
||||||
# check the 'to' address then it is suggested to check at most the
|
|
||||||
# bare JID portion (not the full JID)
|
|
||||||
|
|
||||||
own_jid = self._con.get_own_jid().getStripped()
|
|
||||||
to = stanza.getTo()
|
|
||||||
if to is None:
|
|
||||||
stanza.setTo(own_jid)
|
|
||||||
elif not to.bareMatch(own_jid):
|
|
||||||
log.warning('Message addressed to someone else: %s', stanza)
|
|
||||||
raise nbxmpp.NodeProcessed
|
|
||||||
|
|
||||||
# Check if a child of the message contains any
|
# Check if a child of the message contains any
|
||||||
# namespaces that we handle in other modules.
|
# namespaces that we handle in other modules.
|
||||||
# nbxmpp executes less common handlers last
|
# nbxmpp executes less common handlers last
|
||||||
|
@ -98,20 +80,19 @@ class Message:
|
||||||
stanza=stanza,
|
stanza=stanza,
|
||||||
account=self._account))
|
account=self._account))
|
||||||
|
|
||||||
if stanza.getFrom() == self._con.get_own_jid(warn=True):
|
forwarded = properties.carbon_type is not None
|
||||||
# Drop messages sent from our own full jid
|
sent = properties.carbon_type == 'sent'
|
||||||
# It can happen that when we sent message to our own bare jid
|
if sent:
|
||||||
# that the server routes that message back to us
|
# Ugly, we treat the from attr as the remote jid,
|
||||||
log.info('Received message from self: %s, message is dropped',
|
# to make that work with sent carbons we have to do this.
|
||||||
stanza.getFrom())
|
# TODO: Check where in Gajim and plugins we depend on that behavior
|
||||||
return
|
stanza.setFrom(stanza.getTo().getBare())
|
||||||
|
|
||||||
stanza, sent, forwarded = parse_carbon(self._con, stanza)
|
|
||||||
|
|
||||||
from_ = stanza.getFrom()
|
from_ = stanza.getFrom()
|
||||||
type_ = stanza.getType()
|
type_ = stanza.getType()
|
||||||
if type_ is None:
|
if type_ is None:
|
||||||
type_ = 'normal'
|
type_ = 'normal'
|
||||||
|
|
||||||
self_message = is_self_message(stanza, type_ == 'groupchat')
|
self_message = is_self_message(stanza, type_ == 'groupchat')
|
||||||
muc_pm = is_muc_pm(stanza, from_, type_ == 'groupchat')
|
muc_pm = is_muc_pm(stanza, from_, type_ == 'groupchat')
|
||||||
|
|
||||||
|
@ -138,7 +119,7 @@ class Message:
|
||||||
if type_ == 'groupchat':
|
if type_ == 'groupchat':
|
||||||
archive_jid = stanza.getFrom().getStripped()
|
archive_jid = stanza.getFrom().getStripped()
|
||||||
else:
|
else:
|
||||||
archive_jid = own_jid
|
archive_jid = self._con.get_own_jid().getStripped()
|
||||||
if app.logger.find_stanza_id(self._account,
|
if app.logger.find_stanza_id(self._account,
|
||||||
archive_jid,
|
archive_jid,
|
||||||
stanza_id,
|
stanza_id,
|
||||||
|
|
Loading…
Reference in New Issue