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():