@@ 59,6 59,15 @@ sendPresence config presence targetMuc =
sendPresenceToMUC config presence
(Config.MUC targetMuc (s"XMPP") Nothing Nothing) (s"XMPP")
+isGhost :: (MonadIO m) => Config.Config -> XMPP.JID -> m Bool
+isGhost config from = do
+ ghost <- liftIO $ DB.query (Config.db config)
+ (s"SELECT COUNT(1) FROM sessions WHERE target_muc = ? AND target_nick = ? LIMIT 1")
+ (bareTxt from, nick)
+ return (ghost /= [DB.Only (0::Int)])
+ where
+ nick = fromMaybe mempty $ XMPP.strResource <$> XMPP.jidResource from
+
sendPresenceToMUC :: Config.Config -> XMPP.Presence -> Config.MUC -> Text -> XMPP.XMPP ()
sendPresenceToMUC config presence@XMPP.Presence {
XMPP.presenceFrom = Just from@XMPP.JID {
@@ 67,10 76,8 @@ sendPresenceToMUC config presence@XMPP.Presence {
XMPP.presenceType = typ,
XMPP.presencePayloads = payloads
} targetMuc tag = do
- 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
+ ghost <- isGhost config from
+ when (not ghost) $ do
mkSession config typ (Just from) target
XMPP.putStanza $ presence {