You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.8 KiB
78 lines
2.8 KiB
|
14 years ago
|
module Network.XMPP.Presence where
|
||
|
|
|
||
|
|
import Data.Text(Text)
|
||
|
|
import Network.XMPP.Types
|
||
|
|
|
||
|
14 years ago
|
|
||
|
|
presence :: Presence
|
||
|
|
presence = Presence { presenceID = Nothing
|
||
|
|
, presenceFrom = Nothing
|
||
|
|
, presenceTo = Nothing
|
||
|
|
, presenceLangTag = Nothing
|
||
|
|
, presenceType = Nothing
|
||
|
|
, presenceShowType = Nothing
|
||
|
|
, presenceStatus = Nothing
|
||
|
|
, presencePriority = Nothing
|
||
|
|
, presencePayload = []
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
presenceSubscribe :: JID -> Presence
|
||
|
14 years ago
|
presenceSubscribe to = presence { presenceTo = Just to
|
||
|
|
, presenceType = Just Subscribe
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
|
-- | Is presence a subscription request
|
||
|
|
isPresenceSubscribe :: Presence -> Bool
|
||
|
14 years ago
|
isPresenceSubscribe pres = presenceType pres == (Just Subscribe)
|
||
|
14 years ago
|
|
||
|
|
-- | Approve a subscripton of an entity
|
||
|
|
presenceSubscribed :: JID -> Presence
|
||
|
14 years ago
|
presenceSubscribed to = presence { presenceTo = Just to
|
||
|
|
, presenceType = Just Subscribed
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
|
-- | Is presence a subscription approval
|
||
|
|
isPresenceSubscribed :: Presence -> Bool
|
||
|
14 years ago
|
isPresenceSubscribed pres = presenceType pres == (Just Subscribed)
|
||
|
14 years ago
|
|
||
|
|
-- | End a subscription with an entity
|
||
|
|
presenceUnsubscribe :: JID -> Presence
|
||
|
14 years ago
|
presenceUnsubscribe to = presence { presenceTo = Just to
|
||
|
|
, presenceType = Just Unsubscribed
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
|
-- | Is presence an unsubscription request
|
||
|
|
isPresenceUnsubscribe :: Presence -> Bool
|
||
|
14 years ago
|
isPresenceUnsubscribe pres = presenceType pres == (Just Unsubscribe)
|
||
|
14 years ago
|
|
||
|
|
-- | Signals to the server that the client is available for communication
|
||
|
|
presenceOnline :: Presence
|
||
|
14 years ago
|
presenceOnline = presence
|
||
|
14 years ago
|
|
||
|
|
-- | Signals to the server that the client is no longer available for communication.
|
||
|
|
presenceOffline :: Presence
|
||
|
14 years ago
|
presenceOffline = presence {presenceType = Just Unavailable}
|
||
|
14 years ago
|
|
||
|
14 years ago
|
status
|
||
|
14 years ago
|
:: Maybe Text -- ^ Status message
|
||
|
|
-> Maybe ShowType -- ^ Status Type
|
||
|
|
-> Maybe Int -- ^ Priority
|
||
|
|
-> Presence
|
||
|
14 years ago
|
status txt showType prio = presence { presenceShowType = showType
|
||
|
|
, presencePriority = prio
|
||
|
|
, presenceStatus = txt
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
|
-- | Sets the current availability status. This implicitly sets the clients
|
||
|
|
-- status online
|
||
|
|
presenceAvail :: ShowType -> Presence
|
||
|
14 years ago
|
presenceAvail showType = status Nothing (Just showType) Nothing
|
||
|
14 years ago
|
|
||
|
|
-- | Sets the current status message. This implicitly sets the clients
|
||
|
|
-- status online
|
||
|
|
presenceMessage :: Text -> Presence
|
||
|
14 years ago
|
presenceMessage txt = status (Just txt) Nothing Nothing
|
||
|
14 years ago
|
|
||
|
|
-- | Adds a recipient to a presence notification
|
||
|
14 years ago
|
presTo :: Presence -> JID -> Presence
|
||
|
|
presTo pres to = pres{presenceTo = Just to}
|