~singpolyma/cheogram

32490558975019dcf3c11bcd4936efae19c09b44 — Stephen Paul Weber 1 year, 10 months ago ba52cd7
Allow sms-side commands to use proxied JIDs

Since we know about ourselves, we can know to strip our own proxies JIDs back to
the real thing. This is useful if something wants to talk to us from SMS side
but only knows about our proxied JIDs and doesn't know we exist.
1 files changed, 6 insertions(+), 2 deletions(-)

M Main.hs
M Main.hs => Main.hs +6 -2
@@ 1399,7 1399,7 @@ data Command = Help | Create Text | Join JID | JoinInvited | JoinInvitedWrong | 
parseCommand txt room nick componentJid
	| Just jid <- stripCIPrefix (fromString "/invite ") txt =
		InviteCmd <$> (
			parseJIDrequireNode jid <|>
			(maybeStripProxy <$> parseJIDrequireNode jid) <|>
			telToJid jid (formatJID componentJid)
		)
	| Just room <- stripCIPrefix (fromString "/join ") txt =


@@ 1414,7 1414,7 @@ parseCommand txt room nick componentJid
	| Just input <- stripCIPrefix (fromString "/msg ") txt =
		let (to, msg) = T.breakOn (fromString " ") input in
		Whisper <$> (
			parseJIDrequireNode to <|>
			(maybeStripProxy <$> parseJIDrequireNode to) <|>
			telToJid to (formatJID componentJid) <|>
			(parseJID =<< fmap (\r -> bareTxt r <> fromString "/" <> to) room)
		) <*> pure msg


@@ 1429,6 1429,10 @@ parseCommand txt room nick componentJid
	| citxt == fromString "/help" = Just Help
	| otherwise = Just $ Send txt
	where
	maybeStripProxy jid
		| Just _ <- normalizeTel =<< strNode <$> jidNode jid = jid
		| jidDomain jid == jidDomain (componentJid) = fromMaybe jid $ proxiedJidToReal jid
		| otherwise = jid
	citxt = CI.mk txt

getMessage (ReceivedMessage m) = Just m