~singpolyma/cheogram-muc-bridge

35e1fb63343cffada852a11406769eec36f29e42 — Stephen Paul Weber 3 years ago 4a61033
Keep knowledge of a ghost as long as possible

INSERT the ghost before we actually join them to the room. Only DELETE them
after we get the self-presence about them leaving.

Do not INSERT and join when we get presence errors or presence unavaiable!
2 files changed, 10 insertions(+), 3 deletions(-)

M Session.hs
M gateway.hs
M Session.hs => Session.hs +2 -1
@@ 80,7 80,8 @@ sendPresenceToMUC config presence@XMPP.Presence {
	let typ'
		| ghost = XMPP.PresenceUnavailable
		| otherwise = typ
	mkSession config typ' (Just from) target
	when (typ' == XMPP.PresenceAvailable) $
		mkSession config typ' (Just from) target

	XMPP.putStanza $ presence {
			XMPP.presenceType = typ',

M gateway.hs => gateway.hs +8 -2
@@ 41,9 41,11 @@ targets = map (Config.jid . fst) .: fullTargets
handlePresence :: Config.Config -> XMPP.Presence -> XMPP.XMPP ()
handlePresence config presence@XMPP.Presence {
	XMPP.presenceFrom = Just from,
	XMPP.presenceTo = Just to
	XMPP.presenceTo = Just to,
	XMPP.presenceType = typ
}
	| hasMucCode 110 presence, -- done joining room
	| 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)


@@ 54,6 56,10 @@ handlePresence config presence@XMPP.Presence {
				XMPP.strResource <$> XMPP.jidResource source,
				bareTxt from
			)
	| typ == XMPP.PresenceUnavailable,
	  hasMucCode 110 presence, -- done leaving room
	  Just source <- (XMPP.parseJID . unescapeJid . XMPP.strNode) =<< XMPP.jidNode to = do
		Session.mkSession config typ (Just source) from
	| bareTxt to /= bareTxt (Config.bridgeJid config) =
		-- This is to one of our ghosts, so just ignore it
		return ()