~singpolyma/cheogram

eacee5539280568b3d3b06653b43fd8546804842 — Stephen Paul Weber 9 years ago f68f2d5
Detect when have left a room
1 files changed, 10 insertions(+), 0 deletions(-)

M Main.hs
M Main.hs => Main.hs +10 -0
@@ 133,6 133,16 @@ componentStanza db toVitelity _ (ReceivedPresence p@(Presence { presenceFrom = J
	where
	bareMUC = bareTxt from
	roomNick = fromMaybe mempty (strResource <$> jidResource from)
componentStanza db toVitelity _ (ReceivedPresence p@(Presence { presenceType = PresenceUnavailable, presenceFrom = Just from, presenceTo = Just to }))
	| Just tel <- strNode <$> jidNode to = do
		existingRoom <- (parseJID . fromString =<<) <$> TC.runTCM (TC.get db $ T.unpack tel)
		when (existingRoom == Just from) $ do
			True <- TC.runTCM $ TC.out db $ T.unpack tel
			writeStanzaChan toVitelity $ (emptyMessage MessageChat) {
				messageTo = parseJID (tel <> fromString "@sms"),
				messagePayloads = [Element (fromString "{jabber:client}body") [] [NodeContent $ ContentText $ fromString "* You have left " <> bareTxt from]]
			}
			return ()
componentStanza _ _ toComponent (ReceivedIQ (IQ { iqType = typ, iqFrom = Just from, iqTo = to, iqID = id }))
	| typ `elem` [IQGet, IQSet] =
		writeStanzaChan toComponent $ (emptyIQ IQError) {