~singpolyma/cheogram

cdf1bb39613734830b871811ee74fe46ef14c50a — Stephen Paul Weber 8 years ago a5fab2c
Send whisper
1 files changed, 12 insertions(+), 1 deletions(-)

M Main.hs
M Main.hs => Main.hs +12 -1
@@ 264,7 264,7 @@ component db toVitelity toComponent = do
		s <- getStanza
		liftIO $ componentStanza db toVitelity toComponent s

data Command = Join JID | JoinInvited | Send Text | Leave | InviteCmd JID | SetNick Text
data Command = Join JID | JoinInvited | Send Text | Leave | InviteCmd JID | SetNick Text | Whisper JID Text
	deriving (Show, Eq)

parseCommand txt nick


@@ 273,6 273,9 @@ parseCommand txt nick
	| 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 <$> parseJID to <*> pure msg
	| txt == fromString "/join" = Just JoinInvited
	| txt == fromString "/leave" = Just Leave
	| txt == fromString "/part" = Just Leave


@@ 357,6 360,14 @@ processSMS db toVitelity toComponent componentHost tel txt = do

			True <- TC.runTCM (TC.put db (tcKey tel "nick") (T.unpack nick))
			return ()
		Just (Whisper to msg) -> do
			uuid <- (fmap.fmap) UUID.toString UUID.nextUUID
			writeStanzaChan toComponent $ (emptyMessage MessageChat) {
				messageTo = Just to,
				messageFrom = parseJID $ tel <> fromString "@" <> fromString componentHost,
				messageID = Just $ fromString ("CHEOGRAM%" <> fromMaybe "UUIDFAIL" uuid),
				messagePayloads = [Element (fromString "{jabber:component:accept}body") [] [NodeContent $ ContentText msg]]
			}
		Just (Send msg) -> do
			existingRoom <- tcGetJID db tel "joined"
			case existingRoom of