From 06d890eea7d3e177c6dac9024dea90daea875df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 23 Jul 2017 09:55:13 +0200 Subject: [PATCH] Add more convenient get_own_jid() method --- gajim/common/connection.py | 15 +++++++++++++++ gajim/common/connection_handlers_events.py | 3 +-- gajim/common/gajim.py | 5 +---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/gajim/common/connection.py b/gajim/common/connection.py index 2e0cde5bf..af2a8288b 100644 --- a/gajim/common/connection.py +++ b/gajim/common/connection.py @@ -753,6 +753,21 @@ class Connection(CommonConnection, ConnectionHandlers): def check_jid(self, jid): return helpers.parse_jid(jid) + def get_own_jid(self, full=False): + """ + Return our own jid as JID + If full = True, this raises an exception if we cant provide + the full JID + """ + if self.connection: + full_jid = self.connection._registered_name + return nbxmpp.JID(full_jid) + else: + if full: + raise exceptions.GajimGeneralException( + 'We are not connected, full JID unknown.') + return nbxmpp.JID(gajim.get_jid_from_account(self.name)) + def reconnect(self): # Do not try to reco while we are already trying self.time_to_reconnect = None diff --git a/gajim/common/connection_handlers_events.py b/gajim/common/connection_handlers_events.py index f7ae73a0c..6e467fc44 100644 --- a/gajim/common/connection_handlers_events.py +++ b/gajim/common/connection_handlers_events.py @@ -1131,8 +1131,7 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): self.encrypted = False account = self.conn.name - our_full_jid = gajim.get_jid_from_account(account, full=True) - if self.stanza.getFrom() == our_full_jid: + if self.stanza.getFrom() == self.conn.get_own_jid(full=True): # 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 diff --git a/gajim/common/gajim.py b/gajim/common/gajim.py index bbe71a15a..970fefa47 100644 --- a/gajim/common/gajim.py +++ b/gajim/common/gajim.py @@ -420,16 +420,13 @@ def jid_is_transport(jid): return True return False -def get_jid_from_account(account_name, full=False): +def get_jid_from_account(account_name): """ 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():