~singpolyma/cheogram-muc-bridge

b5685080610758196d4a70be2ede84ddb5159adb — Stephen Paul Weber 3 years ago ae0b80c
Store rewritten nick after full join
1 files changed, 11 insertions(+), 2 deletions(-)

M gateway.hs
M gateway.hs => gateway.hs +11 -2
@@ 43,11 43,20 @@ handlePresence config presence@XMPP.Presence {
	XMPP.presenceFrom = Just from,
	XMPP.presenceTo = Just to
}
	| hasMucCode 110 presence, -- done joining room
	  Just source <- (XMPP.parseJID . unescapeJid . XMPP.strNode) =<< XMPP.jidNode to = do
		when (bareTxt to == bareTxt (Config.bridgeJid config)) $ Session.cleanOld config from
		liftIO $ DB.execute (Config.db config)
			(s"UPDATE sessions SET target_nick=? WHERE source_muc=? AND source_nick=? AND target_muc=?")
			(
				XMPP.strResource <$> XMPP.jidResource from,
				bareTxt source,
				XMPP.strResource <$> XMPP.jidResource source,
				bareTxt from
			)
	| bareTxt to /= bareTxt (Config.bridgeJid config) =
		-- This is to one of our ghosts, so just ignore it
		return ()
	| hasMucCode 110 presence = -- done joining room, clean up old data
		Session.cleanOld config from
	| otherwise = forM_ (fullTargets config from) $
			uncurry $ Session.sendPresenceToMUC config presence
handlePresence _ _ = return ()