~singpolyma/cheogram

1df1d7734c2fe3a875409538cb77e45487e6f6b5 — Stephen Paul Weber 1 year, 11 months ago 1a93142
Only assume nickname for phone number if isE164
1 files changed, 6 insertions(+), 3 deletions(-)

M Main.hs
M Main.hs => Main.hs +6 -3
@@ 160,7 160,7 @@ forkXMPP kid = do

nickFor db jid existingRoom
	| fmap bareTxt existingRoom == Just bareFrom = return $ fromMaybe (fromString "nonick") resourceFrom
	| Just tel <- normalizeTel =<< strNode <$> jidNode jid = do
	| Just tel <- mfilter isE164 (strNode <$> jidNode jid) = do
		mnick <- maybe (return Nothing) (TC.runTCM .TC.get db) (tcKey jid "nick")
		case mnick of
			Just nick -> return (tel <> fromString " \"" <> fromString nick <> fromString "\"")


@@ 1348,9 1348,12 @@ localpartToURI localpart
	where
	result = Just (s"sms:" ++ localpart)

isE164 fullTel
	| Just ('+',e164) <- T.uncons fullTel = T.all isDigit e164
	| otherwise = False

normalizeTel fullTel
	| Just ('+',e164) <- T.uncons fullTel,
	  T.all isDigit e164 = Just fullTel
	| isE164 fullTel = Just fullTel
	| T.length tel == 10 = Just (s"+1" ++ tel)
	| T.length tel == 11, s"1" `T.isPrefixOf` tel = Just (T.cons '+' tel)
	| T.length tel == 5 || T.length tel == 6 = Just (tel ++ s";phone-context=ca-us.phone-context.soprani.ca")