diff options
author | Philipp Hörist <forenjunkie@chello.at> | 2017-04-10 18:10:50 +0300 |
---|---|---|
committer | Philipp Hörist <forenjunkie@chello.at> | 2017-04-10 18:10:50 +0300 |
commit | f7161b468a281f74d83842dbdc38bc22e5357806 (patch) | |
tree | 1aa0f086805467d3720bf4fe62755852ce99e726 | |
parent | b4bb07a071b5b096ee0bbd44ab12e1b13caa8f4f (diff) | |
parent | 5e56f9c3878af2b7f9de65ee397aadb28398da6e (diff) |
Merge branch 'fixselfresource' into 'gajim_0.16'
Improvements for sending messages to ourself
See merge request !69
-rw-r--r-- | src/chat_control.py | 19 | ||||
-rw-r--r-- | src/common/connection.py | 11 | ||||
-rw-r--r-- | src/common/connection_handlers.py | 24 | ||||
-rw-r--r-- | src/common/connection_handlers_events.py | 20 | ||||
-rw-r--r-- | src/common/gajim.py | 5 | ||||
-rw-r--r-- | src/message_control.py | 3 | ||||
-rw-r--r-- | src/roster_window.py | 5 |
7 files changed, 62 insertions, 25 deletions
diff --git a/src/chat_control.py b/src/chat_control.py index cae97a77e..1c6625341 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -2362,7 +2362,10 @@ class ChatControl(ChatControlBase): if not keyID: keyID = 'UNKNOWN' - chatstates_on = gajim.config.get('outgoing_chat_state_notifications') != \ + if self.contact.jid == gajim.get_jid_from_account(self.account): + chatstates_on = False + else: + chatstates_on = gajim.config.get('outgoing_chat_state_notifications') != \ 'disabled' chatstate_to_send = None if chatstates_on and contact is not None: @@ -2377,11 +2380,11 @@ class ChatControl(ChatControlBase): def _on_sent(msg_stanza, message, encrypted, xhtml, label, old_txt): 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: @@ -2696,6 +2699,10 @@ class ChatControl(ChatControlBase): chatstate_setting = gajim.config.get('outgoing_chat_state_notifications') if chatstate_setting == 'disabled': 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 diff --git a/src/common/connection.py b/src/common/connection.py index f2f6d3bdc..9d4e83836 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -298,6 +298,8 @@ class CommonConnection: 'to %s, this JID is not valid.') % j)) return fjid = new_list + elif jid == gajim.get_jid_from_account(self.name): + fjid = jid else: try: jid = self.check_jid(jid) @@ -502,10 +504,11 @@ class CommonConnection: msg_iq.setTag(chatstate, namespace=nbxmpp.NS_CHATSTATES) # 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 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 forward_from: addresses = msg_iq.addChild('addresses', diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index a57f74105..7a1aa8ab5 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1206,17 +1206,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 (u'to', u'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 (u'to', u'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', diff --git a/src/common/connection_handlers_events.py b/src/common/connection_handlers_events.py index 64472cac7..0fc6e08c4 100644 --- a/src/common/connection_handlers_events.py +++ b/src/common/connection_handlers_events.py @@ -1129,6 +1129,15 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): 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, @@ -1184,6 +1193,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: diff --git a/src/common/gajim.py b/src/common/gajim.py index 15a710540..94976feab 100644 --- a/src/common/gajim.py +++ b/src/common/gajim.py @@ -419,13 +419,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(): diff --git a/src/message_control.py b/src/message_control.py index 0e31b03bc..164932f5c 100644 --- a/src/message_control.py +++ b/src/message_control.py @@ -234,7 +234,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: diff --git a/src/roster_window.py b/src/roster_window.py index 574eb8ee9..b2c198350 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -2759,7 +2759,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, @@ -4167,7 +4168,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) |