Philipp Hörist pushed to branch master at gajim / gajim
Commits:
1550705a by Philipp Hörist at 2025-04-19T00:43:18+02:00
cq: Message: Add type annotations
- - - - -
3 changed files:
- gajim/common/modules/message.py
- gajim/common/modules/message_util.py
- pyproject.toml
Changes:
=====================================
gajim/common/modules/message.py
=====================================
@@ -113,7 +113,9 @@ def _message_received(self,
# Ugly, we treat the from attr as the remote jid,
# to make that work with sent carbons we have to do this.
# TODO: Check where in Gajim and plugins we depend on that behavior
- stanza.setFrom(stanza.getTo())
+ to = stanza.getTo()
+ assert to is not None
+ stanza.setFrom(to)
timestamp = get_message_timestamp(properties)
remote_jid = properties.remote_jid
@@ -293,6 +295,8 @@ def _message_error_received(self,
timestamp = get_message_timestamp(properties)
+ assert properties.error is not None
+
error_data = mod.MessageError(
account_=self._account,
remote_jid_=remote_jid,
@@ -323,6 +327,7 @@ def _get_stanza_id(self,
) -> str | None:
if properties.is_mam_message:
+ assert properties.mam is not None
return properties.mam.id
if not properties.stanza_ids:
@@ -330,7 +335,9 @@ def _get_stanza_id(self,
if properties.type.is_groupchat:
archive = properties.remote_jid
+ assert archive is not None
disco_info = app.storage.cache.get_last_disco_info(archive)
+ assert disco_info is not None
if not disco_info.supports(Namespace.SID):
return None
@@ -351,7 +358,7 @@ def build_message_stanza(self, message: OutgoingMessage) ->
nbxmpp.Message:
remote_jid = message.contact.jid
stanza = nbxmpp.Message(
- to=remote_jid,
+ to=str(remote_jid),
body=message.get_text(),
typ=convert_message_type(message.type)
)
@@ -410,7 +417,7 @@ def build_message_stanza(self, message: OutgoingMessage) ->
nbxmpp.Message:
# XEP-0490
if message.mds_id is not None:
- message.setMdsAssist(message.mds_id, own_jid.new_as_bare())
+ stanza.setMdsAssist(message.mds_id, own_jid.new_as_bare())
return stanza
=====================================
gajim/common/modules/message_util.py
=====================================
@@ -6,6 +6,8 @@
from __future__ import annotations
+from typing import Literal
+
from datetime import datetime
from datetime import UTC
@@ -133,7 +135,7 @@ def get_message_timestamp(
return datetime.fromtimestamp(timestamp, tz=UTC)
-def convert_message_type(type_: MessageType) -> str:
+def convert_message_type(type_: MessageType) -> Literal['chat', 'groupchat']:
if type_ in (MessageType.CHAT, MessageType.PM):
return 'chat'
return 'groupchat'
=====================================
pyproject.toml
=====================================
@@ -122,7 +122,6 @@ exclude = [
"gajim/common/modules/httpupload.py",
"gajim/common/modules/ibb.py",
"gajim/common/modules/jingle.py",
- "gajim/common/modules/message.py",
"gajim/common/modules/muc.py",
"gajim/common/modules/omemo.py",
"gajim/common/modules/presence.py",
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/1550705a99c23717fb736e6d3103a4dde0a2e036
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/1550705a99c23717fb736e6d3103a4dde0a2e036
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]