Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gajim/common/client.py7
-rw-r--r--gajim/common/client_modules.py162
-rw-r--r--gajim/common/modules/__init__.py2
-rw-r--r--pyproject.toml1
4 files changed, 167 insertions, 5 deletions
diff --git a/gajim/common/client.py b/gajim/common/client.py
index 626e65612..39f408906 100644
--- a/gajim/common/client.py
+++ b/gajim/common/client.py
@@ -33,6 +33,7 @@ from gajim.common import app
from gajim.common import helpers
from gajim.common import modules
from gajim.common import passwords
+from gajim.common.client_modules import ClientModules
from gajim.common.const import ClientState
from gajim.common.const import SimpleClientState
from gajim.common.events import AccountConnected
@@ -65,9 +66,10 @@ log = logging.getLogger('gajim.client')
IgnoredTlsErrorsT = set[Gio.TlsCertificateFlags] | None
-class Client(Observable):
+class Client(Observable, ClientModules):
def __init__(self, account: str) -> None:
Observable.__init__(self, log)
+ ClientModules.__init__(self, account)
self._client = None
self._account = account
self.name = account
@@ -421,9 +423,6 @@ class Client(Observable):
if include_muc:
self.get_module('MUC').update_presence()
- def get_module(self, name: str):
- return modules.get(self._account, name)
-
@helpers.call_counter
def connect_machine(self) -> None:
log.info('Connect machine state: %s', self._connect_machine_calls)
diff --git a/gajim/common/client_modules.py b/gajim/common/client_modules.py
new file mode 100644
index 000000000..f8404241f
--- /dev/null
+++ b/gajim/common/client_modules.py
@@ -0,0 +1,162 @@
+# This file is part of Gajim.
+#
+# Gajim is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation; version 3 only.
+#
+# Gajim is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
+
+from __future__ import annotations
+
+from typing import Literal
+from typing import overload
+from typing import TYPE_CHECKING
+
+from gajim.common import modules
+
+if TYPE_CHECKING:
+ from gajim.common.modules.adhoc_commands import AdHocCommands
+ from gajim.common.modules.annotations import Annotations
+ from gajim.common.modules.base import BaseModule
+ from gajim.common.modules.bits_of_binary import BitsOfBinary
+ from gajim.common.modules.blocking import Blocking
+ from gajim.common.modules.bookmarks import Bookmarks
+ from gajim.common.modules.bytestream import Bytestream
+ from gajim.common.modules.caps import Caps
+ from gajim.common.modules.carbons import Carbons
+ from gajim.common.modules.chat_markers import ChatMarkers
+ from gajim.common.modules.chatstates import Chatstate
+ from gajim.common.modules.contacts import Contacts
+ from gajim.common.modules.delimiter import Delimiter
+ from gajim.common.modules.discovery import Discovery
+ from gajim.common.modules.entity_time import EntityTime
+ from gajim.common.modules.gateway import Gateway
+ from gajim.common.modules.http_auth import HTTPAuth
+ from gajim.common.modules.httpupload import HTTPUpload
+ from gajim.common.modules.ibb import IBB
+ from gajim.common.modules.iq import Iq
+ from gajim.common.modules.jingle import Jingle
+ from gajim.common.modules.last_activity import LastActivity
+ from gajim.common.modules.mam import MAM
+ from gajim.common.modules.message import Message
+ from gajim.common.modules.muc import MUC
+ from gajim.common.modules.omemo import OMEMO
+ from gajim.common.modules.pep import PEP
+ from gajim.common.modules.ping import Ping
+ from gajim.common.modules.presence import Presence
+ from gajim.common.modules.pubsub import PubSub
+ from gajim.common.modules.receipts import Receipts
+ from gajim.common.modules.register import Register
+ from gajim.common.modules.roster import Roster
+ from gajim.common.modules.roster_item_exchange import RosterItemExchange
+ from gajim.common.modules.search import Search
+ from gajim.common.modules.security_labels import SecLabels
+ from gajim.common.modules.software_version import SoftwareVersion
+ from gajim.common.modules.user_avatar import UserAvatar
+ from gajim.common.modules.user_location import UserLocation
+ from gajim.common.modules.user_nickname import UserNickname
+ from gajim.common.modules.user_tune import UserTune
+ from gajim.common.modules.vcard4 import VCard4
+ from gajim.common.modules.vcard_avatars import VCardAvatars
+ from gajim.common.modules.vcard_temp import VCardTemp
+
+
+class ClientModules:
+ def __init__(self, account: str) -> None:
+ self._account = account
+
+ @overload
+ def get_module(self, name: Literal['AdHocCommands']) -> AdHocCommands: ...
+ @overload
+ def get_module(self, name: Literal['Annotations']) -> Annotations: ...
+ @overload
+ def get_module(self, name: Literal['BitsOfBinary']) -> BitsOfBinary: ...
+ @overload
+ def get_module(self, name: Literal['Blocking']) -> Blocking: ...
+ @overload
+ def get_module(self, name: Literal['Bookmarks']) -> Bookmarks: ...
+ @overload
+ def get_module(self, name: Literal['Bytestream']) -> Bytestream: ...
+ @overload
+ def get_module(self, name: Literal['Caps']) -> Caps: ...
+ @overload
+ def get_module(self, name: Literal['Carbons']) -> Carbons: ...
+ @overload
+ def get_module(self, name: Literal['ChatMarkers']) -> ChatMarkers: ...
+ @overload
+ def get_module(self, name: Literal['Chatstate']) -> Chatstate: ...
+ @overload
+ def get_module(self, name: Literal['Contacts']) -> Contacts: ...
+ @overload
+ def get_module(self, name: Literal['Delimiter']) -> Delimiter: ...
+ @overload
+ def get_module(self, name: Literal['Discovery']) -> Discovery: ...
+ @overload
+ def get_module(self, name: Literal['EntityTime']) -> EntityTime: ...
+ @overload
+ def get_module(self, name: Literal['Gateway']) -> Gateway: ...
+ @overload
+ def get_module(self, name: Literal['HTTPAuth']) -> HTTPAuth: ...
+ @overload
+ def get_module(self, name: Literal['HTTPUpload']) -> HTTPUpload: ...
+ @overload
+ def get_module(self, name: Literal['IBB']) -> IBB: ...
+ @overload
+ def get_module(self, name: Literal['Iq']) -> Iq: ...
+ @overload
+ def get_module(self, name: Literal['Jingle']) -> Jingle: ...
+ @overload
+ def get_module(self, name: Literal['LastActivity']) -> LastActivity: ...
+ @overload
+ def get_module(self, name: Literal['MAM']) -> MAM: ...
+ @overload
+ def get_module(self, name: Literal['Message']) -> Message: ...
+ @overload
+ def get_module(self, name: Literal['MUC']) -> MUC: ...
+ @overload
+ def get_module(self, name: Literal['OMEMO']) -> OMEMO: ...
+ @overload
+ def get_module(self, name: Literal['PEP']) -> PEP: ...
+ @overload
+ def get_module(self, name: Literal['Ping']) -> Ping: ...
+ @overload
+ def get_module(self, name: Literal['Presence']) -> Presence: ...
+ @overload
+ def get_module(self, name: Literal['PubSub']) -> PubSub: ...
+ @overload
+ def get_module(self, name: Literal['Receipts']) -> Receipts: ...
+ @overload
+ def get_module(self, name: Literal['Register']) -> Register: ...
+ @overload
+ def get_module(self, name: Literal['RosterItemExchange']) -> RosterItemExchange: ... # noqa: E501
+ @overload
+ def get_module(self, name: Literal['Roster']) -> Roster: ...
+ @overload
+ def get_module(self, name: Literal['Search']) -> Search: ...
+ @overload
+ def get_module(self, name: Literal['SecLabels']) -> SecLabels: ...
+ @overload
+ def get_module(self, name: Literal['SoftwareVersion']) -> SoftwareVersion: ... # noqa: E501
+ @overload
+ def get_module(self, name: Literal['UserAvatar']) -> UserAvatar: ...
+ @overload
+ def get_module(self, name: Literal['UserLocation']) -> UserLocation: ...
+ @overload
+ def get_module(self, name: Literal['UserNickname']) -> UserNickname: ...
+ @overload
+ def get_module(self, name: Literal['UserTune']) -> UserTune: ...
+ @overload
+ def get_module(self, name: Literal['VCardAvatars']) -> VCardAvatars: ...
+ @overload
+ def get_module(self, name: Literal['VCardTemp']) -> VCardTemp: ...
+ @overload
+ def get_module(self, name: Literal['VCard4']) -> VCard4: ...
+
+ def get_module(self, name: str) -> BaseModule:
+ return modules.get(self._account, name)
diff --git a/gajim/common/modules/__init__.py b/gajim/common/modules/__init__.py
index 3c26fbb34..2f42b3097 100644
--- a/gajim/common/modules/__init__.py
+++ b/gajim/common/modules/__init__.py
@@ -39,7 +39,7 @@ _store_publish_modules = [
def register_modules(client: Client) -> None:
- if client in _modules:
+ if client.account in _modules:
return
_modules[client.account] = {}
diff --git a/pyproject.toml b/pyproject.toml
index c03f5a8c1..1e29e229e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -119,6 +119,7 @@ include = [
"gajim/common/application.py",
"gajim/common/call_manager.py",
"gajim/common/cert_store.py",
+ "gajim/common/client_modules.py",
"gajim/common/commands.py",
"gajim/common/configpaths.py",
"gajim/common/const.py",