~singpolyma/cheogram

facd463972bd06f9b2748b86e8940e8e65ecaeda — Stephen Paul Weber 5 years ago d2350b8
Clear old route before setting new one

Closes #47
2 files changed, 3 insertions(+), 1 deletions(-)

M ConfigureDirectMessageRoute.hs
M Main.hs
M ConfigureDirectMessageRoute.hs => ConfigureDirectMessageRoute.hs +2 -0
@@ 87,9 87,11 @@ lookupAndStepSession setRouteJid sessions sid iqID from payload
				SessionCancel -> return $! Map.delete sid sessions
				SessionSaveAndNext userJid gatewayJid s -> do
					now <- getCurrentTime
					userJid `setRouteJid` Nothing -- clear old route
					userJid `setRouteJid` (Just gatewayJid)
					return $! Map.insert sid (s, now) sessions
				SessionComplete userJid gatewayJid -> do
					when (isJust gatewayJid) $ userJid `setRouteJid` Nothing -- clear old route
					userJid `setRouteJid` gatewayJid
					return $! Map.delete sid sessions
	| otherwise = do

M Main.hs => Main.hs +1 -1
@@ 1493,7 1493,7 @@ main = do
							return ()
						Nothing -> do
							maybeExistingRoute <- (parseJID . fromString =<<) <$> TC.runTCM (TC.get db (T.unpack (bareTxt userJid) ++ "\0direct-message-route"))
							True <- TC.runTCM $ TC.out db (T.unpack (bareTxt userJid) ++ "\0direct-message-route")
							TC.runTCM $ TC.out db (T.unpack (bareTxt userJid) ++ "\0direct-message-route")
							forM_ maybeExistingRoute $ \existingRoute -> do
								uuid <- (fmap.fmap) (fromString . UUID.toString) UUID.nextUUID
								atomically $ writeTChan sendToComponent $ mkStanzaRec $ (emptyIQ IQSet) {