fix(mattermost): ignore system posts

Signed-off-by: Lanre Shittu <136805224+Shizoqua@users.noreply.github.com>
This commit is contained in:
Lanre Shittu
2026-08-19 10:31:14 +08:00
committed by chengyongru
parent d7b3abe589
commit 242f417370
2 changed files with 30 additions and 0 deletions
+4
View File
@@ -221,6 +221,10 @@ class MattermostChannel(BaseChannel):
self.logger.warning("failed to parse post json")
return
post_type = post.get("type")
if isinstance(post_type, str) and post_type.startswith("system_"):
return
sender_id = post.get("user_id", "")
channel_id = post.get("channel_id", "")
message_text = post.get("message", "")
@@ -463,6 +463,32 @@ async def test_posted_thread_event_uses_thread_policy():
assert mock_handle.call_args.kwargs["session_key"] == "mattermost:channel_1:root_1"
@pytest.mark.asyncio
@pytest.mark.parametrize("post_type", ["system_join_channel", "system_leave_channel"])
async def test_posted_event_ignores_system_posts(post_type: str):
channel, _ = _make_channel({"groupPolicy": "open"})
channel._self_id = "bot_id"
with patch.object(channel, "_handle_message", AsyncMock()) as mock_handle:
ws_msg = {
"event": "posted",
"data": {
"channel_type": "O",
"post": json.dumps({
"id": "system_post_1",
"user_id": "user_1",
"channel_id": "channel_1",
"message": "A user joined or left the channel.",
"type": post_type,
}),
},
"broadcast": {},
}
await channel._handle_ws_message(ws_msg)
mock_handle.assert_not_awaited()
@pytest.mark.asyncio
async def test_group_policy_in_thread_allowlist():
"""Thread uses allowlist policy when configured."""