Skip to content

Commit

Permalink
Handle groupchat messages in decrypt_message
Browse files Browse the repository at this point in the history
  • Loading branch information
Syndace committed Oct 19, 2024
1 parent 4ab4c76 commit 1e12704
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed
- Handle groupchat messages in `decrypt_message`

## [1.2.0] - 15th of October, 2024

### Changed
Expand Down
19 changes: 18 additions & 1 deletion slixmpp_omemo/xep_0384.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DeviceListDownloadFailed,
DeviceListUploadFailed,
MessageSendingFailed,
SenderNotFound,
UnknownNamespace
)
from omemo.storage import Storage
Expand All @@ -32,6 +33,7 @@
from slixmpp.jid import JID
from slixmpp.plugins.base import BasePlugin
from slixmpp.plugins.xep_0004 import Form # type: ignore[attr-defined]
from slixmpp.plugins.xep_0045 import XEP_0045
from slixmpp.plugins.xep_0060 import XEP_0060 # type: ignore[attr-defined]
from slixmpp.plugins.xep_0163 import XEP_0163
from slixmpp.roster import RosterNode # type: ignore[attr-defined]
Expand Down Expand Up @@ -1032,6 +1034,7 @@ async def decrypt_message(self, stanza: Message) -> Tuple[Message, DeviceInforma
Raises:
ValueError: in case there is malformed data not caught be the XML schema validation.
ValueError: in case a groupchat message is passed but XEP-0045 is not loaded.
XMLSchemaValidationError: in case the element does not conform to the XML schema given in the
specification.
SenderNotFound: in case the public information about the sending device could not be found or is
Expand All @@ -1041,7 +1044,21 @@ async def decrypt_message(self, stanza: Message) -> Tuple[Message, DeviceInforma

xmpp: BaseXMPP = self.xmpp

sender_bare_jid = stanza.get_from().bare
from_jid: JID = stanza.get_from()
sender_bare_jid: str

if stanza.get_type() == "groupchat":
if not "xep_0045" in xmpp:
raise ValueError("Attempt to decrypt groupchat message but XEP-0045 is not loaded")

xep_0045: XEP_0045 = xmpp["xep_0045"]
real_jid = xep_0045.get_jid_property(JID(from_jid.bare), from_jid.resource, "jid")
if real_jid is None:
raise SenderNotFound(f"Couldn't find real JID of sender from groupchat JID {from_jid}")

sender_bare_jid = real_jid.bare
else:
sender_bare_jid = from_jid.bare

session_manager = await self.get_session_manager()

Expand Down

0 comments on commit 1e12704

Please sign in to comment.