~singpolyma/cheogram

7fa9119167690ae97aced7d374e08ccc5242f5aa — Stephen Paul Weber 8 years ago 0baad80
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
1 files changed, 3 insertions(+), 2 deletions(-)

M Main.hs
M Main.hs => Main.hs +3 -2
@@ 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