~singpolyma/cheogram-muc-bridge

f0c12822c727ec48ac4a56d66e3c6364bbbe305b — Stephen Paul Weber 10 months ago 4e20bfd
Don't leave if just renaming
1 files changed, 12 insertions(+), 6 deletions(-)

M Session.hs
M Session.hs => Session.hs +12 -6
@@ 16,13 16,19 @@ import Util
cleanOld :: Config.Config -> XMPP.JID -> XMPP.XMPP ()
cleanOld config source = do
	old <- liftIO $ DB.query (Config.db config)
		(s"SELECT target_muc, target_nick, source_nick FROM sessions WHERE version < ? AND source_muc = ?")
		(s"SELECT target_muc, target_nick, source_nick, (SELECT COUNT(1) FROM sessions s where s.source_muc=sessions.source_muc AND s.target_muc=sessions.target_muc AND s.source_nick=sessions.source_nick) FROM sessions WHERE version < ? AND source_muc = ?")
		(Config.dbVersion config, bareTxt source)
	forM_ old $ \(muc, nick, source_nick) ->
		let Just target = XMPP.parseJID $ muc  ++ s"/" ++ nick in
		sendPresence config ((XMPP.emptyPresence XMPP.PresenceUnavailable) {
			XMPP.presenceFrom = XMPP.parseJID $ bareTxt source ++ s"/" ++ source_nick
		}) target
	forM_ old $ \(muc, nick, source_nick, count) ->
		let
			Just target = XMPP.parseJID $ muc  ++ s"/" ++ nick
			Just source = XMPP.parseJID $ bareTxt source ++ s"/" ++ source_nick
		in
		if count > (1::Int) then
			mkSession config XMPP.PresenceUnavailable (Just source) target
		else
			sendPresence config ((XMPP.emptyPresence XMPP.PresenceUnavailable) {
				XMPP.presenceFrom = Just source
			}) target

mkSession :: (MonadIO m) =>
	   Config.Config