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

Commits:

6 changed files:

Changes:

  • gajim/common/ged.py
    ... ... @@ -114,6 +114,9 @@ class EventHelper:
    114 114
         def __init__(self):
    
    115 115
             self.__event_handlers: list[EventHandlerT] = []
    
    116 116
     
    
    117
    +    def has_events_registered(self) -> bool:
    
    118
    +        return bool(self.__event_handlers)
    
    119
    +
    
    117 120
         def register_event(self,
    
    118 121
                            event_name: str,
    
    119 122
                            priority: int,
    

  • gajim/gtk/account_page.py
    ... ... @@ -21,7 +21,6 @@
    21 21
     from gajim.common import app
    
    22 22
     from gajim.common import ged
    
    23 23
     from gajim.common.const import AvatarSize
    
    24
    -from gajim.common.events import ApplicationEvent
    
    25 24
     from gajim.common.events import SubscribePresenceReceived
    
    26 25
     from gajim.common.events import UnsubscribedPresenceReceived
    
    27 26
     from gajim.common.events import MucInvitation
    
    ... ... @@ -151,6 +150,3 @@ def _muc_invitation_declined(self, event: MucDecline) -> None:
    151 150
             if event.account != self._account:
    
    152 151
                 return
    
    153 152
             self._notification_manager.add_invitation_declined(event)
    154
    -
    
    155
    -    def process_event(self, event: ApplicationEvent) -> None:
    
    156
    -        self._roster.process_event(event)

  • gajim/gtk/chat_stack.py
    ... ... @@ -732,7 +732,6 @@ def process_event(self, event: Any) -> None:
    732 732
             if isinstance(event, events.MessageReceived):
    
    733 733
                 self._on_message_received(event)
    
    734 734
     
    
    735
    -        self._chat_control.process_event(event)
    
    736 735
             self._message_action_box.process_event(event)
    
    737 736
     
    
    738 737
     
    

  • gajim/gtk/control.py
    ... ... @@ -35,6 +35,7 @@
    35 35
     
    
    36 36
     from gajim.common import app
    
    37 37
     from gajim.common import events
    
    38
    +from gajim.common import ged
    
    38 39
     from gajim.common import helpers
    
    39 40
     from gajim.common import types
    
    40 41
     from gajim.common.helpers import get_file_path_from_dnd_dropped_uri
    
    ... ... @@ -152,6 +153,7 @@ def clear(self) -> None:
    152 153
             self._scrolled_view.clear()
    
    153 154
             self._groupchat_state.clear()
    
    154 155
             self._roster.clear()
    
    156
    +        self.unregister_events()
    
    155 157
     
    
    156 158
         def switch_contact(self, contact: Union[BareContact,
    
    157 159
                                                 GroupchatContact,
    
    ... ... @@ -172,6 +174,8 @@ def switch_contact(self, contact: Union[BareContact,
    172 174
     
    
    173 175
             self.encryption = self.get_encryption_state()
    
    174 176
     
    
    177
    +        self._register_events()
    
    178
    +
    
    175 179
             if isinstance(contact, GroupchatParticipant):
    
    176 180
                 contact.multi_connect({
    
    177 181
                     'user-status-show-changed': self._on_user_status_show_changed,
    
    ... ... @@ -206,60 +210,174 @@ def switch_contact(self, contact: Union[BareContact,
    206 210
                 for transfer in transfers:
    
    207 211
                     self.add_file_transfer(transfer)
    
    208 212
     
    
    209
    -    def process_event(self, event: events.MainEventT) -> None:
    
    210
    -        if self._contact is None:
    
    213
    +    def _register_events(self) -> None:
    
    214
    +        if self.has_events_registered():
    
    211 215
                 return
    
    212 216
     
    
    217
    +        self.register_events([
    
    218
    +            ('presence-received', ged.GUI2, self._on_presence_received),
    
    219
    +            ('message-sent', ged.GUI2, self._on_message_sent),
    
    220
    +            ('message-received', ged.GUI2, self._on_message_received),
    
    221
    +            ('mam-message-received', ged.GUI2, self._on_mam_message_received),
    
    222
    +            ('gc-message-received', ged.GUI2, self._on_gc_message_received),
    
    223
    +            ('message-updated', ged.GUI2, self._on_message_updated),
    
    224
    +            ('message-moderated', ged.GUI2, self._on_message_moderated),
    
    225
    +            ('receipt-received', ged.GUI2, self._on_receipt_received),
    
    226
    +            ('displayed-received', ged.GUI2, self._on_displayed_received),
    
    227
    +            ('message-error', ged.GUI2, self._on_message_error),
    
    228
    +            ('call-stopped', ged.GUI2, self._on_call_stopped),
    
    229
    +            ('jingle-request-received',
    
    230
    +             ged.GUI2, self._on_jingle_request_received),
    
    231
    +            ('file-request-received', ged.GUI2, self._on_file_request_event),
    
    232
    +            ('file-request-sent', ged.GUI2, self._on_file_request_event),
    
    233
    +        ])
    
    234
    +
    
    235
    +    def _is_event_processable(self, event: Any) -> bool:
    
    236
    +        if self._contact is None:
    
    237
    +            return False
    
    238
    +
    
    213 239
             if event.account != self._contact.account:
    
    240
    +            return False
    
    241
    +
    
    242
    +        if event.jid != self._contact.jid:
    
    243
    +            return False
    
    244
    +        return True
    
    245
    +
    
    246
    +    def _on_presence_received(self, event: events.PresenceReceived) -> None:
    
    247
    +        if not self._is_event_processable(event):
    
    248
    +            return
    
    249
    +
    
    250
    +        if not app.settings.get('print_status_in_chats'):
    
    251
    +            return
    
    252
    +
    
    253
    +        contact = self.client.get_module('Contacts').get_contact(event.fjid)
    
    254
    +        if isinstance(contact, BareContact):
    
    214 255
                 return
    
    256
    +        self.conversation_view.add_user_status(self.contact.name,
    
    257
    +                                               contact.show.value,
    
    258
    +                                               contact.status)
    
    215 259
     
    
    216
    -        if event.jid not in (self._contact.jid, self._contact.jid.bare):
    
    260
    +    def _on_message_sent(self, event: events.MessageSent) -> None:
    
    261
    +        if not self._is_event_processable(event):
    
    217 262
                 return
    
    218 263
     
    
    219
    -        file_transfer_events = (
    
    220
    -            events.FileRequestReceivedEvent,
    
    221
    -            events.FileRequestSent
    
    222
    -        )
    
    264
    +        if not event.message:
    
    265
    +            return
    
    223 266
     
    
    224
    -        if isinstance(event, file_transfer_events):
    
    225
    -            self.add_jingle_file_transfer(event=event)
    
    267
    +        if self.contact.is_groupchat:
    
    226 268
                 return
    
    227 269
     
    
    228
    -        if isinstance(event, events.JingleRequestReceived):
    
    229
    -            active_jid = app.call_manager.get_active_call_jid()
    
    230
    -            # Don't add a second row if contact upgrades to video
    
    231
    -            if active_jid is None:
    
    232
    -                self.add_call_message(event=event)
    
    270
    +        message_id = event.message_id
    
    271
    +
    
    272
    +        if event.label:
    
    273
    +            displaymarking = event.label.displaymarking
    
    274
    +        else:
    
    275
    +            displaymarking = None
    
    276
    +
    
    277
    +        if event.correct_id:
    
    278
    +            self.conversation_view.correct_message(
    
    279
    +                event.correct_id, event.message, self.get_our_nick())
    
    233 280
                 return
    
    234 281
     
    
    235
    -        if isinstance(event, events.CallStopped):
    
    236
    -            self.conversation_view.update_call_rows()
    
    282
    +        self.add_message(event.message,
    
    283
    +                         'outgoing',
    
    284
    +                         tim=event.timestamp,
    
    285
    +                         displaymarking=displaymarking,
    
    286
    +                         message_id=message_id,
    
    287
    +                         additional_data=event.additional_data)
    
    288
    +
    
    289
    +    def _on_message_received(self, event: events.MessageReceived) -> None:
    
    290
    +        if not self._is_event_processable(event):
    
    237 291
                 return
    
    238 292
     
    
    239
    -        if isinstance(event, events.MessageReceived) and not self.is_groupchat:
    
    240
    -            self._on_message_received(event)
    
    293
    +        if self.is_groupchat:
    
    241 294
                 return
    
    242 295
     
    
    243
    -        if isinstance(event, events.MessageSent):
    
    244
    -            self._on_message_sent(event)
    
    296
    +        if not event.msgtxt:
    
    245 297
                 return
    
    246 298
     
    
    247
    -        if isinstance(event, events.MessageError):
    
    248
    -            self._on_message_error(event)
    
    299
    +        kind = 'incoming'
    
    300
    +        if event.properties.is_sent_carbon:
    
    301
    +            kind = 'outgoing'
    
    302
    +
    
    303
    +        self.add_message(event.msgtxt,
    
    304
    +                         kind,
    
    305
    +                         tim=event.properties.timestamp,
    
    306
    +                         displaymarking=event.displaymarking,
    
    307
    +                         msg_log_id=event.msg_log_id,
    
    308
    +                         message_id=event.properties.id,
    
    309
    +                         stanza_id=event.stanza_id,
    
    310
    +                         additional_data=event.additional_data)
    
    311
    +
    
    312
    +    def _on_mam_message_received(self,
    
    313
    +                                 event: events.MamMessageReceived) -> None:
    
    314
    +
    
    315
    +        if not self._is_event_processable(event):
    
    249 316
                 return
    
    250 317
     
    
    251
    -        method_name = event.name.replace('-', '_')
    
    252
    -        method_name = f'_on_{method_name}'
    
    253
    -        getattr(self, method_name)(event)
    
    318
    +        if isinstance(self.contact, GroupchatContact):
    
    254 319
     
    
    255
    -    def _on_message_error(self, event: events.MessageError) -> None:
    
    256
    -        self.conversation_view.show_error(event.message_id, event.error)
    
    320
    +            if not event.properties.type.is_groupchat:
    
    321
    +                return
    
    322
    +            if event.archive_jid != self.contact.jid:
    
    323
    +                return
    
    324
    +            self.add_muc_message(event.msgtxt,
    
    325
    +                                 tim=event.properties.mam.timestamp,
    
    326
    +                                 contact=event.properties.muc_nickname,
    
    327
    +                                 message_id=event.properties.id,
    
    328
    +                                 stanza_id=event.stanza_id,
    
    329
    +                                 additional_data=event.additional_data)
    
    330
    +
    
    331
    +        else:
    
    332
    +
    
    333
    +            if event.properties.is_muc_pm:
    
    334
    +                if not event.properties.jid == self.contact.jid:
    
    335
    +                    return
    
    336
    +            else:
    
    337
    +                if not event.properties.jid.bare_match(self.contact.jid):
    
    338
    +                    return
    
    339
    +
    
    340
    +            kind = 'incoming'
    
    341
    +            if event.kind == KindConstant.CHAT_MSG_SENT:
    
    342
    +                kind = 'outgoing'
    
    343
    +
    
    344
    +            self.add_message(event.msgtxt,
    
    345
    +                             kind,
    
    346
    +                             tim=event.properties.mam.timestamp,
    
    347
    +                             message_id=event.properties.id,
    
    348
    +                             stanza_id=event.stanza_id,
    
    349
    +                             additional_data=event.additional_data)
    
    350
    +
    
    351
    +    def _on_gc_message_received(self, event: events.GcMessageReceived) -> None:
    
    352
    +        if not self._is_event_processable(event):
    
    353
    +            return
    
    354
    +
    
    355
    +        if event.properties.muc_nickname is None:
    
    356
    +            # message from server
    
    357
    +            self.add_muc_message(event.msgtxt,
    
    358
    +                                 tim=event.properties.timestamp,
    
    359
    +                                 displaymarking=event.displaymarking,
    
    360
    +                                 additional_data=event.additional_data)
    
    361
    +        else:
    
    362
    +            self.add_muc_message(event.msgtxt,
    
    363
    +                                 tim=event.properties.timestamp,
    
    364
    +                                 contact=event.properties.muc_nickname,
    
    365
    +                                 displaymarking=event.displaymarking,
    
    366
    +                                 message_id=event.properties.id,
    
    367
    +                                 stanza_id=event.stanza_id,
    
    368
    +                                 additional_data=event.additional_data)
    
    257 369
     
    
    258 370
         def _on_message_updated(self, event: events.MessageUpdated) -> None:
    
    371
    +        if not self._is_event_processable(event):
    
    372
    +            return
    
    373
    +
    
    259 374
             self.conversation_view.correct_message(
    
    260 375
                 event.correct_id, event.msgtxt, event.nickname)
    
    261 376
     
    
    262 377
         def _on_message_moderated(self, event: events.MessageModerated) -> None:
    
    378
    +        if not self._is_event_processable(event):
    
    379
    +            return
    
    380
    +
    
    263 381
             text = get_retraction_text(
    
    264 382
                 self.contact.account,
    
    265 383
                 event.moderation.moderator_jid,
    
    ... ... @@ -267,6 +385,52 @@ def _on_message_moderated(self, event: events.MessageModerated) -> None:
    267 385
             self.conversation_view.show_message_retraction(
    
    268 386
                 event.moderation.stanza_id, text)
    
    269 387
     
    
    388
    +    def _on_receipt_received(self, event: events.ReceiptReceived) -> None:
    
    389
    +        if not self._is_event_processable(event):
    
    390
    +            return
    
    391
    +
    
    392
    +        self.conversation_view.show_receipt(event.receipt_id)
    
    393
    +
    
    394
    +    def _on_displayed_received(self, event: events.DisplayedReceived) -> None:
    
    395
    +        if not self._is_event_processable(event):
    
    396
    +            return
    
    397
    +
    
    398
    +        self.conversation_view.set_read_marker(event.marker_id)
    
    399
    +
    
    400
    +    def _on_message_error(self, event: events.MessageError) -> None:
    
    401
    +        if not self._is_event_processable(event):
    
    402
    +            return
    
    403
    +
    
    404
    +        self.conversation_view.show_error(event.message_id, event.error)
    
    405
    +
    
    406
    +    def _on_call_stopped(self, event: events.CallStopped) -> None:
    
    407
    +        if not self._is_event_processable(event):
    
    408
    +            return
    
    409
    +
    
    410
    +        self.conversation_view.update_call_rows()
    
    411
    +
    
    412
    +    def _on_jingle_request_received(self,
    
    413
    +                                    event: events.JingleRequestReceived
    
    414
    +                                    ) -> None:
    
    415
    +
    
    416
    +        if not self._is_event_processable(event):
    
    417
    +            return
    
    418
    +
    
    419
    +        active_jid = app.call_manager.get_active_call_jid()
    
    420
    +        # Don't add a second row if contact upgrades to video
    
    421
    +        if active_jid is None:
    
    422
    +            self.add_call_message(event=event)
    
    423
    +
    
    424
    +    def _on_file_request_event(self,
    
    425
    +                               event: Union[events.FileRequestReceivedEvent,
    
    426
    +                                            events.FileRequestSent]
    
    427
    +                               ) -> None:
    
    428
    +
    
    429
    +        if not self._is_event_processable(event):
    
    430
    +            return
    
    431
    +
    
    432
    +        self.add_jingle_file_transfer(event=event)
    
    433
    +
    
    270 434
         @property
    
    271 435
         def is_chat(self) -> bool:
    
    272 436
             return isinstance(self.contact, BareContact)
    
    ... ... @@ -279,9 +443,6 @@ def is_privatechat(self) -> bool:
    279 443
         def is_groupchat(self) -> bool:
    
    280 444
             return isinstance(self.contact, GroupchatContact)
    
    281 445
     
    
    282
    -    def _on_ping_event(self, event: events.PingEventT) -> None:
    
    283
    -        raise NotImplementedError
    
    284
    -
    
    285 446
         def mark_as_read(self, send_marker: bool = True) -> None:
    
    286 447
             self._jump_to_end_button.reset_unread_count()
    
    287 448
     
    
    ... ... @@ -523,91 +684,6 @@ def add_messages(self, messages: list[ConversationRow]):
    523 684
                     marker=msg.marker,
    
    524 685
                     error=msg.error)
    
    525 686
     
    
    526
    -    def _on_mam_message_received(self,
    
    527
    -                                 event: events.MamMessageReceived) -> None:
    
    528
    -
    
    529
    -        if isinstance(self.contact, GroupchatContact):
    
    530
    -
    
    531
    -            if not event.properties.type.is_groupchat:
    
    532
    -                return
    
    533
    -            if event.archive_jid != self.contact.jid:
    
    534
    -                return
    
    535
    -            self.add_muc_message(event.msgtxt,
    
    536
    -                                 tim=event.properties.mam.timestamp,
    
    537
    -                                 contact=event.properties.muc_nickname,
    
    538
    -                                 message_id=event.properties.id,
    
    539
    -                                 stanza_id=event.stanza_id,
    
    540
    -                                 additional_data=event.additional_data)
    
    541
    -
    
    542
    -        else:
    
    543
    -
    
    544
    -            if event.properties.is_muc_pm:
    
    545
    -                if not event.properties.jid == self.contact.jid:
    
    546
    -                    return
    
    547
    -            else:
    
    548
    -                if not event.properties.jid.bare_match(self.contact.jid):
    
    549
    -                    return
    
    550
    -
    
    551
    -            kind = 'incoming'
    
    552
    -            if event.kind == KindConstant.CHAT_MSG_SENT:
    
    553
    -                kind = 'outgoing'
    
    554
    -
    
    555
    -            self.add_message(event.msgtxt,
    
    556
    -                             kind,
    
    557
    -                             tim=event.properties.mam.timestamp,
    
    558
    -                             message_id=event.properties.id,
    
    559
    -                             stanza_id=event.stanza_id,
    
    560
    -                             additional_data=event.additional_data)
    
    561
    -
    
    562
    -    def _on_message_received(self, event: events.MessageReceived) -> None:
    
    563
    -        if not event.msgtxt:
    
    564
    -            return
    
    565
    -
    
    566
    -        kind = 'incoming'
    
    567
    -        if event.properties.is_sent_carbon:
    
    568
    -            kind = 'outgoing'
    
    569
    -
    
    570
    -        self.add_message(event.msgtxt,
    
    571
    -                         kind,
    
    572
    -                         tim=event.properties.timestamp,
    
    573
    -                         displaymarking=event.displaymarking,
    
    574
    -                         msg_log_id=event.msg_log_id,
    
    575
    -                         message_id=event.properties.id,
    
    576
    -                         stanza_id=event.stanza_id,
    
    577
    -                         additional_data=event.additional_data)
    
    578
    -
    
    579
    -    def _on_message_sent(self, event: events.MessageSent) -> None:
    
    580
    -        if not event.message:
    
    581
    -            return
    
    582
    -
    
    583
    -        if self.contact.is_groupchat:
    
    584
    -            return
    
    585
    -
    
    586
    -        message_id = event.message_id
    
    587
    -
    
    588
    -        if event.label:
    
    589
    -            displaymarking = event.label.displaymarking
    
    590
    -        else:
    
    591
    -            displaymarking = None
    
    592
    -
    
    593
    -        if event.correct_id:
    
    594
    -            self.conversation_view.correct_message(
    
    595
    -                event.correct_id, event.message, self.get_our_nick())
    
    596
    -            return
    
    597
    -
    
    598
    -        self.add_message(event.message,
    
    599
    -                         'outgoing',
    
    600
    -                         tim=event.timestamp,
    
    601
    -                         displaymarking=displaymarking,
    
    602
    -                         message_id=message_id,
    
    603
    -                         additional_data=event.additional_data)
    
    604
    -
    
    605
    -    def _on_receipt_received(self, event: events.ReceiptReceived) -> None:
    
    606
    -        self.conversation_view.show_receipt(event.receipt_id)
    
    607
    -
    
    608
    -    def _on_displayed_received(self, event: events.DisplayedReceived) -> None:
    
    609
    -        self.conversation_view.set_read_marker(event.marker_id)
    
    610
    -
    
    611 687
         def add_message(self,
    
    612 688
                         text: str,
    
    613 689
                         kind: str,
    
    ... ... @@ -634,17 +710,6 @@ def add_message(self,
    634 710
                               stanza_id=stanza_id,
    
    635 711
                               additional_data=additional_data)
    
    636 712
     
    
    637
    -    def _on_presence_received(self, event: events.PresenceReceived) -> None:
    
    638
    -        if not app.settings.get('print_status_in_chats'):
    
    639
    -            return
    
    640
    -
    
    641
    -        contact = self.client.get_module('Contacts').get_contact(event.fjid)
    
    642
    -        if isinstance(contact, BareContact):
    
    643
    -            return
    
    644
    -        self.conversation_view.add_user_status(self.contact.name,
    
    645
    -                                               contact.show.value,
    
    646
    -                                               contact.status)
    
    647
    -
    
    648 713
         def _on_user_nickname_changed(self,
    
    649 714
                                       _user_contact: GroupchatParticipant,
    
    650 715
                                       _signal_name: str,
    
    ... ... @@ -708,9 +773,6 @@ def _on_user_status_show_changed(self,
    708 773
                                                                    status=status)
    
    709 774
             self.add_info_message(message)
    
    710 775
     
    
    711
    -    def _on_muc_disco_update(self, event: events.MucDiscoUpdate) -> None:
    
    712
    -        pass
    
    713
    -
    
    714 776
         def invite(self, invited_jid: JID) -> None:
    
    715 777
             # TODO: Remove, used by command system
    
    716 778
             self.client.get_module('MUC').invite(
    
    ... ... @@ -743,22 +805,6 @@ def on_approve() -> None:
    743 805
                                    callback=on_approve)],
    
    744 806
                 modal=False).show()
    
    745 807
     
    
    746
    -    def _on_gc_message_received(self, event: events.GcMessageReceived) -> None:
    
    747
    -        if event.properties.muc_nickname is None:
    
    748
    -            # message from server
    
    749
    -            self.add_muc_message(event.msgtxt,
    
    750
    -                                 tim=event.properties.timestamp,
    
    751
    -                                 displaymarking=event.displaymarking,
    
    752
    -                                 additional_data=event.additional_data)
    
    753
    -        else:
    
    754
    -            self.add_muc_message(event.msgtxt,
    
    755
    -                                 tim=event.properties.timestamp,
    
    756
    -                                 contact=event.properties.muc_nickname,
    
    757
    -                                 displaymarking=event.displaymarking,
    
    758
    -                                 message_id=event.properties.id,
    
    759
    -                                 stanza_id=event.stanza_id,
    
    760
    -                                 additional_data=event.additional_data)
    
    761
    -
    
    762 808
         def add_muc_message(self,
    
    763 809
                             text: str,
    
    764 810
                             tim: float,
    

  • gajim/gtk/main_stack.py
    ... ... @@ -94,6 +94,10 @@ def process_event(self, event: ApplicationEvent) -> None:
    94 94
             for page in pages:
    
    95 95
                 if page is empty_box:
    
    96 96
                     continue
    
    97
    +
    
    98
    +            if isinstance(page, AccountPage):
    
    99
    +                continue
    
    100
    +
    
    97 101
                 page.process_event(event)
    
    98 102
     
    
    99 103
         def _on_chat_selected(self,
    

  • gajim/gtk/roster.py
    ... ... @@ -56,8 +56,6 @@
    56 56
     log = logging.getLogger('gajim.gui.roster')
    
    57 57
     
    
    58 58
     
    
    59
    -HANDLED_EVENTS = []
    
    60
    -
    
    61 59
     DEFAULT_GROUP = _('Contacts')
    
    62 60
     
    
    63 61
     
    
    ... ... @@ -727,10 +725,6 @@ def _clear(self):
    727 725
             self._group_refs.clear()
    
    728 726
             self._store.clear()
    
    729 727
     
    
    730
    -    def process_event(self, event: ApplicationEvent) -> None:
    
    731
    -        if event.name not in HANDLED_EVENTS:
    
    732
    -            return
    
    733
    -
    
    734 728
         def _on_destroy(self, _roster: Roster) -> None:
    
    735 729
             app.settings.disconnect_signals(self)
    
    736 730
             self._contact_refs.clear()