~singpolyma/cheogram-muc-bridge

380691995804ec9f33b8c51b09fb674c1854d53f — Stephen Paul Weber 1 year, 10 months ago 4471e1a
isGhost helper
1 files changed, 11 insertions(+), 4 deletions(-)

M Session.hs
M Session.hs => Session.hs +11 -4
@@ 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 {