~singpolyma/cheogram

69f3bbd93185d0c33df53bda76fcec6564cb1277 — Stephen Paul Weber 1 year, 2 months ago 8c7e7b0
Allow owners to message any JID from the phone number they own

Messages to user\40domain@component used to only work if the from domain matched
the target's route, but this adds another case where if the from has an assigned
cheoJid (aka phone number) that they own, we can route to the target from that JID.
1 files changed, 7 insertions(+), 4 deletions(-)

M Main.hs
M Main.hs => Main.hs +7 -4
@@ 1529,9 1529,10 @@ component db redis pushStatsd backendHost did maybeAvatar cacheOOB sendIQ iqRece
				| Nothing <- mapM localpartToURI (T.split (==',') $ fromMaybe mempty $ fmap strNode $ jidNode to),
				  Just routeTo <- parseJID (unescapeJid localpart ++ maybe mempty (s"/"++) (strResource <$> jidResource to)),
				  fmap (((s"CHEOGRAM%") `T.isPrefixOf`) . strResource) (jidResource to) /= Just True -> liftIO $ do
					maybeOwnedCheoJid <- (XMPP.parseJID =<<) <$> DB.get db (DB.byJid from ["cheoJid"])
					maybeRoute <- DB.get db (DB.byJid routeTo ["direct-message-route"])
					case (maybeRoute, mapToComponent from) of
						(Just route, _)
					case (maybeRoute, mapToComponent from, maybeOwnedCheoJid) of
						(Just route, _, _)
							| route == bareTxt from,
							  ReceivedIQ iq <- stanza,
							  iqType iq == IQSet,


@@ 1539,7 1540,7 @@ component db redis pushStatsd backendHost did maybeAvatar cacheOOB sendIQ iqRece
								deleteDirectMessageRoute db routeTo
								sendToComponent $ mkStanzaRec $ iqReply
									(Just $ Element (fromString "{jabber:iq:register}query") [] []) iq
						(Just route, Just componentFrom)
						(Just route, Just componentFrom, _)
							| route == strDomain (jidDomain from),
							  ReceivedIQ iq <- stanza,
							  [items] <- XML.isNamed (s"{http://jabber.org/protocol/pubsub}items") =<< XML.elementChildren =<< XML.isNamed (s"{http://jabber.org/protocol/pubsub}pubsub") =<< justZ (iqPayload iq),


@@ 1561,7 1562,9 @@ component db redis pushStatsd backendHost did maybeAvatar cacheOOB sendIQ iqRece
								sendToComponent $ receivedStanza $ receivedStanzaFromTo from' routeTo stanza
							| route == strDomain (jidDomain from) ->
								(sendToComponent . receivedStanza) =<< mapReceivedMessageM (fmap addMarkable . UIO.lift . (rememberIncomingBody db <=< cacheOOB (Just . addOOBFallbackBody) True)) (receivedStanzaFromTo componentFrom routeTo stanza)
						(Just route, _) -- Alphanumeric senders
						(_, _, Just ownedCheoJid) ->
							(sendToComponent . receivedStanza) =<< mapReceivedMessageM (fmap addMarkable . UIO.lift . (rememberIncomingBody db <=< cacheOOB (Just . addOOBFallbackBody) True)) (receivedStanzaFromTo ownedCheoJid routeTo stanza)
						(Just route, _, _) -- Alphanumeric senders
							| route == strDomain (jidDomain from),
							  Just localpart <- strNode <$> jidNode from,
							  Nothing <- T.find (\c -> not ((isAlphaNum c || c == ' ') && isAscii c)) localpart ->