From cd639d0a70fd53a2efcd38066f9d06700c44c687 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sat, 28 Nov 2015 16:28:59 -0500 Subject: [PATCH] Whisper by room nick and show errors --- Main.hs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Main.hs b/Main.hs index 2403d55..9247920 100644 --- a/Main.hs +++ b/Main.hs @@ -124,6 +124,18 @@ code str status = <> hasAttributeText (fromString "code") (== (fromString str)) status +componentMessage db toVitelity (m@Message { messageType = MessageError }) _ _ _ tel body = do + let errorTxt = fmap (mconcat . elementText) $ listToMaybe $ + isNamed (fromString "{urn:ietf:params:xml:ns:xmpp-stanzas}text") =<< + elementChildren =<< isNamed (fromString "{jabber:component:accept}error") =<< messagePayloads m + writeStanzaChan toVitelity $ mkSMS tel $ + mconcat [ + fromString "(ERROR from ", + maybe (fromString "unspecified") formatJID (messageFrom m), + fromString ")", + maybe mempty (fromString "\n"<>) errorTxt, + maybe mempty (fromString "\n"<>) body + ] componentMessage db toVitelity m existingRoom _ _ tel _ | Just invite <- getMediatedInvitation m <|> getDirectInvitation m = do existingInvite <- tcGetJID db tel "invited" @@ -352,13 +364,20 @@ data Command = Join JID | JoinInvited | Send Text | Leave | InviteCmd JID | SetN parseCommand txt room nick componentHost | Just jid <- T.stripPrefix (fromString "/invite ") txt = - InviteCmd <$> (parseJIDrequireNode jid <|> telToJid jid (fromString componentHost)) + InviteCmd <$> ( + parseJIDrequireNode jid <|> + telToJid jid (fromString componentHost) + ) | Just room <- T.stripPrefix (fromString "/join ") txt = Join <$> (parseJID (room <> fromString "/" <> nick) <|> parseJID room) | Just nick <- T.stripPrefix (fromString "/nick ") txt = Just $ SetNick nick | Just input <- T.stripPrefix (fromString "/msg ") txt = let (to, msg) = T.breakOn (fromString " ") input in - Whisper <$> (parseJIDrequireNode to <|> telToJid to (fromString componentHost)) <*> pure msg + Whisper <$> ( + parseJIDrequireNode to <|> + telToJid to (fromString componentHost) <|> + (parseJID =<< fmap (\r -> bareTxt r <> fromString "/" <> to) room) + ) <*> pure msg | txt == fromString "/join" = Just JoinInvited | txt == fromString "/leave" = Just Leave | txt == fromString "/part" = Just Leave -- 2.34.5