From 4e57a2d6a970a2aa258f2507aec41ba330047595 Mon Sep 17 00:00:00 2001 From: Diogo Castro Date: Fri, 8 Sep 2023 16:19:22 +0100 Subject: [PATCH] [#108] Don't report warnings for `user`/`usergroup`/`broadcast` blocks Problem: The server reports warnings whenever it finds a message with a tag like `@user`. Since this occurs very often, it ends up flooding the logs. Solution: Don't report warnings for blocks of type `user`, `usergroup` and `broadcast`. --- src/TzBot/Slack/API/MessageBlock.hs | 11 ++++++++++- test/Test/TzBot/MessageBlocksSpec.hs | 4 +--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/TzBot/Slack/API/MessageBlock.hs b/src/TzBot/Slack/API/MessageBlock.hs index 1fc3817..ffeffac 100644 --- a/src/TzBot/Slack/API/MessageBlock.hs +++ b/src/TzBot/Slack/API/MessageBlock.hs @@ -208,7 +208,9 @@ extractPieces mBlocks = runWriter $ concat <$> mapM goMessageBlock mBlocks -- skip over emoji blocks go mbCurPiece prevPieces es _ -> do - tell [EEUnknownBlockElementLevel2 $ UnknownBlockElementLevel2Error blockType val] + -- return an error if we find a block type we don't recognize. + when (blockType `notElem` knownBlockTypes) do + tell [EEUnknownBlockElementLevel2 $ UnknownBlockElementLevel2Error blockType val] -- break the message in two separate `Text` pieces. go Nothing (prependMbCurrentToPrevious mbCurPiece prevPieces) es Right (BEL2ElementText elementText) -> do @@ -229,3 +231,10 @@ extractPieces mBlocks = runWriter $ concat <$> mapM goMessageBlock mBlocks prependMbCurrentToPrevious :: Maybe Builder -> [Text] -> [Text] prependMbCurrentToPrevious mbCurPiece prevPieces = maybe prevPieces ((: prevPieces) . cs . toLazyText) mbCurPiece + + knownBlockTypes :: [Text] + knownBlockTypes = + [ "user" -- A user tag, e.g. `@gromak` + , "usergroup" -- A tag for a user group, e.g. `@ligo-lsp-project + , "broadcast" -- A tag like `@here` or `@channel` + ] diff --git a/test/Test/TzBot/MessageBlocksSpec.hs b/test/Test/TzBot/MessageBlocksSpec.hs index f28761d..b688926 100644 --- a/test/Test/TzBot/MessageBlocksSpec.hs +++ b/test/Test/TzBot/MessageBlocksSpec.hs @@ -67,9 +67,7 @@ test_messageBlocksSpec = TestGroup "Message blocks" $ , "am I a human?" , "end!" ] - getLevel2Errors (snd res) @?= - [ "user", "broadcast" - ] + getLevel2Errors (snd res) @?= [] ] {- | The original Slack message (in markdown format):