~singpolyma/cheogram-muc-bridge

e8afef3d50a77933d4952e99a041afb85265d4f9 — Stephen Paul Weber 1 year, 4 months ago 89ffe05
Remove any possible dupes when recording a rename
1 files changed, 19 insertions(+), 10 deletions(-)

M gateway.hs
M gateway.hs => gateway.hs +19 -10
@@ 46,16 46,25 @@ handlePresence config presence@XMPP.Presence {
}
	| typ == XMPP.PresenceAvailable,
	  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) = do
		liftIO $ DB.withTransaction (Config.db config) $ do
			DB.execute (Config.db config)
				(s"DELETE FROM sessions WHERE source_muc=? AND target_muc=?")
				(Nothing :: Maybe Text, bareTxt from)
			Session.mkSession config XMPP.PresenceAvailable Nothing from
		Session.cleanOld config from
	| typ == XMPP.PresenceAvailable,
	  hasMucCode 110 presence, -- done joining room
	  Just source <- (XMPP.parseJID . unescapeJid . XMPP.strNode) =<< XMPP.jidNode to =
		liftIO $ DB.withTransaction (Config.db config) $ do
			DB.execute (Config.db config)
				(s"DELETE FROM sessions WHERE source_muc=? AND source_nick=? AND target_muc=?")
				(
					bareTxt source,
					XMPP.strResource <$> XMPP.jidResource source,
					bareTxt from
				)
			Session.mkSession config XMPP.PresenceAvailable (Just source) from
	| typ == XMPP.PresenceUnavailable,
	  hasMucCode 110 presence, -- done leaving room
	  Just source <- (XMPP.parseJID . unescapeJid . XMPP.strNode) =<< XMPP.jidNode to =