Philipp Hörist pushed to branch master at gajim / gajim

Commits:

11 changed files:

Changes:

  • gajim/common/client.py
    ... ... @@ -55,6 +55,7 @@
    55 55
     from gajim.common.idle import Monitor
    
    56 56
     from gajim.common.idle import IdleMonitorManager
    
    57 57
     from gajim.common.i18n import _
    
    58
    +from gajim.common.structs import OutgoingMessage
    
    58 59
     
    
    59 60
     from gajim.gui.util import open_window
    
    60 61
     
    
    ... ... @@ -471,13 +472,13 @@ def _finish_connect(self) -> None:
    471 472
             app.ged.raise_event(SignedIn(account=self._account, conn=self))
    
    472 473
             modules.send_stored_publish(self._account)
    
    473 474
     
    
    474
    -    def send_stanza(self, stanza):
    
    475
    +    def send_stanza(self, stanza: Any) -> None:
    
    475 476
             """
    
    476 477
             Send a stanza untouched
    
    477 478
             """
    
    478 479
             return self._client.send_stanza(stanza)
    
    479 480
     
    
    480
    -    def send_message(self, message):
    
    481
    +    def send_message(self, message: OutgoingMessage) -> None:
    
    481 482
             if not self._state.is_available:
    
    482 483
                 log.warning('Trying to send message while offline')
    
    483 484
                 return
    
    ... ... @@ -504,7 +505,7 @@ def send_message(self, message):
    504 505
                                                message,
    
    505 506
                                                self._send_message)
    
    506 507
     
    
    507
    -    def _send_message(self, message):
    
    508
    +    def _send_message(self, message: OutgoingMessage) -> None:
    
    508 509
             message.set_sent_timestamp()
    
    509 510
             message.message_id = self.send_stanza(message.stanza)
    
    510 511
     
    
    ... ... @@ -525,7 +526,7 @@ def _send_message(self, message):
    525 526
     
    
    526 527
             self.get_module('Message').log_message(message)
    
    527 528
     
    
    528
    -    def send_messages(self, jids, message):
    
    529
    +    def send_messages(self, jids: list[JID], message: OutgoingMessage) -> None:
    
    529 530
             if not self._state.is_available:
    
    530 531
                 log.warning('Trying to send message while offline')
    
    531 532
                 return
    

  • gajim/common/helpers.py
    ... ... @@ -1414,7 +1414,7 @@ def get_group_chat_nick(account: str, room_jid: Union[JID, str]) -> str:
    1414 1414
         return nick
    
    1415 1415
     
    
    1416 1416
     
    
    1417
    -def get_muc_context(jid: Union[JID, str]) -> Optional[str]:
    
    1417
    +def get_muc_context(jid: JID) -> Optional[str]:
    
    1418 1418
         disco_info = app.storage.cache.get_last_disco_info(jid)
    
    1419 1419
         if disco_info is None:
    
    1420 1420
             return None
    

  • gajim/common/modules/base.py
    ... ... @@ -43,6 +43,7 @@ def __init__(self,
    43 43
     
    
    44 44
             EventHelper.__init__(self)
    
    45 45
             self._con = con
    
    46
    +        self._client = con
    
    46 47
             self._account = con.account
    
    47 48
             self._log = self._set_logger(plugin)
    
    48 49
             self._nbxmpp_callbacks: dict[str, Any] = {}
    

  • gajim/common/modules/caps.py
    ... ... @@ -106,8 +106,9 @@ def _entity_caps(self, _con, _stanza, properties):
    106 106
                 self._queue_task(task)
    
    107 107
                 return
    
    108 108
     
    
    109
    -        jid = str(properties.jid)
    
    110
    -        app.storage.cache.set_last_disco_info(jid, disco_info, cache_only=True)
    
    109
    +        app.storage.cache.set_last_disco_info(properties.jid,
    
    110
    +                                              disco_info,
    
    111
    +                                              cache_only=True)
    
    111 112
     
    
    112 113
             contact = self._con.get_module('Contacts').get_contact(properties.jid)
    
    113 114
             contact.notify('caps-update')
    
    ... ... @@ -145,7 +146,7 @@ def _on_disco_info(self, nbxmpp_task):
    145 146
                 return
    
    146 147
     
    
    147 148
             app.storage.cache.add_caps_entry(
    
    148
    -            str(disco_info.jid),
    
    149
    +            disco_info.jid,
    
    149 150
                 task.entity.method,
    
    150 151
                 disco_info.get_caps_hash(),
    
    151 152
                 disco_info)
    

  • gajim/common/modules/chat_markers.py
    ... ... @@ -14,10 +14,15 @@
    14 14
     
    
    15 15
     # Chat Markers (XEP-0333)
    
    16 16
     
    
    17
    +from __future__ import annotations
    
    18
    +
    
    19
    +from typing import Any
    
    20
    +
    
    17 21
     from nbxmpp.namespaces import Namespace
    
    18 22
     from nbxmpp.structs import StanzaHandler
    
    19 23
     
    
    20 24
     from gajim.common import app
    
    25
    +from gajim.common import types
    
    21 26
     from gajim.common.events import DisplayedReceived
    
    22 27
     from gajim.common.events import ReadStateSync
    
    23 28
     from gajim.common.modules.base import BaseModule
    
    ... ... @@ -28,8 +33,8 @@ class ChatMarkers(BaseModule):
    28 33
     
    
    29 34
         _nbxmpp_extends = 'ChatMarkers'
    
    30 35
     
    
    31
    -    def __init__(self, con):
    
    32
    -        BaseModule.__init__(self, con)
    
    36
    +    def __init__(self, client: types.Client):
    
    37
    +        BaseModule.__init__(self, client)
    
    33 38
     
    
    34 39
             self.handlers = [
    
    35 40
                 StanzaHandler(name='message',
    
    ... ... @@ -38,7 +43,11 @@ def __init__(self, con):
    38 43
                               priority=47),
    
    39 44
             ]
    
    40 45
     
    
    41
    -    def _process_chat_marker(self, _con, _stanza, properties):
    
    46
    +    def _process_chat_marker(self,
    
    47
    +                             _client: types.xmppClient,
    
    48
    +                             _stanza: Any,
    
    49
    +                             properties: Any) -> None:
    
    50
    +
    
    42 51
             if not properties.is_marker or not properties.marker.is_displayed:
    
    43 52
                 return
    
    44 53
     
    
    ... ... @@ -46,7 +55,7 @@ def _process_chat_marker(self, _con, _stanza, properties):
    46 55
                 return
    
    47 56
     
    
    48 57
             if properties.type.is_groupchat:
    
    49
    -            contact = self._con.get_module('Contacts').get_contact(
    
    58
    +            contact = self._client.get_module('Contacts').get_contact(
    
    50 59
                     properties.muc_jid,
    
    51 60
                     groupchat=True)
    
    52 61
                 if not contact.is_joined:
    
    ... ... @@ -64,12 +73,12 @@ def _process_chat_marker(self, _con, _stanza, properties):
    64 73
                 return
    
    65 74
     
    
    66 75
             if properties.is_mam_message:
    
    67
    -            if properties.from_.bare_match(self._con.get_own_jid()):
    
    76
    +            if properties.from_.bare_match(self._client.get_own_jid()):
    
    68 77
                     return
    
    69 78
     
    
    70 79
             self._raise_event('displayed-received', properties)
    
    71 80
     
    
    72
    -    def _raise_event(self, name, properties):
    
    81
    +    def _raise_event(self, name: str, properties: Any) -> None:
    
    73 82
             self._log.info('%s: %s %s',
    
    74 83
                            name,
    
    75 84
                            properties.jid,
    
    ... ... @@ -100,10 +109,15 @@ def _raise_event(self, name, properties):
    100 109
                             is_muc_pm=properties.is_muc_pm,
    
    101 110
                             marker_id=properties.marker.id))
    
    102 111
     
    
    103
    -    def _send_marker(self, contact, marker, id_, type_):
    
    112
    +    def _send_marker(self,
    
    113
    +                     contact: types.ChatContacts,
    
    114
    +                     marker: str,
    
    115
    +                     id_: str,
    
    116
    +                     type_: str) -> None:
    
    117
    +
    
    104 118
             jid = contact.jid
    
    105 119
             if contact.is_pm_contact:
    
    106
    -            jid = contact.jid.bare
    
    120
    +            jid = contact.jid.new_as_bare()
    
    107 121
     
    
    108 122
             if type_ in ('gc', 'pm'):
    
    109 123
                 if not app.settings.get_group_chat_setting(
    
    ... ... @@ -121,8 +135,11 @@ def _send_marker(self, contact, marker, id_, type_):
    121 135
                                       type_=typ,
    
    122 136
                                       marker=(marker, id_),
    
    123 137
                                       play_sound=False)
    
    124
    -        self._con.send_message(message)
    
    138
    +        self._client.send_message(message)
    
    125 139
             self._log.info('Send %s: %s', marker, contact.jid)
    
    126 140
     
    
    127
    -    def send_displayed_marker(self, contact, id_, type_):
    
    128
    -        self._send_marker(contact, 'displayed', id_, str(type_))
    141
    +    def send_displayed_marker(self,
    
    142
    +                              contact: types.ChatContacts,
    
    143
    +                              id_: str,
    
    144
    +                              type_: str) -> None:
    
    145
    +        self._send_marker(contact, 'displayed', id_, type_)

  • gajim/common/modules/contacts.py
    ... ... @@ -45,13 +45,13 @@
    45 45
     
    
    46 46
     
    
    47 47
     class ContactSettings:
    
    48
    -    def __init__(self, account: str, jid: str) -> None:
    
    48
    +    def __init__(self, account: str, jid: JID) -> None:
    
    49 49
             self.get = partial(app.settings.get_contact_setting, account, jid)
    
    50 50
             self.set = partial(app.settings.set_contact_setting, account, jid)
    
    51 51
     
    
    52 52
     
    
    53 53
     class GroupChatSettings:
    
    54
    -    def __init__(self, account: str, jid: str) -> None:
    
    54
    +    def __init__(self, account: str, jid: JID) -> None:
    
    55 55
             self._account = account
    
    56 56
             self._jid = jid
    
    57 57
     
    
    ... ... @@ -73,7 +73,7 @@ def set(self, setting: BoolGroupChatSettings, value: bool) -> None: ...
    73 73
         def set(self, setting: IntGroupChatSettings, value: int) -> None: ...
    
    74 74
         def set(self, setting: Any, value: Any) -> None:
    
    75 75
             app.settings.set_group_chat_setting(
    
    76
    -            self._account, str(self._jid), setting, value)
    
    76
    +            self._account, self._jid, setting, value)
    
    77 77
     
    
    78 78
     
    
    79 79
     class Contacts(BaseModule):
    
    ... ... @@ -228,7 +228,7 @@ class BareContact(CommonContact):
    228 228
         def __init__(self, logger: logging.Logger, jid: JID, account: str) -> None:
    
    229 229
             CommonContact.__init__(self, logger, jid, account)
    
    230 230
     
    
    231
    -        self.settings = ContactSettings(account, str(jid))
    
    231
    +        self.settings = ContactSettings(account, jid)
    
    232 232
     
    
    233 233
             self._avatar_sha = app.storage.cache.get_contact(jid, 'avatar')
    
    234 234
     
    
    ... ... @@ -474,7 +474,7 @@ class GroupchatContact(CommonContact):
    474 474
         def __init__(self, logger: logging.Logger, jid: JID, account: str) -> None:
    
    475 475
             CommonContact.__init__(self, logger, jid, account)
    
    476 476
     
    
    477
    -        self.settings = GroupChatSettings(account, str(jid))
    
    477
    +        self.settings = GroupChatSettings(account, jid)
    
    478 478
     
    
    479 479
         @property
    
    480 480
         def is_groupchat(self) -> bool:
    

  • gajim/common/settings.py
    ... ... @@ -73,7 +73,7 @@
    73 73
     from gajim.common.setting_values import BoolSettings
    
    74 74
     from gajim.common.setting_values import BoolAccountSettings
    
    75 75
     
    
    76
    -SETTING_TYPE = Union[bool, int, str, object, list]
    
    76
    +SETTING_TYPE = Union[bool, int, str, object]
    
    77 77
     
    
    78 78
     
    
    79 79
     log = logging.getLogger('gajim.c.settings')
    
    ... ... @@ -705,27 +705,27 @@ def set_account_setting(self,
    705 705
         @overload
    
    706 706
         def get_group_chat_setting(self,
    
    707 707
                                    account: str,
    
    708
    -                               jid: Union[str, JID],
    
    708
    +                               jid: JID,
    
    709 709
                                    setting: IntGroupChatSettings
    
    710 710
                                    ) -> int: ...
    
    711 711
     
    
    712 712
         @overload
    
    713 713
         def get_group_chat_setting(self,
    
    714 714
                                    account: str,
    
    715
    -                               jid: Union[str, JID],
    
    715
    +                               jid: JID,
    
    716 716
                                    setting: BoolGroupChatSettings
    
    717 717
                                    ) -> bool: ...
    
    718 718
     
    
    719 719
         @overload
    
    720 720
         def get_group_chat_setting(self,
    
    721 721
                                    account: str,
    
    722
    -                               jid: Union[str, JID],
    
    722
    +                               jid: JID,
    
    723 723
                                    setting: StringGroupChatSettings
    
    724 724
                                    ) -> str: ...
    
    725 725
     
    
    726 726
         def get_group_chat_setting(self,
    
    727 727
                                    account: str,
    
    728
    -                               jid: Union[str, JID],
    
    728
    +                               jid: JID,
    
    729 729
                                    setting: AllGroupChatSettings
    
    730 730
                                    ) -> AllGroupChatSettingsT:
    
    731 731
     
    
    ... ... @@ -766,27 +766,27 @@ def get_group_chat_setting(self,
    766 766
         @overload
    
    767 767
         def set_group_chat_setting(self,
    
    768 768
                                    account: str,
    
    769
    -                               jid: str,
    
    769
    +                               jid: JID,
    
    770 770
                                    setting: StringGroupChatSettings,
    
    771 771
                                    value: str) -> None: ...
    
    772 772
     
    
    773 773
         @overload
    
    774 774
         def set_group_chat_setting(self,
    
    775 775
                                    account: str,
    
    776
    -                               jid: str,
    
    776
    +                               jid: JID,
    
    777 777
                                    setting: IntGroupChatSettings,
    
    778 778
                                    value: int) -> None: ...
    
    779 779
     
    
    780 780
         @overload
    
    781 781
         def set_group_chat_setting(self,
    
    782 782
                                    account: str,
    
    783
    -                               jid: str,
    
    783
    +                               jid: JID,
    
    784 784
                                    setting: BoolGroupChatSettings,
    
    785 785
                                    value: bool) -> None: ...
    
    786 786
     
    
    787 787
         def set_group_chat_setting(self,
    
    788 788
                                    account: str,
    
    789
    -                               jid: str,
    
    789
    +                               jid: JID,
    
    790 790
                                    setting: AllGroupChatSettings,
    
    791 791
                                    value: AllGroupChatSettingsT) -> None:
    
    792 792
     
    
    ... ... @@ -851,7 +851,7 @@ def set_group_chat_settings(self,
    851 851
     
    
    852 852
         def get_contact_setting(self,
    
    853 853
                                 account: str,
    
    854
    -                            jid: str,
    
    854
    +                            jid: JID,
    
    855 855
                                 setting: str) -> SETTING_TYPE:
    
    856 856
     
    
    857 857
             if account not in self._account_settings:
    
    ... ... @@ -874,7 +874,7 @@ def get_contact_setting(self,
    874 874
     
    
    875 875
         def set_contact_setting(self,
    
    876 876
                                 account: str,
    
    877
    -                            jid: str,
    
    877
    +                            jid: JID,
    
    878 878
                                 setting: str,
    
    879 879
                                 value: SETTING_TYPE) -> None:
    
    880 880
     
    

  • gajim/common/structs.py
    ... ... @@ -25,6 +25,7 @@
    25 25
     import time
    
    26 26
     from dataclasses import dataclass
    
    27 27
     from dataclasses import fields
    
    28
    +
    
    28 29
     from gi.repository import GLib
    
    29 30
     
    
    30 31
     from nbxmpp.protocol import JID
    
    ... ... @@ -49,7 +50,12 @@ class URI(NamedTuple):
    49 50
     
    
    50 51
     
    
    51 52
     class MUCData:
    
    52
    -    def __init__(self, room_jid, nick, password, config=None):
    
    53
    +    def __init__(self,
    
    54
    +                 room_jid: str,
    
    55
    +                 nick: str,
    
    56
    +                 password: str,
    
    57
    +                 config=None) -> None:
    
    58
    +
    
    53 59
             self._room_jid = JID.from_string(room_jid)
    
    54 60
             self._config = config
    
    55 61
             self.nick = nick
    
    ... ... @@ -60,11 +66,11 @@ def __init__(self, room_jid, nick, password, config=None):
    60 66
             self.subject = None
    
    61 67
     
    
    62 68
         @property
    
    63
    -    def jid(self):
    
    69
    +    def jid(self) -> JID:
    
    64 70
             return self._room_jid
    
    65 71
     
    
    66 72
         @property
    
    67
    -    def occupant_jid(self):
    
    73
    +    def occupant_jid(self) -> JID:
    
    68 74
             return self._room_jid.new_with(resource=self.nick)
    
    69 75
     
    
    70 76
         @property
    
    ... ... @@ -74,23 +80,23 @@ def config(self):
    74 80
     
    
    75 81
     class OutgoingMessage:
    
    76 82
         def __init__(self,
    
    77
    -                 account,
    
    83
    +                 account: str,
    
    78 84
                      contact,
    
    79
    -                 message,
    
    80
    -                 type_,
    
    81
    -                 subject=None,
    
    85
    +                 message: Optional[str],
    
    86
    +                 type_: str,
    
    87
    +                 subject: Optional[str] = None,
    
    82 88
                      chatstate=None,
    
    83
    -                 marker=None,
    
    84
    -                 resource=None,
    
    85
    -                 user_nick=None,
    
    86
    -                 label=None,
    
    89
    +                 marker: Optional[tuple[str, str]] = None,
    
    90
    +                 resource: Optional[str] = None,
    
    91
    +                 user_nick: Optional[str] = None,
    
    92
    +                 label: Optional[str] = None,
    
    87 93
                      control=None,
    
    88
    -                 attention=None,
    
    89
    -                 correct_id=None,
    
    90
    -                 oob_url=None,
    
    94
    +                 attention: Optional[bool] = None,
    
    95
    +                 correct_id: Optional[str] = None,
    
    96
    +                 oob_url: Optional[str] = None,
    
    91 97
                      xhtml=None,
    
    92 98
                      nodes=None,
    
    93
    -                 play_sound=True):
    
    99
    +                 play_sound: bool = True):
    
    94 100
     
    
    95 101
             if type_ not in ('chat', 'groupchat', 'normal', 'headline'):
    
    96 102
                 raise ValueError('Unknown message type: %s' % type_)
    
    ... ... @@ -157,37 +163,37 @@ def copy(self):
    157 163
             return message
    
    158 164
     
    
    159 165
         @property
    
    160
    -    def jid(self):
    
    166
    +    def jid(self) -> JID:
    
    161 167
             return self.contact.jid
    
    162 168
     
    
    163 169
         @property
    
    164
    -    def is_groupchat(self):
    
    170
    +    def is_groupchat(self) -> bool:
    
    165 171
             return self.type_ == 'groupchat'
    
    166 172
     
    
    167 173
         @property
    
    168
    -    def is_chat(self):
    
    174
    +    def is_chat(self) -> bool:
    
    169 175
             return self.type_ == 'chat'
    
    170 176
     
    
    171 177
         @property
    
    172
    -    def is_normal(self):
    
    178
    +    def is_normal(self) -> bool:
    
    173 179
             return self.type_ == 'normal'
    
    174 180
     
    
    175
    -    def set_sent_timestamp(self):
    
    181
    +    def set_sent_timestamp(self) -> None:
    
    176 182
             if self.is_groupchat:
    
    177 183
                 return
    
    178 184
             self.timestamp = time.time()
    
    179 185
     
    
    180 186
         @property
    
    181
    -    def is_encrypted(self):
    
    187
    +    def is_encrypted(self) -> bool:
    
    182 188
             return bool(self.additional_data.get_value('encrypted', 'name', False))
    
    183 189
     
    
    184 190
         @property
    
    185
    -    def msg_iq(self):
    
    191
    +    def msg_iq(self) -> Any:
    
    186 192
             # Backwards compatibility for plugins
    
    187 193
             return self.stanza
    
    188 194
     
    
    189 195
         @msg_iq.setter
    
    190
    -    def msg_iq(self, value):
    
    196
    +    def msg_iq(self, value: Any) -> None:
    
    191 197
             # Backwards compatibility for plugins
    
    192 198
             self.stanza = value
    
    193 199
     
    
    ... ... @@ -245,6 +251,7 @@ def from_presence(cls, properties):
    245 251
                                            role=Role.NONE,
    
    246 252
                                            real_jid=None)
    
    247 253
     
    
    254
    +
    
    248 255
     class VariantMixin:
    
    249 256
     
    
    250 257
         _type_to_variant_funcs = {
    

  • gajim/common/types.py
    ... ... @@ -34,6 +34,7 @@
    34 34
     if TYPE_CHECKING:
    
    35 35
         # pylint: disable=unused-import
    
    36 36
         from gajim.common.client import Client
    
    37
    +    from nbxmpp.client import Client as xmppClient
    
    37 38
         from gajim.common.zeroconf.connection_zeroconf import ConnectionZeroconf
    
    38 39
         from gajim.common.modules.contacts import CommonContact
    
    39 40
         from gajim.common.modules.contacts import BareContact
    
    ... ... @@ -41,6 +42,8 @@
    41 42
         from gajim.common.modules.contacts import GroupchatContact
    
    42 43
         from gajim.common.modules.contacts import GroupchatParticipant
    
    43 44
     
    
    45
    +    ChatContacts = Union[BareContact, GroupchatContact, GroupchatParticipant]
    
    46
    +
    
    44 47
         from gajim.gui_interface import Interface
    
    45 48
         from gajim.common.settings import Settings
    
    46 49
         from gajim.gtk.css_config import CSSConfig
    

  • gajim/gtk/controls/base.py
    ... ... @@ -570,7 +570,7 @@ def mark_as_read(self, send_marker: bool = True) -> None:
    570 570
                 self._client.get_module('ChatMarkers').send_displayed_marker(
    
    571 571
                     self.contact,
    
    572 572
                     self.last_msg_id,
    
    573
    -                self._type)
    
    573
    +                str(self._type))
    
    574 574
                 self.last_msg_id = None
    
    575 575
     
    
    576 576
         def change_encryption(self,
    

  • pyrightconfig.json
    ... ... @@ -12,6 +12,7 @@
    12 12
             "gajim/common/i18n.py",
    
    13 13
             "gajim/common/idle.py",
    
    14 14
             "gajim/common/logging_helpers.py",
    
    15
    +        "gajim/common/modules/chat_markers.py",
    
    15 16
             "gajim/common/passwords.py",
    
    16 17
             "gajim/common/regex.py",
    
    17 18
             "gajim/common/sound.py",