Daniel Brötzmann pushed to branch newcontrol at gajim / gajim
Commits: b871f524 by wurstsalat at 2022-07-20T20:24:38+02:00 Types: Use python’s integrated types
- - - - - f2bcbe02 by wurstsalat at 2022-07-20T20:25:05+02:00 PrivateChatControl: Remove unused code
- - - - - 57341420 by wurstsalat at 2022-07-20T20:27:03+02:00 Controls: Typing
- - - - -
7 changed files:
- gajim/common/events.py - gajim/common/types.py - gajim/gtk/controls/base.py - gajim/gtk/controls/chat.py - gajim/gtk/controls/groupchat.py - gajim/gtk/controls/private.py - pyrightconfig.json
Changes:
===================================== gajim/common/events.py ===================================== @@ -593,6 +593,9 @@ class PingReply(ApplicationEvent): seconds: float
+PingEventT = Union[PingSent, PingReply, PingError] + + @dataclass class SecCatalogReceived(ApplicationEvent): name: str = field(init=False, default='sec-catalog-received')
===================================== gajim/common/types.py ===================================== @@ -16,10 +16,7 @@
from typing import Any from typing import Callable -from typing import Dict -from typing import List from typing import Optional -from typing import Tuple from typing import Union from typing import TYPE_CHECKING
@@ -62,15 +59,15 @@
# PEP PEPNotifyCallback = Callable[[nbxmpp.JID, nbxmpp.Node], None] -PEPHandlersDict = Dict[str, List[PEPNotifyCallback]] +PEPHandlersDict = dict[str, list[PEPNotifyCallback]]
# Plugins -PluginExtensionPoints = Dict[str, Tuple[Optional[Callable[..., None]], +PluginExtensionPoints = dict[str, tuple[Optional[Callable[..., None]], Optional[Callable[..., None]]]]
SettingsT = Union['Settings']
-BookmarksDict = Dict[JID, BookmarkData] +BookmarksDict = dict[JID, BookmarkData]
GdkPixbufType = Union[GdkPixbuf.Pixbuf, GdkPixbuf.PixbufAnimation]
===================================== gajim/gtk/controls/base.py ===================================== @@ -202,9 +202,9 @@ def __init__(self, widget_name: str, account: str, jid: JID) -> None: app.plugin_manager.gui_extension_point('chat_control_base', self)
self.register_events([ - ('ping-sent', ged.GUI1, self._nec_ping), - ('ping-reply', ged.GUI1, self._nec_ping), - ('ping-error', ged.GUI1, self._nec_ping), + ('ping-sent', ged.GUI1, self._on_ping_event), + ('ping-reply', ged.GUI1, self._on_ping_event), + ('ping-error', ged.GUI1, self._on_ping_event), ])
# This is basically a very nasty hack to surpass the inability @@ -306,7 +306,7 @@ def is_privatechat(self) -> bool: def is_groupchat(self) -> bool: return self._type.is_groupchat
- def _nec_ping(self, obj): + def _on_ping_event(self, event: events.PingEventT) -> None: raise NotImplementedError
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: def _on_displayed_received(self, event: events.DisplayedReceived) -> None: self.conversation_view.set_read_marker(event.marker_id)
- def _nec_ping(self, event: events.ApplicationEvent): + def _on_ping_event(self, event: events.PingEventT) -> None: if self.contact != event.contact: return if isinstance(event, events.PingSent): @@ -177,7 +177,7 @@ def _nec_ping(self, event: events.ApplicationEvent): elif isinstance(event, events.PingReply): self.add_info_message( _('Pong! (%s seconds)') % event.seconds) - elif isinstance(event, events.PingError): + else: self.add_info_message(event.error)
def add_message(self,
===================================== gajim/gtk/controls/groupchat.py ===================================== @@ -184,6 +184,7 @@ def _on_room_voice_request(self, properties: MessageProperties ) -> None: voice_request = properties.voice_request + assert voice_request is not None
def on_approve() -> None: self._client.get_module('MUC').approve_voice_request( @@ -292,6 +293,7 @@ def _on_room_config_changed(self, # http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify
status_codes = properties.muc_status_codes + assert status_codes is not None
changes: list[str] = [] if StatusCode.SHOWING_UNAVAILABLE in status_codes: @@ -329,7 +331,7 @@ def _on_room_config_changed(self, self.add_info_message(change)
@event_filter(['account']) - def _nec_ping(self, event: events.ApplicationEvent) -> None: + def _on_ping_event(self, event: events.PingEventT) -> None: if not event.contact.is_groupchat: return
@@ -340,17 +342,19 @@ def _nec_ping(self, event: events.ApplicationEvent) -> None: if isinstance(event, events.PingSent): self.add_info_message(_('Ping? (%s)') % nick) elif isinstance(event, events.PingReply): - self.add_info_message( - _('Pong! (%(nick)s %(delay)s s.)') % {'nick': nick, - 'delay': event.seconds}) - elif isinstance(event, events.PingError): + self.add_info_message(_('Pong! (%(nick)s %(delay)s s.)') % { + 'nick': nick, + 'delay': event.seconds}) + else: self.add_info_message(event.error)
def _set_control_active(self) -> None: + assert self.roster is not None self.roster.initial_draw() self.conversation_view.update_avatars()
def _set_control_inactive(self) -> None: + assert self.roster is not None self.roster.enable_sort(False) self.roster.clear()
@@ -403,6 +407,8 @@ def _on_user_nickname_changed(self, properties: MessageProperties ) -> None: nick = user_contact.name + + assert properties.muc_user is not None new_nick = properties.muc_user.nick if properties.is_muc_self_presence: message = _('You are now known as %s') % new_nick @@ -433,6 +439,8 @@ def _on_user_affiliation_changed(self, ) -> None: affiliation = helpers.get_uf_affiliation(user_contact.affiliation) nick = user_contact.name + + assert properties.muc_user is not None reason = properties.muc_user.reason reason = '' if reason is None else f': {reason}'
@@ -464,6 +472,8 @@ def _on_user_role_changed(self, ) -> None: role = helpers.get_uf_role(user_contact.role) nick = user_contact.name + + assert properties.muc_user is not None reason = properties.muc_user.reason reason = '' if reason is None else f': {reason}'
@@ -492,6 +502,7 @@ def _on_room_kicked(self, ) -> None: status_codes = properties.muc_status_codes or []
+ assert properties.muc_user is not None reason = properties.muc_user.reason reason = '' if reason is None else f': {reason}'
@@ -550,6 +561,7 @@ def _on_user_left(self, status_codes = properties.muc_status_codes or [] nick = user_contact.name
+ assert properties.muc_user is not None reason = properties.muc_user.reason reason = '' if reason is None else f': {reason}'
===================================== gajim/gtk/controls/private.py ===================================== @@ -35,7 +35,6 @@ from gajim.gui.controls.chat import ChatControl from gajim.command_system.implementation.hosts import PrivateChatCommands
-from gajim.gui.dialogs import ErrorDialog from gajim.gui.const import ControlType
@@ -78,6 +77,8 @@ def _on_user_nickname_changed(self, ) -> None: # TODO nick = properties.muc_nickname + + assert properties.muc_user is not None new_nick = properties.muc_user.nick if properties.is_muc_self_presence: message = _('You are now known as %s') % new_nick @@ -110,31 +111,3 @@ def _on_user_status_show_changed(self, show=show, status=status) self.add_info_message(message) - - def send_message(self, - message: str, - process_commands: bool = True, - attention: bool = False - ) -> None: - """ - Call this method to send the message - """ - message = helpers.remove_invalid_xml_chars(message) - if not message: - return - - # We need to make sure that we can still send through the room and that - # the recipient did not go away - if not self.contact.is_available: - ErrorDialog( - _('Sending private message failed'), - _('You are no longer joined "%(room)s" or ' - '"%(nick)s" has left the chat.') % { - 'room': self.room_name, - 'nick': self.contact.name}) - return - - ChatControl.send_message(self, - message, - process_commands=process_commands, - attention=attention)
===================================== pyrightconfig.json ===================================== @@ -41,6 +41,7 @@ "gajim/common/sound.py", "gajim/common/storage/", "gajim/common/task_manager.py", + "gajim/gtk/controls/private.py", "gajim/gtk/conversation", "gajim/gtk/about.py", "gajim/gtk/account_page.py",
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/b00603be6295ad66abddcdba1da6c2ea...