From 7fa9119167690ae97aced7d374e08ccc5242f5aa Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 1 Dec 2015 10:40:45 -0500 Subject: [PATCH] Check if someone is in the room before saying the join It seems GTalk repeatedly sends presence to the room, even when already joined, which was causing many extra messages. Closes #4 --- Main.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Main.hs b/Main.hs index 0cd449b..35c48df 100644 --- a/Main.hs +++ b/Main.hs @@ -271,8 +271,9 @@ componentStanza db toVitelity _ _ (ReceivedPresence p@(Presence { presenceType = writeStanzaChan toVitelity $ mkSMS tel (fromString "* You have left " <> bareTxt from) componentStanza db toVitelity _ _ (ReceivedPresence (Presence { presenceType = typ, presenceFrom = Just from, presenceTo = Just to })) | Just tel <- strNode <$> jidNode to = do + presence <- fmap (fromMaybe [] . (readZ =<<)) (TC.runTCM $ TC.get db (T.unpack (bareTxt from) <> "\0presence")) existingRoom <- tcGetJID db tel "joined" - when (fmap bareTxt existingRoom == Just (bareTxt from)) $ + when (fmap bareTxt existingRoom == Just (bareTxt from) && not (resourceFrom `elem` presence)) $ writeStanzaChan toVitelity $ mkSMS tel $ mconcat [ fromString "* ", resourceFrom, @@ -450,8 +451,8 @@ component db toVitelity toComponent componentHost = do forever $ do s <- getStanza - liftIO $ storePresence db s liftIO $ componentStanza db toVitelity toComponent componentHost s + liftIO $ storePresence db s liftIO $ killThread thread -- 2.38.5