diff options
author | joe <joe@jerkface.net> | 2013-06-19 00:14:48 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2013-06-19 00:14:48 -0400 |
commit | 2a2126403c681e498c7980043fd18e9e904eae30 (patch) | |
tree | dde59d1c1f49465751132484608879e9182cfe47 /Presence/XMPPServer.hs | |
parent | 31aee2ac1bf2eb4ad1b2725659f6e6695c2f84d3 (diff) |
presence subscription API
Diffstat (limited to 'Presence/XMPPServer.hs')
-rw-r--r-- | Presence/XMPPServer.hs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs index 044ed9e4..4a859bc9 100644 --- a/Presence/XMPPServer.hs +++ b/Presence/XMPPServer.hs | |||
@@ -40,6 +40,33 @@ import Network.Socket | |||
40 | import Data.String | 40 | import Data.String |
41 | import Control.Monad.Trans.Maybe | 41 | import Control.Monad.Trans.Maybe |
42 | import Control.Monad.IO.Class | 42 | import Control.Monad.IO.Class |
43 | import Control.DeepSeq | ||
44 | import Control.Concurrent.STM | ||
45 | |||
46 | -- | Jabber ID (JID) datatype | ||
47 | data JID = JID { name :: Maybe ByteString | ||
48 | , server :: ByteString | ||
49 | , resource :: Maybe ByteString | ||
50 | } | ||
51 | deriving (Ord,Eq) | ||
52 | |||
53 | instance Show JID where | ||
54 | show (JID n s r ) = L.unpack $ fmap (<++>"@") n <?++> s <++?> fmap ("/"<++>) r | ||
55 | |||
56 | instance NFData JID where | ||
57 | rnf v@(JID n s r) = n `seq` s `seq` r `seq` () | ||
58 | |||
59 | jid user host rsrc = JID (Just user) host (Just rsrc) | ||
60 | |||
61 | data JabberShow = Offline | ||
62 | | Away | ||
63 | | Available | ||
64 | deriving (Show,Enum,Ord,Eq,Read) | ||
65 | |||
66 | data Presence = Presence JID JabberShow | ||
67 | |||
68 | instance NFData Presence where | ||
69 | rnf (Presence jid stat) = rnf jid `seq` stat `seq` () | ||
43 | 70 | ||
44 | 71 | ||
45 | class XMPPSession session where | 72 | class XMPPSession session where |
@@ -48,6 +75,7 @@ class XMPPSession session where | |||
48 | setResource :: session -> ByteString -> IO () | 75 | setResource :: session -> ByteString -> IO () |
49 | getJID :: session -> IO ByteString | 76 | getJID :: session -> IO ByteString |
50 | closeSession :: session -> IO () | 77 | closeSession :: session -> IO () |
78 | subscribeToPresence :: session -> Maybe JID -> IO (TChan Presence) | ||
51 | 79 | ||
52 | 80 | ||
53 | greet host = L.unlines | 81 | greet host = L.unlines |