Philipp Hörist pushed to branch master at gajim / gajim
Commits: d4053801 by Philipp Hörist at 2020-01-30T22:29:35+01:00 Remove unused code
- - - - - a5c13198 by Philipp Hörist at 2020-01-30T22:29:35+01:00 MUC: Store service jid in MUC module
- light refactoring of code which uses the service jid
- - - - - 7aab19fb by Philipp Hörist at 2020-01-30T22:29:35+01:00 Remove unused code
- - - - - 60182967 by Philipp Hörist at 2020-01-30T22:29:35+01:00 Reduce usage of the server_resource variable
- - - - -
12 changed files:
- gajim/common/app.py - gajim/common/connection.py - gajim/common/connection_handlers_events.py - gajim/common/jingle_session.py - gajim/common/modules/bytestream.py - gajim/common/modules/discovery.py - gajim/common/modules/muc.py - gajim/common/zeroconf/connection_zeroconf.py - gajim/gtk/groupchat_creation.py - gajim/gtk/server_info.py - gajim/gtk/tooltips.py - gajim/roster_window.py
Changes:
===================================== gajim/common/app.py ===================================== @@ -598,8 +598,6 @@ def get_name_from_jid(account, jid): actor = jid return actor
-def get_muc_domain(account): - return connections[account].muc_jid.get('jabber', None)
def get_recent_groupchats(account): recent_groupchats = config.get_per(
===================================== gajim/common/connection.py ===================================== @@ -112,10 +112,8 @@ class CommonConnection: self.agent_registrations = {}
self.roster_supported = True - self.addressing_supported = False self.avatar_conversion = False
- self.muc_jid = {} # jid of muc server for each transport type self._stun_servers = [] # STUN servers of our jabber server
# Tracks the calls of the connect_machine() method @@ -167,13 +165,6 @@ class CommonConnection: def get_status(self): return app.SHOW_LIST[self.connected]
- def check_jid(self, jid): - """ - This function must be implemented by derived classes. It has to return - the valid jid, or raise a helpers.InvalidFormat exception - """ - raise NotImplementedError - def new_account(self, name, config, sync=False): """ To be implemented by derived classes @@ -304,9 +295,6 @@ class Connection(CommonConnection, ConnectionHandlers): 'client_cert') self.client_cert_passphrase = ''
- def check_jid(self, jid): - return helpers.parse_jid(jid) - def get_own_jid(self, warn=False): """ Return the last full JID we received on a bind event. @@ -1259,8 +1247,7 @@ class Connection(CommonConnection, ConnectionHandlers):
cfg_proxies = app.config.get_per('accounts', self.name, 'file_transfer_proxies') - our_jid = helpers.parse_jid(app.get_jid_from_account(self.name) + \ - '/' + self.server_resource) + our_jid = self.get_own_jid() testit = app.config.get_per('accounts', self.name, 'test_ft_proxies_on_startup') if cfg_proxies:
===================================== gajim/common/connection_handlers_events.py ===================================== @@ -131,7 +131,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent): if self.jingle_content.getAttr('creator') == 'initiator': file_tag = desc.getTag('file') self.file_props.sender = self.fjid - self.file_props.receiver = self.conn.get_module('Bytestream')._ft_get_our_jid() + self.file_props.receiver = self.conn.get_own_jid() else: file_tag = desc.getTag('file') h = file_tag.getTag('hash') @@ -142,7 +142,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent): file_info = self.conn.get_module('Jingle').get_file_info( pjid, hash_=h, name=n, account=self.conn.name) self.file_props.file_name = file_info['file-name'] - self.file_props.sender = self.conn.get_module('Bytestream')._ft_get_our_jid() + self.file_props.sender = self.conn.get_own_jid() self.file_props.receiver = self.fjid self.file_props.type_ = 's' for child in file_tag.getChildren():
===================================== gajim/common/jingle_session.py ===================================== @@ -88,9 +88,7 @@ class JingleSession: self.contents = {} # negotiated contents self.connection = con # connection to use # our full jid - self.ourjid = app.get_jid_from_account(self.connection.name) - if con.server_resource: - self.ourjid = self.ourjid + '/' + con.server_resource + self.ourjid = str(self.connection.get_own_jid()) self.peerjid = jid # jid we connect to # jid we use as the initiator self.initiator = self.ourjid if weinitiate else self.peerjid
===================================== gajim/common/modules/bytestream.py ===================================== @@ -113,13 +113,6 @@ class Bytestream(BaseModule): default=self._account, testit=testit) raise nbxmpp.NodeProcessed
- def _ft_get_our_jid(self): - if self._account == 'Local': - return app.get_jid_from_account(self._account) - our_jid = app.get_jid_from_account(self._account) - resource = self._con.server_resource - return our_jid + '/' + resource - def _ft_get_receiver_jid(self, file_props): if self._account == 'Local': return file_props.receiver.jid
===================================== gajim/common/modules/discovery.py ===================================== @@ -147,9 +147,6 @@ class Discovery(BaseModule): if nbxmpp.NS_REGISTER in result.features: self._con.register_supported = True
- if nbxmpp.NS_ADDRESS in result.features: - self._con.addressing_supported = True - self._con.connect_machine(restart=True)
def _parse_transports(self, info):
===================================== gajim/common/modules/muc.py ===================================== @@ -117,6 +117,15 @@ class MUC(BaseModule): self._rejoin_muc = set() self._join_timeouts = {} self._rejoin_timeouts = {} + self._muc_service_jid = None + + @property + def supported(self): + return self._muc_service_jid is not None + + @property + def service_jid(self): + return self._muc_service_jid
def get_manager(self): return self._manager @@ -129,8 +138,7 @@ class MUC(BaseModule): continue if nbxmpp.NS_MUC in info.features: self._log.info('Discovered MUC: %s', info.jid) - # TODO: make this nicer - self._con.muc_jid['jabber'] = str(info.jid) + self._muc_service_jid = info.jid raise nbxmpp.NodeProcessed
def join(self, muc_data):
===================================== gajim/common/zeroconf/connection_zeroconf.py ===================================== @@ -101,9 +101,6 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf): self.username = app.config.get_per('accounts', app.ZEROCONF_ACC_NAME, 'name')
- def check_jid(self, jid): - return jid - def get_own_jid(self, *args, **kwargs): return nbxmpp.JID(self.username + '@' + self.host)
===================================== gajim/gtk/groupchat_creation.py ===================================== @@ -61,6 +61,10 @@ class CreateGroupchatWindow(Gtk.ApplicationWindow): self.show_all() self.set_focus(self._ui.address_entry)
+ def _get_muc_service_jid(self): + con = app.connections[self._account] + return str(con.get_module('MUC').service_jid or 'muc.example.com') + def _fill_account_combo(self, account): accounts = app.get_enabled_accounts_with_labels(connected_only=True) account_liststore = self._ui.account_combo.get_model() @@ -91,7 +95,7 @@ class CreateGroupchatWindow(Gtk.ApplicationWindow):
def _fill_placeholders(self): placeholder = random.choice(MUC_CREATION_EXAMPLES) - server = app.get_muc_domain(self._account) or 'muc.example.com' + server = self._get_muc_service_jid()
self._ui.name_entry.set_placeholder_text( placeholder[0] + _(' (optional)...')) @@ -116,7 +120,7 @@ class CreateGroupchatWindow(Gtk.ApplicationWindow): model = entry.get_completion().get_model() model.clear()
- server = app.get_muc_domain(self._account) or 'muc.example.com' + server = self._get_muc_service_jid() model.append(['%s@%s' % (text, server)])
def _validate_jid(self, text):
===================================== gajim/gtk/server_info.py ===================================== @@ -283,7 +283,8 @@ class ServerInfo(Gtk.ApplicationWindow, EventHelper): return [ Feature('XEP-0016: Privacy Lists', con.get_module('PrivacyLists').supported), - Feature('XEP-0045: Multi-User Chat', con.muc_jid), + Feature('XEP-0045: Multi-User Chat', + con.get_module('MUC').supported), Feature('XEP-0054: vcard-temp', con.get_module('VCardTemp').supported), Feature('XEP-0163: Personal Eventing Protocol',
===================================== gajim/gtk/tooltips.py ===================================== @@ -327,7 +327,7 @@ class RosterTooltip(StatusTable): name=account_name, show=connection.get_status(), status=connection.status, - resource=connection.server_resource, + resource=connection.get_own_jid().getResource(), priority=connection.priority)
contacts.append(contact)
===================================== gajim/roster_window.py ===================================== @@ -1839,9 +1839,7 @@ class RosterWindow: if account not in app.groups: app.groups[account] = {}
- self_jid = app.get_jid_from_account(account) - if app.connections[account].server_resource: - self_jid += '/' + app.connections[account].server_resource + self_jid = str(app.connections[account].get_own_jid()) if account != app.ZEROCONF_ACC_NAME: array[self_jid] = {'name': app.nicks[account], 'groups': ['self_contact'], @@ -2180,7 +2178,7 @@ class RosterWindow: if account not in app.contacts.get_accounts(): return child_iterA = self._get_account_iter(account, self.model) - self_resource = app.connections[account].server_resource + self_resource = app.connections[account].get_own_jid().getResource() self_contact = app.contacts.get_contact(account, app.get_jid_from_account(account), resource=self_resource) if self_contact: @@ -2553,14 +2551,11 @@ class RosterWindow: account = obj.conn.name self_jid = app.get_jid_from_account(account) if self_jid not in app.contacts.get_jid_list(account): - resource = '' - if app.connections[account].server_resource: - resource = app.connections[account].server_resource sha = app.config.get_per('accounts', account, 'avatar_sha') contact = app.contacts.create_contact( jid=self_jid, account=account, name=app.nicks[account], groups=['self_contact'], show='offline', sub='both', - ask='none', resource=resource, avatar_sha=sha) + ask='none', avatar_sha=sha) app.contacts.add_contact(account, contact) self.add_contact(self_jid, account)
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/4ef838344744ce4d60e30ea34e97d00198...