~singpolyma/cheogram

155f8add673741bee53984f37832c49638c80748 — Stephen Paul Weber 7 years ago 0e76102
Invite to room by phone number
1 files changed, 26 insertions(+), 25 deletions(-)

M Main.hs
M Main.hs => Main.hs +26 -25
@@ 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)