Skip to content

Commit

Permalink
[#108] Don't report warnings for user/usergroup/broadcast blocks
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
dcastro committed Sep 8, 2023
1 parent 0e9201a commit 4e57a2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/TzBot/Slack/API/MessageBlock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
]
4 changes: 1 addition & 3 deletions test/Test/TzBot/MessageBlocksSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 4e57a2d

Please sign in to comment.