Philipp Hörist pushed to branch sfs at gajim / python-nbxmpp
Commits:
8bfa2b31 by Philipp Hörist at 2025-07-13T09:14:44+02:00
fix: Be more strict with id parsing
- - - - -
d7db59b4 by Philipp Hörist at 2025-07-15T23:07:59+02:00
Add attach to parsing
- - - - -
4 changed files:
- nbxmpp/modules/message.py
- nbxmpp/modules/sfs.py
- nbxmpp/namespaces.py
- nbxmpp/structs.py
Changes:
=====================================
nbxmpp/modules/message.py
=====================================
@@ -106,6 +106,7 @@ class BaseMessage(BaseModule):
)
properties.thread = stanza.getThread()
properties.subject = stanza.getSubject()
+ properties.attach_to = self._parse_attaching(stanza)
forms = stanza.getTags("x", namespace=Namespace.DATA)
if forms:
properties.forms = forms
@@ -121,6 +122,12 @@ class BaseMessage(BaseModule):
properties.xhtml = XHTMLData(xhtml)
+ def _parse_attaching(self, stanza: Message) -> str | None:
+ attach_id = stanza.getTagAttr("attach-to", "id",
namespace=Namespace.ATTACHING)
+ if attach_id:
+ return attach_id
+ return None
+
def _parse_type(self, stanza: Message) -> MessageType:
type_ = stanza.getType()
if type_ is None:
=====================================
nbxmpp/modules/sfs.py
=====================================
@@ -78,10 +78,18 @@ class StatelessFileSharing(BaseModule):
sources_list: list[FileSources] = []
for sources in stanza.getTags("sources", namespace=Namespace.SFS):
try:
- sources_list.append(FileSources.from_node(sources))
+ source = FileSources.from_node(sources)
except Exception as e:
self._log.warning("Unable to parse sources node: %s", e)
self._log.warning(stanza)
+ continue
+
+ if source.id is None:
+ self._log.warning("Source without id")
+ self._log.warning(stanza)
+ continue
+
+ sources_list.append(source)
unique_ids = {sources.id for sources in sources_list}
if len(sources_list) > len(unique_ids):
@@ -354,4 +362,7 @@ class FileSharing:
else:
sources = None
+ if id_ is None and sources is None:
+ raise ValueError("fileshare id is missing")
+
return cls(file=file, sources=sources, id=id_, disposition=disposition)
=====================================
nbxmpp/namespaces.py
=====================================
@@ -13,6 +13,7 @@ class _Namespaces:
ACTIVITY: str = "http://jabber.org/protocol/activity"
ADDRESS: str = "http://jabber.org/protocol/address"
AGENTS: str = "jabber:iq:agents"
+ ATTACHING: str = "urn:xmpp:message-attaching:1"
ATTENTION: str = "urn:xmpp:attention:0"
AUTH: str = "jabber:iq:auth"
AVATAR_METADATA: str = "urn:xmpp:avatar:metadata"
=====================================
nbxmpp/structs.py
=====================================
@@ -1143,6 +1143,7 @@ class MessageProperties:
reactions: Reactions | None = None
sfs: list[FileSharing] = field(default_factory=list)
sfs_sources: list[FileSources] = field(default_factory=list)
+ attach_to: str | None = None
def is_from_us(self, bare_match: bool = True) -> bool:
if self.from_ is None:
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/compare/56d11a25b9af81aecb1bfb2ae4dbe22e7b392c29...d7db59b4ad8a6b5763d72d84c2e9bbb7d4534249
--
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/compare/56d11a25b9af81aecb1bfb2ae4dbe22e7b392c29...d7db59b4ad8a6b5763d72d84c2e9bbb7d4534249
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]