diff --git a/src/TzBot/Slack/API/MessageBlock.hs b/src/TzBot/Slack/API/MessageBlock.hs index 74e3caa..1fc3817 100644 --- a/src/TzBot/Slack/API/MessageBlock.hs +++ b/src/TzBot/Slack/API/MessageBlock.hs @@ -202,15 +202,24 @@ extractPieces mBlocks = runWriter $ concat <$> mapM goMessageBlock mBlocks go :: Maybe Builder -> [Text] -> [WithUnknown BlockElementLevel2] -> Writer [ExtractError] [Text] go mbCurPiece prevPieces (e:es) = case unUnknown e of Left val -> do - let _type = fromMaybe "unknown" (val ^? key "type" . _String) - tell [EEUnknownBlockElementLevel2 $ UnknownBlockElementLevel2Error _type val] - go Nothing (prependMbCurrentToPrevious mbCurPiece prevPieces) es + let blockType = fromMaybe "unknown" (val ^? key "type" . _String) + case blockType of + "emoji" -> + -- skip over emoji blocks + go mbCurPiece prevPieces es + _ -> do + tell [EEUnknownBlockElementLevel2 $ UnknownBlockElementLevel2Error blockType val] + -- break the message in two separate `Text` pieces. + go Nothing (prependMbCurrentToPrevious mbCurPiece prevPieces) es Right (BEL2ElementText elementText) -> do let etTextB = fromText elementText.etText if (elementText.etStyle >>= styCode) == Just True - -- ignore inline code block - then go Nothing (prependMbCurrentToPrevious mbCurPiece prevPieces) es - else go (Just $ maybe etTextB (<> etTextB) mbCurPiece) prevPieces es + then + -- ignore inline code block + go Nothing (prependMbCurrentToPrevious mbCurPiece prevPieces) es + else + -- collate this block's text with any adjacent text-like block + go (Just $ maybe etTextB (<> etTextB) mbCurPiece) prevPieces es Right (BEL2ElementLink elementLink) -> do let linkText = fromText elementLink.elText go (Just $ maybe linkText (<> linkText) mbCurPiece) prevPieces es diff --git a/test/Test/TzBot/MessageBlocksSpec.hs b/test/Test/TzBot/MessageBlocksSpec.hs index eabf7ec..f2eae2e 100644 --- a/test/Test/TzBot/MessageBlocksSpec.hs +++ b/test/Test/TzBot/MessageBlocksSpec.hs @@ -54,8 +54,7 @@ test_messageBlocksSpec = TestGroup "Message blocks" $ , "3.1quote block " , " 3.2quote block" , "4.1plain " - , " 4.1strike " - , " 4.1bold " + , " 4.1strike 4.1bold " , "4.2plain " , " 4.2strike github 4.2bold " , "between the lists\n" @@ -69,7 +68,7 @@ test_messageBlocksSpec = TestGroup "Message blocks" $ , "end!" ] getLevel2Errors (snd res) @?= - [ "emoji", "user", "broadcast" + [ "user", "broadcast" ] ]