diff options
author | mathieui <mathieui@mathieui.net> | 2022-03-25 22:11:50 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2022-03-28 13:45:28 +0200 |
commit | 41a45068a4498fc0be6c1d11745852e77ff7e150 (patch) | |
tree | 2d607e15c5544e03ea9f3291d76a95ffdc20446b /poezio | |
parent | a224d8820feec02459574213840b29144bc67106 (diff) | |
download | poezio-41a45068a4498fc0be6c1d11745852e77ff7e150.tar.gz poezio-41a45068a4498fc0be6c1d11745852e77ff7e150.tar.bz2 poezio-41a45068a4498fc0be6c1d11745852e77ff7e150.tar.xz poezio-41a45068a4498fc0be6c1d11745852e77ff7e150.zip |
Filter MUC PMs in MAM
Since prosody returns all of the PMs from the room, regardless of who
sent them, we need to filter out messages by full jid here.
Diffstat (limited to 'poezio')
-rw-r--r-- | poezio/mam.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/poezio/mam.py b/poezio/mam.py index 67467e99..59544b16 100644 --- a/poezio/mam.py +++ b/poezio/mam.py @@ -130,6 +130,20 @@ def _parse_message(msg: SMessage) -> Dict: } +def _ignore_private_message(stanza: SMessage, filter_jid: JID) -> bool: + """Returns True if a MUC-PM should be ignored, as prosody returns + all PMs within the same room. + """ + if filter_jid is None: + return False + sent = stanza['from'].bare != filter_jid.bare + if sent and stanza['to'].full != filter_jid.full: + return True + elif not sent and stanza['from'].full != filter_jid.full: + return True + return False + + async def retrieve_messages(tab: tabs.ChatTab, results: AsyncIterable[SMessage], amount: int = 100) -> List[BaseMessage]: @@ -137,11 +151,17 @@ async def retrieve_messages(tab: tabs.ChatTab, msg_count = 0 msgs = [] to_add = [] + tab_is_private = isinstance(tab, tabs.PrivateTab) + filter_jid = None + if tab_is_private: + filter_jid = tab.jid try: async for rsm in results: for msg in rsm['mam']['results']: - if msg['mam_result']['forwarded']['stanza'] \ - .xml.find('{%s}%s' % ('jabber:client', 'body')) is not None: + stanza = msg['mam_result']['forwarded']['stanza'] + if stanza.xml.find('{%s}%s' % ('jabber:client', 'body')) is not None: + if _ignore_private_message(stanza, filter_jid): + continue args = _parse_message(msg) msgs.append(make_line(tab, **args)) for msg in reversed(msgs): |