Detect ghost presence from DB instead of by looking for tag in nick

This commit is contained in:
Stephen Paul Weber 2021-06-29 19:18:10 -05:00
parent 16411dd54d
commit 3d6657e165
No known key found for this signature in database
GPG Key ID: D11C2911CE519CDE
2 changed files with 16 additions and 13 deletions

View File

@ -62,17 +62,21 @@ sendPresence config presence@XMPP.Presence {
XMPP.presenceType = typ,
XMPP.presencePayloads = payloads
} targetMuc = do
mkSession config typ (Just from) target
ghost <- liftIO $ DB.query (Config.db config)
(s"SELECT COUNT(1) FROM sessions WHERE target_muc = ? AND target_nick = ? LIMIT 1")
(bareTxt from, fromNick)
when (ghost == [DB.Only (0::Int)]) $ do
mkSession config typ (Just from) target
XMPP.putStanza $ presence {
XMPP.presenceFrom = Just (proxyJid config from),
XMPP.presenceTo = Just target,
XMPP.presencePayloads = map (\payload ->
case XML.isNamed (s"{http://jabber.org/protocol/muc#user}x") payload of
[_] -> mucJoinX
_ -> payload
) payloads
}
XMPP.putStanza $ presence {
XMPP.presenceFrom = Just (proxyJid config from),
XMPP.presenceTo = Just target,
XMPP.presencePayloads = map (\payload ->
case XML.isNamed (s"{http://jabber.org/protocol/muc#user}x") payload of
[_] -> mucJoinX
_ -> payload
) payloads
}
where
target = maybeAddNick targetMuc (fromNick ++ s"[x]")
fromNick = XMPP.strResource fromResource

View File

@ -46,9 +46,8 @@ handlePresence config presence@XMPP.Presence {
return ()
| hasMucCode 110 presence = -- done joining room, clean up old data
Session.cleanOld config from
| Just resource <- XMPP.jidResource from,
not (s"[x]" `T.isInfixOf` XMPP.strResource resource) = forM_ (targets config from) $
Session.sendPresence config presence
| otherwise = forM_ (targets config from) $
Session.sendPresence config presence
handlePresence _ _ = return ()
handlePresenceError :: Config.Config -> XMPP.Presence -> XMPP.XMPP ()