Skip to content
Snippets Groups Projects
Commit 61605616 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Use new JID attributes/methods

parent 0aba0f32
No related branches found
No related tags found
No related merge requests found
Showing
with 75 additions and 76 deletions
......@@ -248,12 +248,12 @@ def _open_uris(self, uris):
jid, cmd = uri, 'message'
try:
jid = JID(jid)
jid = JID.from_string(jid)
except InvalidJid as error:
app.log('uri_handler').warning('Invalid JID %s: %s', uri, error)
continue
if cmd == 'join' and jid.getResource():
if cmd == 'join' and jid.resource:
app.log('uri_handler').warning('Invalid MUC JID %s', uri)
continue
......
......@@ -578,7 +578,7 @@ def _on_mam_decrypted_message_received(self, event):
if not event.properties.jid == self.contact.get_full_jid():
return
else:
if not event.properties.jid.bareMatch(self.contact.jid):
if not event.properties.jid.bare_match(self.contact.jid):
return
kind = '' # incoming
......
......@@ -572,9 +572,8 @@ def get_recent_groupchats(account):
recent_list = []
for groupchat in recent_groupchats:
jid = nbxmpp.JID(groupchat)
recent = RecentGroupchat(
jid.getNode(), jid.getDomain(), jid.getResource())
jid = nbxmpp.JID.from_string(groupchat)
recent = RecentGroupchat(jid.localpart, jid.domain, jid.resource)
recent_list.append(recent)
return recent_list
......
......@@ -347,7 +347,7 @@ def get_own_jid(self):
return jid
# This returns the bare jid
return nbxmpp.JID(app.get_jid_from_account(self._account))
return nbxmpp.JID.from_string(app.get_jid_from_account(self._account))
def change_status(self, show, message):
if not message:
......
......@@ -159,7 +159,7 @@ def make_new_session(self, jid, thread_id=None, type_='chat', cls=None):
if not cls:
cls = app.default_session_type
sess = cls(self, nbxmpp.JID(jid), thread_id, type_)
sess = cls(self, nbxmpp.JID.from_string(jid), thread_id, type_)
# determine if this session is a pm session
# if not, discard the resource so that all sessions are stored bare
......
......@@ -1199,17 +1199,17 @@ def get_default_muc_config():
def validate_jid(jid, type_=None):
try:
jid = JID(str(jid))
jid = JID.from_string(str(jid))
except InvalidJid as error:
raise ValueError(error)
if type_ is None:
return jid
if type_ == 'bare' and jid.isBare:
if type_ == 'bare' and jid.is_bare:
return jid
if type_ == 'full' and jid.isFull:
if type_ == 'full' and jid.is_full:
return jid
if type_ == 'domain' and jid.isDomain:
if type_ == 'domain' and jid.is_domain:
return jid
raise ValueError('Not a %s JID' % type_)
......
......@@ -679,7 +679,7 @@ def __reason_from_stanza(stanza):
return (reason, text)
def __make_jingle(self, action, reason=None):
stanza = nbxmpp.Iq(typ='set', to=nbxmpp.JID(self.peerjid),
stanza = nbxmpp.Iq(typ='set', to=nbxmpp.JID.from_string(self.peerjid),
frm=self.ourjid)
attrs = {
'action': action,
......
......@@ -168,7 +168,7 @@ def _jid_adapter(jid):
return str(jid)
def _jid_converter(jid):
return JID(jid.decode())
return JID.from_string(jid.decode())
sqlite.register_converter('jid', _jid_converter)
......
......@@ -209,13 +209,13 @@ def __init__(self, con):
self._sessions = {}
def get_own_bare_jid(self):
return self._con.get_own_jid().getStripped()
return self._con.get_own_jid().bare
def is_same_jid(self, jid):
"""
Test if the bare jid given is the same as our bare jid
"""
return nbxmpp.JID(jid).getStripped() == self.get_own_bare_jid()
return nbxmpp.JID.from_string(jid).bare == self.get_own_bare_jid()
def command_list_query(self, stanza):
iq = stanza.buildReply('result')
......
......@@ -24,7 +24,7 @@ def __init__(self, con):
BaseModule.__init__(self, con)
def delete_motd(self):
server = self._con.get_own_jid().getDomain()
server = self._con.get_own_jid().domain
jid = '%s/announce/motd/delete' % server
self.set_announce(jid)
......
......@@ -113,7 +113,7 @@ def _entity_caps(self, _con, _stanza, properties):
NetworkEvent('caps-update',
account=self._account,
fjid=jid,
jid=properties.jid.getBare()))
jid=properties.jid.bare))
def _execute_task(self, task):
self._log.info('Request %s from %s', task.entity.hash, task.entity.jid)
......@@ -160,7 +160,7 @@ def _on_disco_info(self, disco_info):
NetworkEvent('caps-update',
account=self._account,
fjid=str(task.entity.jid),
jid=task.entity.jid.getBare()))
jid=task.entity.jid.bare))
def update_caps(self):
if not app.account_is_connected(self._account):
......@@ -209,7 +209,7 @@ def preconditions_met(self):
if self._from_muc:
muc = client.get_module('MUC').get_manager().get(
self.entity.jid.getBare())
self.entity.jid.bare)
if muc is None or not muc.state.is_joined:
self.set_obsolete()
......
......@@ -105,12 +105,12 @@ def _presence_received(self,
return
full_jid = stanza.getFrom()
if full_jid is None or self._con.get_own_jid().bareMatch(full_jid):
if full_jid is None or self._con.get_own_jid().bare_match(full_jid):
# Presence from ourself
return
contact = app.contacts.get_gc_contact(
self._account, full_jid.getStripped(), full_jid.getResource())
self._account, full_jid.bare, full_jid.resource)
if contact is None:
contact = app.contacts.get_contact_from_full_jid(
self._account, str(full_jid))
......@@ -150,8 +150,8 @@ def _process_chatstate(self, _con, _stanza, properties):
if properties.is_muc_pm:
contact = app.contacts.get_gc_contact(
self._account,
properties.jid.getBare(),
properties.jid.getResource())
properties.jid.bare,
properties.jid.resource)
else:
contact = app.contacts.get_contact_from_full_jid(
self._account, str(properties.jid))
......@@ -224,7 +224,7 @@ def get_active_chatstate(self, contact: ContactT) -> Optional[str]:
if not contact.is_groupchat:
# Don’t send chatstates to ourself
if self._con.get_own_jid().bareMatch(contact.jid):
if self._con.get_own_jid().bare_match(contact.jid):
return None
if not contact.supports(Namespace.CHATSTATES):
......@@ -256,7 +256,7 @@ def set_chatstate_delayed(self, contact: ContactT, state: State) -> None:
@ensure_enabled
def set_chatstate(self, contact: ContactT, state: State) -> None:
# Don’t send chatstates to ourself
if self._con.get_own_jid().bareMatch(contact.jid):
if self._con.get_own_jid().bare_match(contact.jid):
return
if contact.jid in self._blocked:
......
......@@ -59,7 +59,7 @@ def server_info(self):
return self._server_info
def discover_server_items(self):
server = self._con.get_own_jid().getDomain()
server = self._con.get_own_jid().domain
self.disco_items(server, callback=self._server_items_received)
def _server_items_received(self, result):
......@@ -95,7 +95,7 @@ def _server_items_info_received(self, result):
NetworkIncomingEvent('server-disco-received'))
def discover_account_info(self):
own_jid = self._con.get_own_jid().getStripped()
own_jid = self._con.get_own_jid().bare
self.disco_info(own_jid, callback=self._account_info_received)
def _account_info_received(self, result):
......@@ -120,7 +120,7 @@ def _account_info_received(self, result):
def discover_server_info(self):
# Calling this method starts the connect_maschine()
server = self._con.get_own_jid().getDomain()
server = self._con.get_own_jid().domain
self.disco_info(server, callback=self._server_info_received)
def _server_info_received(self, result):
......
......@@ -41,7 +41,7 @@ def _on_unsubscribe_result(self, _nbxmpp_client, stanza):
self._log.info('Error: %s', stanza.getError())
return
agent = stanza.getFrom().getBare()
agent = stanza.getFrom().bare
jid_list = []
for jid in app.contacts.get_jid_list(self._account):
if jid.endswith('@' + agent):
......@@ -72,8 +72,8 @@ def request_gateway_prompt(self, jid, prompt=None):
def _on_prompt_result(self, _nbxmpp_client, stanza):
jid = str(stanza.getFrom())
fjid = stanza.getFrom().getBare()
resource = stanza.getFrom().getResource()
fjid = stanza.getFrom().bare
resource = stanza.getFrom().resource
query = stanza.getTag('query')
if query is not None:
......
......@@ -50,7 +50,7 @@ def _iq_error_received(self, _con, _stanza, properties):
app.nec.push_incoming_event(
NetworkEvent('file-request-error',
conn=self._con,
jid=properties.jid.getBare(),
jid=properties.jid.bare,
file_props=file_props,
error_msg=to_user_string(properties.error)))
self._con.get_module('Bytestream').disconnect_transfer(
......
......@@ -93,7 +93,7 @@ def _from_valid_archive(self, _stanza, properties):
else:
expected_archive = self._con.get_own_jid()
return properties.mam.archive.bareMatch(expected_archive)
return properties.mam.archive.bare_match(expected_archive)
def _get_unique_id(self, properties):
if properties.type.is_groupchat:
......@@ -105,7 +105,7 @@ def _get_unique_id(self, properties):
if properties.is_muc_pm:
return properties.mam.id, properties.id
if self._con.get_own_jid().bareMatch(properties.from_):
if self._con.get_own_jid().bare_match(properties.from_):
# message we sent
return properties.mam.id, properties.id
......@@ -119,7 +119,7 @@ def _set_message_archive_info(self, _con, _stanza, properties):
return
if properties.type.is_groupchat:
archive_jid = properties.jid.getBare()
archive_jid = properties.jid.bare
timestamp = properties.timestamp
disco_info = app.logger.get_last_disco_info(archive_jid)
......@@ -136,7 +136,7 @@ def _set_message_archive_info(self, _con, _stanza, properties):
if not self.available:
return
archive_jid = self._con.get_own_jid().getBare()
archive_jid = self._con.get_own_jid().bare
timestamp = None
if properties.stanza_id is None:
......@@ -179,7 +179,7 @@ def _mam_message_received(self, _con, stanza, properties):
if is_groupchat:
kind = KindConstant.GC_MSG
else:
if properties.from_.bareMatch(self._con.get_own_jid()):
if properties.from_.bare_match(self._con.get_own_jid()):
kind = KindConstant.CHAT_MSG_SENT
else:
kind = KindConstant.CHAT_MSG_RECV
......@@ -217,7 +217,7 @@ def _mam_message_received(self, _con, stanza, properties):
self._log.debug(stanza.getProperties())
return
with_ = properties.jid.getStripped()
with_ = properties.jid.bare
if properties.is_muc_pm:
# we store the message with the full JID
with_ = str(with_)
......@@ -262,7 +262,7 @@ def _get_query_id(self, jid):
return query_id
def request_archive_on_signin(self):
own_jid = self._con.get_own_jid().getBare()
own_jid = self._con.get_own_jid().bare
if own_jid in self._mam_query_ids:
self._log.warning('Request already running: %s', own_jid)
......@@ -407,7 +407,7 @@ def request_archive_interval(self,
after=None,
queryid=None):
jid = self._con.get_own_jid().getBare()
jid = self._con.get_own_jid().bare
if after is None:
self._log.info('Request interval: %s, from %s to %s',
......
......@@ -62,7 +62,7 @@ def _check_if_unknown_contact(self, _con, stanza, properties):
properties.is_mam_message):
return
if self._con.get_own_jid().getDomain() == str(properties.jid):
if self._con.get_own_jid().domain == str(properties.jid):
# Server message
return
......@@ -70,7 +70,7 @@ def _check_if_unknown_contact(self, _con, stanza, properties):
'ignore_unknown_contacts'):
return
jid = properties.jid.getBare()
jid = properties.jid.bare
if self._con.get_module('Roster').get_item(jid) is None:
self._log.warning('Ignore message from unknown contact: %s', jid)
self._log.warning(stanza)
......@@ -103,8 +103,8 @@ def _message_received(self, _con, stanza, properties):
from_ = stanza.getFrom()
fjid = str(from_)
jid = from_.getBare()
resource = from_.getResource()
jid = from_.bare
resource = from_.resource
type_ = properties.type
......@@ -115,14 +115,14 @@ def _message_received(self, _con, stanza, properties):
# Don’t check for message text because the message could be
# encrypted.
if app.logger.deduplicate_muc_message(self._account,
properties.jid.getBare(),
properties.jid.getResource(),
properties.jid.bare,
properties.jid.resource,
properties.timestamp,
properties.id):
raise nbxmpp.NodeProcessed
if (properties.is_self_message or properties.is_muc_pm):
archive_jid = self._con.get_own_jid().getStripped()
archive_jid = self._con.get_own_jid().bare
if app.logger.find_stanza_id(self._account,
archive_jid,
stanza_id,
......@@ -214,9 +214,9 @@ def _message_received(self, _con, stanza, properties):
NetworkEvent('decrypted-message-received', **event_attr))
def _message_error_received(self, _con, _stanza, properties):
jid = properties.jid.copy()
jid = properties.jid
if not properties.is_muc_pm:
jid.setBare()
jid = jid.new_as_bare()
self._log.info(properties.error)
......@@ -267,7 +267,7 @@ def _get_unique_id(self, properties):
if properties.type.is_groupchat:
disco_info = app.logger.get_last_disco_info(
properties.jid.getBare())
properties.jid.bare)
if disco_info.mam_namespace != Namespace.MAM_2:
return None, None
......@@ -279,7 +279,7 @@ def _get_unique_id(self, properties):
archive = self._con.get_own_jid()
if archive.bareMatch(properties.stanza_id.by):
if archive.bare_match(properties.stanza_id.by):
return properties.stanza_id.id, None
# stanza-id not added by the archive, ignore it.
return None, None
......@@ -329,7 +329,7 @@ def build_message_stanza(self, message):
oob.addChild('url').setData(message.oob_url)
# XEP-0184
if not own_jid.bareMatch(message.jid):
if not own_jid.bare_match(message.jid):
if message.message and not message.is_groupchat:
stanza.setReceiptRequest()
......
......@@ -162,7 +162,7 @@ def _on_disco_result(self, result):
app.nec.push_incoming_event(
NetworkEvent('muc-join-failed',
account=self._account,
room_jid=result.jid.getBare(),
room_jid=result.jid.bare,
error=result))
return
......@@ -317,7 +317,7 @@ def change_nick(self, room_jid, new_nick):
status=message)
def _on_error_presence(self, _con, _stanza, properties):
room_jid = properties.jid.getBare()
room_jid = properties.jid.bare
muc_data = self._manager.get(room_jid)
if muc_data is None:
return
......@@ -529,7 +529,7 @@ def _raise_muc_event(self, event_name, properties):
app.nec.push_incoming_event(
NetworkEvent(event_name,
account=self._account,
room_jid=properties.jid.getBare(),
room_jid=properties.jid.bare,
properties=properties))
self._log_muc_event(event_name, properties)
......@@ -558,7 +558,7 @@ def _log_muc_event(self, event_name, properties):
app.logger.insert_into_logs(
self._account,
properties.jid.getBare(),
properties.jid.bare,
properties.timestamp,
KindConstant.GCSTATUS,
contact_name=properties.muc_nickname,
......@@ -571,7 +571,7 @@ def _add_new_muc_contact(self, properties):
if properties.muc_user.jid is not None:
real_jid = str(properties.muc_user.jid)
contact = app.contacts.create_gc_contact(
room_jid=properties.jid.getBare(),
room_jid=properties.jid.bare,
account=self._account,
name=properties.muc_nickname,
show=properties.show,
......@@ -686,7 +686,7 @@ def _on_captcha_challenge(self, _con, _stanza, properties):
app.nec.push_incoming_event(
NetworkEvent('muc-captcha-challenge',
account=self._account,
room_jid=properties.jid.getBare(),
room_jid=properties.jid.bare,
form=properties.captcha.form))
raise nbxmpp.NodeProcessed
......
......@@ -95,7 +95,7 @@ def _presence_received(self, _con, stanza, properties):
show=properties.show.value))
return
jid = properties.jid.getBare()
jid = properties.jid.bare
roster_item = self._con.get_module('Roster').get_item(jid)
if not properties.is_self_bare and roster_item is None:
# Handle only presence from roster contacts
......@@ -114,8 +114,8 @@ def _presence_received(self, _con, stanza, properties):
'need_add_in_roster': False,
'popup': False,
'ptype': properties.type.value,
'jid': properties.jid.getBare(),
'resource': properties.jid.getResource(),
'jid': properties.jid.bare,
'resource': properties.jid.resource,
'id_': properties.id,
'fjid': str(properties.jid),
'timestamp': properties.timestamp,
......@@ -139,8 +139,8 @@ def _presence_received(self, _con, stanza, properties):
def _update_contact(self, event, properties):
# Note: A similar method also exists in connection_zeroconf
jid = properties.jid.getBare()
resource = properties.jid.getResource()
jid = properties.jid.bare
resource = properties.jid.resource
status_strings = ['offline', 'error', 'online', 'chat', 'away',
'xa', 'dnd']
......@@ -156,8 +156,8 @@ def _update_contact(self, event, properties):
event.contact_list = contact_list
contact = app.contacts.get_contact_strict(self._account,
properties.jid.getBare(),
properties.jid.getResource())
properties.jid.bare,
properties.jid.resource)
if contact is None:
contact = app.contacts.get_first_contact_from_jid(self._account,
jid)
......@@ -229,7 +229,7 @@ def _is_resource_known(contact_list):
def _log_presence(self, properties):
if not app.settings.get('log_contact_status_changes'):
return
if not should_log(self._account, properties.jid.getBare()):
if not should_log(self._account, properties.jid.bare):
return
show = ShowConstant[properties.show.name]
......@@ -237,14 +237,14 @@ def _log_presence(self, properties):
show = ShowConstant.OFFLINE
app.logger.insert_into_logs(self._account,
properties.jid.getBare(),
properties.jid.bare,
time.time(),
KindConstant.STATUS,
message=properties.status,
show=show)
def _subscribe_received(self, _con, _stanza, properties):
jid = properties.jid.getBare()
jid = properties.jid.bare
fjid = str(properties.jid)
is_transport = app.jid_is_transport(fjid)
......@@ -276,7 +276,7 @@ def _subscribe_received(self, _con, _stanza, properties):
raise nbxmpp.NodeProcessed
def _subscribed_received(self, _con, _stanza, properties):
jid = properties.jid.getBare()
jid = properties.jid.bare
self._log.info('Received Subscribed: %s', properties.jid)
if jid in self.automatically_added:
self.automatically_added.remove(jid)
......@@ -296,7 +296,7 @@ def _unsubscribed_received(self, _con, _stanza, properties):
self._log.info('Received Unsubscribed: %s', properties.jid)
app.nec.push_incoming_event(NetworkEvent(
'unsubscribed-presence-received',
conn=self._con, jid=properties.jid.getBare()))
conn=self._con, jid=properties.jid.bare))
raise nbxmpp.NodeProcessed
def subscribed(self, jid):
......
......@@ -77,9 +77,9 @@ def _process_message_receipt(self, _con, stanza, properties):
properties.jid,
properties.receipt.id)
jid = properties.jid.copy()
jid = properties.jid
if not properties.is_muc_pm:
jid.setBare()
jid = jid.new_as_bare()
app.logger.set_marker(app.get_jid_from_account(self._account),
jid,
......@@ -97,11 +97,11 @@ def _process_message_receipt(self, _con, stanza, properties):
def _get_contact(self, properties):
if properties.is_muc_pm:
return app.contacts.get_gc_contact(self._account,
properties.jid.getBare(),
properties.jid.getResource())
properties.jid.bare,
properties.jid.resource)
contact = app.contacts.get_contact(self._account,
properties.jid.getBare())
properties.jid.bare)
if contact is not None and contact.sub not in ('to', 'none'):
return contact
return None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment