~singpolyma/cheogram

197a2470399b44ec1231840f637103dc298dec89 — Stephen Paul Weber 7 years ago 62db334
Send <presence type="subscribe"/> to users configured by a third party

Closes #58
1 files changed, 14 insertions(+), 1 deletions(-)

M Main.hs
M Main.hs => Main.hs +14 -1
@@ 674,7 674,20 @@ componentStanza _ _ registrationJids _ _ _ processDirectMessageRouteConfig compo
				iqPayload = Just payload
			}
		let fromLocalpart = maybe mempty (\localpart -> localpart++s"@") (fmap strNode . jidNode =<< iqFrom replyIQ)
		return [mkStanzaRec $ replyIQ {

		let subscribe = if attributeText (s"action") payload /= Just (s"complete") then [] else [
				mkStanzaRec $ (emptyPresence PresenceSubscribe) {
					presenceTo = Just asFrom,
					presenceFrom = Just componentJid,
					presencePayloads = [
						Element (s"{jabber:component:accept}status") [] [
							NodeContent $ ContentText $ s"Welcome to Cheogram! You are now configured to send SMS by sending messages to +1<phone-number>@cheogram.com JIDs."
						]
					]
				}
			]

		return $ subscribe ++ [mkStanzaRec $ replyIQ {
			iqTo = if iqTo replyIQ == Just asFrom then Just from else iqTo replyIQ,
			iqFrom = parseJID (fromLocalpart ++ formatJID componentJid ++ s"/CHEOGRAM%" ++ ConfigureDirectMessageRoute.nodeName)
		}]