Philipp Hörist pushed to branch master at gajim / gajim
Commits: 2126d430 by Philipp Hörist at 2017-05-01T17:23:46+02:00 Extend method to return our own full jid
- - - - - e02798dc by Philipp Hörist at 2017-05-01T17:52:19+02:00 Dont send chatstates to own resources
- - - - - c49d13bc by Philipp Hörist at 2017-05-01T17:58:55+02:00 Use BareJID when sending message to ourself
- - - - - 33a584b8 by Philipp Hörist at 2017-05-01T19:08:11+02:00 Dont use message receipts in message to ourself
- - - - - d346333d by Philipp Hörist at 2017-05-01T19:08:19+02:00 Drop some message from ourself
- 'received'-Carbons from ourself, because we either received the message directly or got a 'sent'-Carbon about it - Messages from our own full jid, this can happen when we send a Message to ourself and no other resource is online.
- - - - -
8 changed files:
- src/chat_control.py - src/chat_control_base.py - src/common/connection.py - src/common/connection_handlers.py - src/common/connection_handlers_events.py - src/common/gajim.py - src/message_control.py - src/roster_window.py
Changes:
===================================== src/chat_control.py ===================================== --- a/src/chat_control.py +++ b/src/chat_control.py @@ -978,11 +978,11 @@ class ChatControl(ChatControlBase):
def _on_sent(obj, msg_stanza, message, encrypted, xhtml, label): id_ = msg_stanza.getID() - if self.contact.supports(NS_RECEIPTS) and gajim.config.get_per( - 'accounts', self.account, 'request_receipt'): - xep0184_id = id_ - else: - xep0184_id = None + xep0184_id = None + if self.contact.jid != gajim.get_jid_from_account(self.account): + if self.contact.supports(NS_RECEIPTS) and gajim.config.get_per( + 'accounts', self.account, 'request_receipt'): + xep0184_id = id_ if label: displaymarking = label.getTag('displaymarking') else: @@ -1233,6 +1233,9 @@ class ChatControl(ChatControlBase): if contact and contact.sub in ('to', 'none'): return
+ if self.contact.jid == gajim.get_jid_from_account(self.account): + return + elif chatstate_setting == 'composing_only' and state != 'active' and\ state != 'composing': return
===================================== src/chat_control_base.py ===================================== --- a/src/chat_control_base.py +++ b/src/chat_control_base.py @@ -701,7 +701,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): # refresh timers self.reset_kbd_mouse_timeout_vars()
- if gajim.config.get('outgoing_chat_state_notifications') == 'disabled': + notifications = gajim.config.get('outgoing_chat_state_notifications') + if (self.contact.jid == gajim.get_jid_from_account(self.account) or + notifications == 'disabled'): chatstate = None
label = self.get_seclabel()
===================================== src/common/connection.py ===================================== --- a/src/common/connection.py +++ b/src/common/connection.py @@ -355,7 +355,10 @@ class CommonConnection: else: msgtxt = obj.message
- fjid = obj.get_full_jid() + if obj.jid == gajim.get_jid_from_account(self.name): + fjid = obj.jid + else: + fjid = obj.get_full_jid()
if obj.correction_msg: id_ = obj.correction_msg.getID() @@ -464,10 +467,11 @@ class CommonConnection: namespace=nbxmpp.NS_MSG_HINTS)
# XEP-0184 - if msgtxt and gajim.config.get_per('accounts', self.name, - 'request_receipt') and contact and contact.supports( - nbxmpp.NS_RECEIPTS): - msg_iq.setTag('request', namespace=nbxmpp.NS_RECEIPTS) + if obj.jid != gajim.get_jid_from_account(self.name): + if msgtxt and gajim.config.get_per('accounts', self.name, + 'request_receipt') and contact and contact.supports( + nbxmpp.NS_RECEIPTS): + msg_iq.setTag('request', namespace=nbxmpp.NS_RECEIPTS)
if obj.forward_from: addresses = msg_iq.addChild('addresses',
===================================== src/common/connection_handlers.py ===================================== --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1174,17 +1174,19 @@ class ConnectionHandlersBase: jid_to = gajim.get_jid_without_resource(fjid_to) if jid_to == gajim.get_jid_from_account(self.name): reply = True - if obj.receipt_request_tag and gajim.config.get_per('accounts', - self.name, 'answer_receipts') and ((contact and contact.sub \ - not in ('to', 'none')) or gc_contact) and obj.mtype != 'error' and \ - reply: - receipt = nbxmpp.Message(to=obj.fjid, typ='chat') - receipt.setTag('received', namespace='urn:xmpp:receipts', - attrs={'id': obj.id_}) - - if obj.thread_id: - receipt.setThread(obj.thread_id) - self.connection.send(receipt) + + if obj.jid != gajim.get_jid_from_account(self.name): + if obj.receipt_request_tag and gajim.config.get_per('accounts', + self.name, 'answer_receipts') and ((contact and contact.sub \ + not in ('to', 'none')) or gc_contact) and obj.mtype != 'error' and \ + reply: + receipt = nbxmpp.Message(to=obj.fjid, typ='chat') + receipt.setTag('received', namespace='urn:xmpp:receipts', + attrs={'id': obj.id_}) + + if obj.thread_id: + receipt.setThread(obj.thread_id) + self.connection.send(receipt)
# We got our message's receipt if obj.receipt_received_tag and gajim.config.get_per('accounts',
===================================== src/common/connection_handlers_events.py ===================================== --- a/src/common/connection_handlers_events.py +++ b/src/common/connection_handlers_events.py @@ -1124,6 +1124,15 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): self.sent = False account = self.conn.name
+ our_full_jid = gajim.get_jid_from_account(account, full=True) + if self.stanza.getFrom() == our_full_jid: + # Drop messages sent from our own full jid + # It can happen that when we sent message to our own bare jid + # that the server routes that message back to us + log.info('Received message from self: %s, message is dropped' + % self.stanza.getFrom()) + return + # check if the message is a roster item exchange (XEP-0144) if self.stanza.getTag('x', namespace=nbxmpp.NS_ROSTERX): gajim.nec.push_incoming_event(RosterItemExchangeEvent(None, @@ -1179,6 +1188,17 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): to = gajim.get_jid_from_account(account) self.stanza.setFrom(to) self.sent = True + elif carbon_marker.getName() == 'received': + full_frm = str(self.stanza.getFrom()) + frm = gajim.get_jid_without_resource(full_frm) + if frm == gajim.get_jid_from_account(account): + # 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' + % full_frm) + return try: self.get_jid_resource() except helpers.InvalidFormat:
===================================== src/common/gajim.py ===================================== --- a/src/common/gajim.py +++ b/src/common/gajim.py @@ -420,13 +420,16 @@ def jid_is_transport(jid): return True return False
-def get_jid_from_account(account_name): +def get_jid_from_account(account_name, full=False): """ Return the jid we use in the given account """ name = config.get_per('accounts', account_name, 'name') hostname = config.get_per('accounts', account_name, 'hostname') jid = name + '@' + hostname + if full: + resource = connections[account_name].server_resource + jid += '/' + resource return jid
def get_our_jids():
===================================== src/message_control.py ===================================== --- a/src/message_control.py +++ b/src/message_control.py @@ -235,7 +235,8 @@ class MessageControl(object): conn = gajim.connections[self.account]
if not self.session: - if not obj.resource: + if (not obj.resource and + obj.jid != gajim.get_jid_from_account(self.account)): if self.resource: obj.resource = self.resource else:
===================================== src/roster_window.py ===================================== --- a/src/roster_window.py +++ b/src/roster_window.py @@ -2734,7 +2734,8 @@ class RosterWindow: typ = 'error' if obj.forwarded and obj.sent: typ = 'out' - xep0184_id = obj.id_ + if obj.jid != gajim.get_jid_from_account(obj.conn.name): + xep0184_id = obj.id_
obj.session.control.print_conversation(obj.msgtxt, typ, tim=obj.timestamp, encrypted=obj.encrypted, subject=obj.subject, @@ -3916,7 +3917,7 @@ class RosterWindow: contact = gajim.contacts.get_contact_with_highest_priority(account, jid) if jid == gajim.get_jid_from_account(account): - resource = contact.resource + resource = None
gajim.interface.on_open_chat_window(None, contact, account, \ resource=resource, session=session)
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/0eb2433c1754e4bdf967072aee6ce1b1c0...