Philipp Hörist pushed to branch master at gajim / gajim
Commits:
ae699c18 by lovetox at 2022-08-21T11:29:53+02:00
refactor: ChatBanner: Use asserts instead of return
There is no case where client or contact should be None
- - - - -
32c0d3e3 by lovetox at 2022-08-21T11:42:29+02:00
refactor: Chatstates: Fix TODOs and refactor checks for different contacts
- Lower logging level to DEBUG
- Don’t send chatstates to unsubscribed contacts
- - - - -
2 changed files:
- gajim/common/modules/chatstates.py
- gajim/gtk/chat_banner.py
Changes:
=====================================
gajim/common/modules/chatstates.py
=====================================
@@ -36,6 +36,8 @@
from gajim.common.const import ClientState
from gajim.common.structs import OutgoingMessage
from gajim.common.modules.base import BaseModule
+from gajim.common.modules.contacts import GroupchatParticipant
+from gajim.common.modules.contacts import BareContact
INACTIVE_AFTER = 60
PAUSED_AFTER = 10
@@ -270,9 +272,9 @@ def set_chatstate(self, contact: types.ChatContactT, state:
State) -> None:
if setting == 'disabled':
# Send a last 'active' state after user disabled chatstates
if current_state is not None:
- self._log.info('Disabled for %s', contact.jid)
+ self._log.info('Disabled for %s', contact)
self._log.info('Send last state: %-10s - %s',
- State.ACTIVE, contact.jid)
+ State.ACTIVE, contact)
self._send_chatstate(contact, State.ACTIVE)
@@ -281,22 +283,23 @@ def set_chatstate(self, contact: types.ChatContactT,
state: State) -> None:
self._last_keyboard_activity.pop(contact.jid, None)
return
- if not contact.is_groupchat:
- # Don’t leak presence to contacts
- # which are not allowed to see our status
- if not contact.is_pm_contact:
- # TODO
- # if contact and contact.sub in ('to', 'none'):
- # self._log.info('Contact not subscribed: %s', contact.jid)
- # return
- pass
+ if isinstance(contact, BareContact):
+ if not contact.is_subscribed:
+ self._log.debug('Contact not subscribed: %s', contact)
+ return
if not contact.is_available:
- self._log.info('Contact offline: %s', contact.jid)
+ self._log.debug('Contact offline: %s', contact)
return
- if not contact.supports(Namespace.CHATSTATES):
- self._log.info('Chatstates not supported: %s', contact.jid)
+ elif isinstance(contact, GroupchatParticipant):
+ if not contact.is_available:
+ self._log.debug('Contact offline: %s', contact)
+ return
+
+ else:
+ if not contact.is_joined:
+ self._log.debug('Groupchat not joined: %s', contact)
return
if state in (State.ACTIVE, State.COMPOSING):
@@ -309,7 +312,7 @@ def set_chatstate(self, contact: types.ChatContactT, state:
State) -> None:
if current_state == state:
return
- self._log.info('Send: %-10s - %s', state, contact.jid)
+ self._log.info('Send: %-10s - %s', state, contact)
self._send_chatstate(contact, state)
=====================================
gajim/gtk/chat_banner.py
=====================================
@@ -240,8 +240,8 @@ def _update_avatar(self) -> None:
self._ui.avatar_image.set_from_surface(surface)
def _update_content(self) -> None:
- if self._client is None or self._contact is None:
- return
+ assert self._contact is not None
+ assert self._client is not None
name = self._contact.name
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/12669c512656b01180a2871f5a8f1b1e8b115687...32c0d3e35a04dba1e312fe459ee687b3aa7b4685
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/12669c512656b01180a2871f5a8f1b1e8b115687...32c0d3e35a04dba1e312fe459ee687b3aa7b4685
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits