Daniel Brötzmann pushed to branch newcontrol at gajim / gajim

Commits:

7 changed files:

Changes:

  • gajim/common/events.py
    ... ... @@ -593,6 +593,9 @@ class PingReply(ApplicationEvent):
    593 593
         seconds: float
    
    594 594
     
    
    595 595
     
    
    596
    +PingEventT = Union[PingSent, PingReply, PingError]
    
    597
    +
    
    598
    +
    
    596 599
     @dataclass
    
    597 600
     class SecCatalogReceived(ApplicationEvent):
    
    598 601
         name: str = field(init=False, default='sec-catalog-received')
    

  • gajim/common/types.py
    ... ... @@ -16,10 +16,7 @@
    16 16
     
    
    17 17
     from typing import Any
    
    18 18
     from typing import Callable
    
    19
    -from typing import Dict
    
    20
    -from typing import List
    
    21 19
     from typing import Optional
    
    22
    -from typing import Tuple
    
    23 20
     from typing import Union
    
    24 21
     from typing import TYPE_CHECKING
    
    25 22
     
    
    ... ... @@ -62,15 +59,15 @@
    62 59
     
    
    63 60
     # PEP
    
    64 61
     PEPNotifyCallback = Callable[[nbxmpp.JID, nbxmpp.Node], None]
    
    65
    -PEPHandlersDict = Dict[str, List[PEPNotifyCallback]]
    
    62
    +PEPHandlersDict = dict[str, list[PEPNotifyCallback]]
    
    66 63
     
    
    67 64
     # Plugins
    
    68
    -PluginExtensionPoints = Dict[str, Tuple[Optional[Callable[..., None]],
    
    65
    +PluginExtensionPoints = dict[str, tuple[Optional[Callable[..., None]],
    
    69 66
                                             Optional[Callable[..., None]]]]
    
    70 67
     
    
    71 68
     SettingsT = Union['Settings']
    
    72 69
     
    
    73
    -BookmarksDict = Dict[JID, BookmarkData]
    
    70
    +BookmarksDict = dict[JID, BookmarkData]
    
    74 71
     
    
    75 72
     GdkPixbufType = Union[GdkPixbuf.Pixbuf, GdkPixbuf.PixbufAnimation]
    
    76 73
     
    

  • gajim/gtk/controls/base.py
    ... ... @@ -202,9 +202,9 @@ def __init__(self, widget_name: str, account: str, jid: JID) -> None:
    202 202
             app.plugin_manager.gui_extension_point('chat_control_base', self)
    
    203 203
     
    
    204 204
             self.register_events([
    
    205
    -            ('ping-sent', ged.GUI1, self._nec_ping),
    
    206
    -            ('ping-reply', ged.GUI1, self._nec_ping),
    
    207
    -            ('ping-error', ged.GUI1, self._nec_ping),
    
    205
    +            ('ping-sent', ged.GUI1, self._on_ping_event),
    
    206
    +            ('ping-reply', ged.GUI1, self._on_ping_event),
    
    207
    +            ('ping-error', ged.GUI1, self._on_ping_event),
    
    208 208
             ])
    
    209 209
     
    
    210 210
             # This is basically a very nasty hack to surpass the inability
    
    ... ... @@ -306,7 +306,7 @@ def is_privatechat(self) -> bool:
    306 306
         def is_groupchat(self) -> bool:
    
    307 307
             return self._type.is_groupchat
    
    308 308
     
    
    309
    -    def _nec_ping(self, obj):
    
    309
    +    def _on_ping_event(self, event: events.PingEventT) -> None:
    
    310 310
             raise NotImplementedError
    
    311 311
     
    
    312 312
         def mark_as_read(self, send_marker: bool = True) -> None:
    

  • gajim/gtk/controls/chat.py
    ... ... @@ -169,7 +169,7 @@ def _on_receipt_received(self, event: events.ReceiptReceived) -> None:
    169 169
         def _on_displayed_received(self, event: events.DisplayedReceived) -> None:
    
    170 170
             self.conversation_view.set_read_marker(event.marker_id)
    
    171 171
     
    
    172
    -    def _nec_ping(self, event: events.ApplicationEvent):
    
    172
    +    def _on_ping_event(self, event: events.PingEventT) -> None:
    
    173 173
             if self.contact != event.contact:
    
    174 174
                 return
    
    175 175
             if isinstance(event, events.PingSent):
    
    ... ... @@ -177,7 +177,7 @@ def _nec_ping(self, event: events.ApplicationEvent):
    177 177
             elif isinstance(event, events.PingReply):
    
    178 178
                 self.add_info_message(
    
    179 179
                     _('Pong! (%s seconds)') % event.seconds)
    
    180
    -        elif isinstance(event, events.PingError):
    
    180
    +        else:
    
    181 181
                 self.add_info_message(event.error)
    
    182 182
     
    
    183 183
         def add_message(self,
    

  • gajim/gtk/controls/groupchat.py
    ... ... @@ -184,6 +184,7 @@ def _on_room_voice_request(self,
    184 184
                                    properties: MessageProperties
    
    185 185
                                    ) -> None:
    
    186 186
             voice_request = properties.voice_request
    
    187
    +        assert voice_request is not None
    
    187 188
     
    
    188 189
             def on_approve() -> None:
    
    189 190
                 self._client.get_module('MUC').approve_voice_request(
    
    ... ... @@ -292,6 +293,7 @@ def _on_room_config_changed(self,
    292 293
             # http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify
    
    293 294
     
    
    294 295
             status_codes = properties.muc_status_codes
    
    296
    +        assert status_codes is not None
    
    295 297
     
    
    296 298
             changes: list[str] = []
    
    297 299
             if StatusCode.SHOWING_UNAVAILABLE in status_codes:
    
    ... ... @@ -329,7 +331,7 @@ def _on_room_config_changed(self,
    329 331
                 self.add_info_message(change)
    
    330 332
     
    
    331 333
         @event_filter(['account'])
    
    332
    -    def _nec_ping(self, event: events.ApplicationEvent) -> None:
    
    334
    +    def _on_ping_event(self, event: events.PingEventT) -> None:
    
    333 335
             if not event.contact.is_groupchat:
    
    334 336
                 return
    
    335 337
     
    
    ... ... @@ -340,17 +342,19 @@ def _nec_ping(self, event: events.ApplicationEvent) -> None:
    340 342
             if isinstance(event, events.PingSent):
    
    341 343
                 self.add_info_message(_('Ping? (%s)') % nick)
    
    342 344
             elif isinstance(event, events.PingReply):
    
    343
    -            self.add_info_message(
    
    344
    -                _('Pong! (%(nick)s %(delay)s s.)') % {'nick': nick,
    
    345
    -                                                      'delay': event.seconds})
    
    346
    -        elif isinstance(event, events.PingError):
    
    345
    +            self.add_info_message(_('Pong! (%(nick)s %(delay)s s.)') % {
    
    346
    +                'nick': nick,
    
    347
    +                'delay': event.seconds})
    
    348
    +        else:
    
    347 349
                 self.add_info_message(event.error)
    
    348 350
     
    
    349 351
         def _set_control_active(self) -> None:
    
    352
    +        assert self.roster is not None
    
    350 353
             self.roster.initial_draw()
    
    351 354
             self.conversation_view.update_avatars()
    
    352 355
     
    
    353 356
         def _set_control_inactive(self) -> None:
    
    357
    +        assert self.roster is not None
    
    354 358
             self.roster.enable_sort(False)
    
    355 359
             self.roster.clear()
    
    356 360
     
    
    ... ... @@ -403,6 +407,8 @@ def _on_user_nickname_changed(self,
    403 407
                                       properties: MessageProperties
    
    404 408
                                       ) -> None:
    
    405 409
             nick = user_contact.name
    
    410
    +
    
    411
    +        assert properties.muc_user is not None
    
    406 412
             new_nick = properties.muc_user.nick
    
    407 413
             if properties.is_muc_self_presence:
    
    408 414
                 message = _('You are now known as %s') % new_nick
    
    ... ... @@ -433,6 +439,8 @@ def _on_user_affiliation_changed(self,
    433 439
                                          ) -> None:
    
    434 440
             affiliation = helpers.get_uf_affiliation(user_contact.affiliation)
    
    435 441
             nick = user_contact.name
    
    442
    +
    
    443
    +        assert properties.muc_user is not None
    
    436 444
             reason = properties.muc_user.reason
    
    437 445
             reason = '' if reason is None else f': {reason}'
    
    438 446
     
    
    ... ... @@ -464,6 +472,8 @@ def _on_user_role_changed(self,
    464 472
                                   ) -> None:
    
    465 473
             role = helpers.get_uf_role(user_contact.role)
    
    466 474
             nick = user_contact.name
    
    475
    +
    
    476
    +        assert properties.muc_user is not None
    
    467 477
             reason = properties.muc_user.reason
    
    468 478
             reason = '' if reason is None else f': {reason}'
    
    469 479
     
    
    ... ... @@ -492,6 +502,7 @@ def _on_room_kicked(self,
    492 502
                             ) -> None:
    
    493 503
             status_codes = properties.muc_status_codes or []
    
    494 504
     
    
    505
    +        assert properties.muc_user is not None
    
    495 506
             reason = properties.muc_user.reason
    
    496 507
             reason = '' if reason is None else f': {reason}'
    
    497 508
     
    
    ... ... @@ -550,6 +561,7 @@ def _on_user_left(self,
    550 561
             status_codes = properties.muc_status_codes or []
    
    551 562
             nick = user_contact.name
    
    552 563
     
    
    564
    +        assert properties.muc_user is not None
    
    553 565
             reason = properties.muc_user.reason
    
    554 566
             reason = '' if reason is None else f': {reason}'
    
    555 567
     
    

  • gajim/gtk/controls/private.py
    ... ... @@ -35,7 +35,6 @@
    35 35
     from gajim.gui.controls.chat import ChatControl
    
    36 36
     from gajim.command_system.implementation.hosts import PrivateChatCommands
    
    37 37
     
    
    38
    -from gajim.gui.dialogs import ErrorDialog
    
    39 38
     from gajim.gui.const import ControlType
    
    40 39
     
    
    41 40
     
    
    ... ... @@ -78,6 +77,8 @@ def _on_user_nickname_changed(self,
    78 77
                                       ) -> None:
    
    79 78
             # TODO
    
    80 79
             nick = properties.muc_nickname
    
    80
    +
    
    81
    +        assert properties.muc_user is not None
    
    81 82
             new_nick = properties.muc_user.nick
    
    82 83
             if properties.is_muc_self_presence:
    
    83 84
                 message = _('You are now known as %s') % new_nick
    
    ... ... @@ -110,31 +111,3 @@ def _on_user_status_show_changed(self,
    110 111
                                                                    show=show,
    
    111 112
                                                                    status=status)
    
    112 113
             self.add_info_message(message)
    113
    -
    
    114
    -    def send_message(self,
    
    115
    -                     message: str,
    
    116
    -                     process_commands: bool = True,
    
    117
    -                     attention: bool = False
    
    118
    -                     ) -> None:
    
    119
    -        """
    
    120
    -        Call this method to send the message
    
    121
    -        """
    
    122
    -        message = helpers.remove_invalid_xml_chars(message)
    
    123
    -        if not message:
    
    124
    -            return
    
    125
    -
    
    126
    -        # We need to make sure that we can still send through the room and that
    
    127
    -        # the recipient did not go away
    
    128
    -        if not self.contact.is_available:
    
    129
    -            ErrorDialog(
    
    130
    -                _('Sending private message failed'),
    
    131
    -                _('You are no longer joined "%(room)s" or '
    
    132
    -                  '"%(nick)s" has left the chat.') % {
    
    133
    -                      'room': self.room_name,
    
    134
    -                      'nick': self.contact.name})
    
    135
    -            return
    
    136
    -
    
    137
    -        ChatControl.send_message(self,
    
    138
    -                                 message,
    
    139
    -                                 process_commands=process_commands,
    
    140
    -                                 attention=attention)

  • pyrightconfig.json
    ... ... @@ -41,6 +41,7 @@
    41 41
             "gajim/common/sound.py",
    
    42 42
             "gajim/common/storage/",
    
    43 43
             "gajim/common/task_manager.py",
    
    44
    +        "gajim/gtk/controls/private.py",
    
    44 45
             "gajim/gtk/conversation",
    
    45 46
             "gajim/gtk/about.py",
    
    46 47
             "gajim/gtk/account_page.py",