Add more convenient get_own_jid() method
This commit is contained in:
parent
85d220c80e
commit
06d890eea7
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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():
|
||||
|
|
Loading…
Reference in New Issue