Improve getting own jid
We get our full JID on the bind event. After that it is saved in the `registered_name` attr on the Connection Object. In case the bind never occured we get the bare JID from config.
This commit is contained in:
parent
914935f864
commit
1e313cc7e2
|
@ -671,6 +671,8 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
self.try_connecting_for_foo_secs = 45
|
||||
# holds the actual hostname to which we are connected
|
||||
self.connected_hostname = None
|
||||
# Holds the full jid we received on the bind event
|
||||
self.registered_name = None
|
||||
self.redirected = None
|
||||
self.last_time_to_reconnect = None
|
||||
self.new_account_info = None
|
||||
|
@ -754,19 +756,16 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
def check_jid(self, jid):
|
||||
return helpers.parse_jid(jid)
|
||||
|
||||
def get_own_jid(self, full=False):
|
||||
def get_own_jid(self):
|
||||
"""
|
||||
Return our own jid as JID
|
||||
If full = True, this raises an exception if we cant provide
|
||||
the full JID
|
||||
Return the last full JID we received on a bind event.
|
||||
In case we were never connected it returns the bare JID from config.
|
||||
"""
|
||||
if self.connection:
|
||||
full_jid = self.connection._registered_name
|
||||
return nbxmpp.JID(full_jid)
|
||||
if self.registered_name:
|
||||
# This returns the full jid we received on the bind event
|
||||
return self.registered_name
|
||||
else:
|
||||
if full:
|
||||
raise exceptions.GajimGeneralException(
|
||||
'We are not connected, full JID unknown.')
|
||||
# This returns the bare jid
|
||||
return nbxmpp.JID(gajim.get_jid_from_account(self.name))
|
||||
|
||||
def reconnect(self):
|
||||
|
@ -1465,6 +1464,7 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
return
|
||||
if hasattr(con, 'Resource'):
|
||||
self.server_resource = con.Resource
|
||||
self.registered_name = con._registered_name
|
||||
if gajim.config.get_per('accounts', self.name, 'anonymous_auth'):
|
||||
# Get jid given by server
|
||||
old_jid = gajim.get_jid_from_account(self.name)
|
||||
|
|
|
@ -1146,7 +1146,7 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|||
self.encrypted = False
|
||||
account = self.conn.name
|
||||
|
||||
if self.stanza.getFrom() == self.conn.get_own_jid(full=True):
|
||||
if self.stanza.getFrom() == self.conn.get_own_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
|
||||
|
|
Loading…
Reference in New Issue