M Main.hs => Main.hs +3 -3
@@ 1338,11 1338,11 @@ removeSpan t (start, -1) = T.dropEnd (T.length t - start) t
removeSpan t (start, end) = T.take (start + 1) t ++ T.takeEnd (T.length t - end) t
removeFallbacks :: [Text] -> XMPP.Message -> XMPP.Message
-removeFallbacks for m = (mapBody go m) {
- messagePayloads = filter (`notElem` toRemove) (messagePayloads m)
+removeFallbacks for m = m {
+ messagePayloads = filter (`notElem` toRemove) (messagePayloads $ mapBodyMaybe go m)
}
where
- go body = foldl' removeSpan body (sortedFallbackSpans removeFromBody)
+ go body = emptyNothing $ foldl' removeSpan body (sortedFallbackSpans removeFromBody)
removeFromBody = XML.isNamed (s"{urn:xmpp:fallback:0}body") =<< XML.elementChildren =<< toRemove
toRemove = filter (\fb -> XML.attributeText (s"for") fb `elem` for') (isNamed (s"{urn:xmpp:fallback:0}fallback") =<< messagePayloads m)
for' = map Just for
M Util.hs => Util.hs +5 -0
@@ 328,3 328,8 @@ hasLocked msg action =
contentText :: XML.Content -> [Text]
contentText (XML.ContentText t) = [t]
contentText (XML.ContentEntity entity) = [T.pack "&", entity, T.pack ";"]
+
+emptyNothing :: Text -> Maybe Text
+emptyNothing t
+ | T.null t = Nothing
+ | otherwise = Just t