From 35e1fb63343cffada852a11406769eec36f29e42 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Thu, 22 Jul 2021 20:50:40 -0500 Subject: [PATCH] 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! --- Session.hs | 3 ++- gateway.hs | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Session.hs b/Session.hs index d3890e4..a28a6ed 100644 --- a/Session.hs +++ b/Session.hs @@ -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', diff --git a/gateway.hs b/gateway.hs index 652c455..498c01f 100644 --- a/gateway.hs +++ b/gateway.hs @@ -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 () -- 2.38.5