summaryrefslogtreecommitdiff
path: root/Presence/ClientState.hs
blob: 30a5313199eaaa99163ff920f387caac36a0bcff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module ClientState where

import Control.Concurrent.STM
import Data.Text ( Text )
import Data.Int  ( Int8 )
import Data.Bits ( (.&.) )

import UTmp       ( ProcessID )
import XMPPServer ( Stanza )

data ClientState = ClientState
    { clientResource :: Text
    , clientUser :: Text
    , clientPid :: Maybe ProcessID
    , clientStatus :: TVar (Maybe Stanza)
    , clientFlags :: TVar Int8
    }

cf_available :: Int8
cf_available = 0x1
cf_interested :: Int8
cf_interested = 0x2

-- | True if the client has sent an initial presence
clientIsAvailable :: ClientState -> STM Bool
clientIsAvailable c  = do
    flgs <- readTVar (clientFlags c)
    return $ flgs .&. cf_available /= 0

-- | True if the client has requested a roster
clientIsInterested :: ClientState -> STM Bool
clientIsInterested c = do
    flgs <- readTVar (clientFlags c)
    return $ flgs .&. cf_interested /= 0