~singpolyma/cheogram

2e9482fc78c65413a646e25e60d3205bd1e61c22 — Stephen Paul Weber 11 days ago 04f6e7d
mapBodyMaybe helper
1 files changed, 7 insertions(+), 4 deletions(-)

M Main.hs
M Main.hs => Main.hs +7 -4
@@ 374,12 374,15 @@ stripOtrWhitespaceOnce body =

stripOtrWhitespace = stripOtrWhitespaceOnce . stripOtrWhitespaceOnce . stripOtrWhitespaceOnce . stripOtrWhitespaceOnce . stripOtrWhitespaceOnce

mapBody f (m@Message { messagePayloads = payloads }) =
mapBody :: (Text -> Text) -> XMPP.Message -> XMPP.Message
mapBody f = mapBodyMaybe (Just . f)

mapBodyMaybe f (m@Message { messagePayloads = payloads }) =
	m { messagePayloads =
		map (\payload ->
		mapMaybe (\payload ->
			case isNamed (s"{jabber:component:accept}body") payload of
				[] -> payload
				_ -> payload { elementNodes = [NodeContent $ ContentText $ f (concat (elementText payload))] }
				[] -> Just payload
				_ -> fmap (\c -> payload { elementNodes = [NodeContent $ ContentText c]}) (f (concat (elementText payload)))
		) payloads
	}