From 155f8add673741bee53984f37832c49638c80748 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sat, 28 Nov 2015 14:12:54 -0500 Subject: [PATCH] Invite to room by phone number --- Main.hs | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/Main.hs b/Main.hs index 3130913..fdacdd1 100644 --- a/Main.hs +++ b/Main.hs @@ -288,7 +288,7 @@ data Command = Join JID | JoinInvited | Send Text | Leave | InviteCmd JID | SetN parseCommand txt room nick componentHost | Just jid <- T.stripPrefix (fromString "/invite ") txt = - InviteCmd <$> parseJID jid + 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 @@ -346,31 +346,32 @@ processSMS db toVitelity toComponent componentHost tel txt = do leaveRoom db toComponent componentHost tel "Joined a different room." joinRoom db toComponent componentHost tel room Just Leave -> leaveRoom db toComponent componentHost tel "Left" - Just (InviteCmd jid) -> do - forM_ existingRoom $ \room -> do - writeStanzaChan toComponent $ (emptyMessage MessageNormal) { - messageTo = Just room, - messageFrom = parseJID $ tel <> fromString "@" <> fromString componentHost, - messagePayloads = [ - Element (fromString "{http://jabber.org/protocol/muc#user}x") [] [ - NodeElement $ Element (fromString "{http://jabber.org/protocol/muc#user}invite") [ - (fromString "{http://jabber.org/protocol/muc#user}to", [ContentText $ formatJID jid]) - ] [] - ] + Just (InviteCmd jid) + | Just room <- existingRoom -> do + writeStanzaChan toComponent $ (emptyMessage MessageNormal) { + messageTo = Just room, + messageFrom = parseJID $ tel <> fromString "@" <> fromString componentHost, + messagePayloads = [ + Element (fromString "{http://jabber.org/protocol/muc#user}x") [] [ + NodeElement $ Element (fromString "{http://jabber.org/protocol/muc#user}invite") [ + (fromString "{http://jabber.org/protocol/muc#user}to", [ContentText $ formatJID jid]) + ] [] ] - } - - writeStanzaChan toComponent $ (emptyMessage MessageNormal) { - messageTo = Just jid, - messageFrom = parseJID $ tel <> fromString "@" <> fromString componentHost, - messagePayloads = [ - Element (fromString "{jabber:x:conference}x") [ - (fromString "{jabber:x:conference}jid", [ContentText $ formatJID room]) - ] [], - Element (fromString "{jabber:component:accept}body") [] - [NodeContent $ ContentText $ mconcat [tel, fromString " has invited you to join ", formatJID room]] - ] - } + ] + } + + writeStanzaChan toComponent $ (emptyMessage MessageNormal) { + messageTo = Just jid, + messageFrom = parseJID $ tel <> fromString "@" <> fromString componentHost, + messagePayloads = [ + Element (fromString "{jabber:x:conference}x") [ + (fromString "{jabber:x:conference}jid", [ContentText $ formatJID room]) + ] [], + Element (fromString "{jabber:component:accept}body") [] + [NodeContent $ ContentText $ mconcat [tel, fromString " has invited you to join ", formatJID room]] + ] + } + | otherwise -> writeStanzaChan toVitelity $ mkSMS tel (fromString "You are not joined to a room") Just (SetNick nick) -> do forM_ existingRoom $ \room -> do let toJoin = parseJID (bareTxt room <> fromString "/" <> nick) -- 2.38.5