From 2a2126403c681e498c7980043fd18e9e904eae30 Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 19 Jun 2013 00:14:48 -0400 Subject: presence subscription API --- Presence/XMPPServer.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'Presence/XMPPServer.hs') 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 import Data.String import Control.Monad.Trans.Maybe import Control.Monad.IO.Class +import Control.DeepSeq +import Control.Concurrent.STM + +-- | Jabber ID (JID) datatype +data JID = JID { name :: Maybe ByteString + , server :: ByteString + , resource :: Maybe ByteString + } + deriving (Ord,Eq) + +instance Show JID where + show (JID n s r ) = L.unpack $ fmap (<++>"@") n s <++?> fmap ("/"<++>) r + +instance NFData JID where + rnf v@(JID n s r) = n `seq` s `seq` r `seq` () + +jid user host rsrc = JID (Just user) host (Just rsrc) + +data JabberShow = Offline + | Away + | Available + deriving (Show,Enum,Ord,Eq,Read) + +data Presence = Presence JID JabberShow + +instance NFData Presence where + rnf (Presence jid stat) = rnf jid `seq` stat `seq` () class XMPPSession session where @@ -48,6 +75,7 @@ class XMPPSession session where setResource :: session -> ByteString -> IO () getJID :: session -> IO ByteString closeSession :: session -> IO () + subscribeToPresence :: session -> Maybe JID -> IO (TChan Presence) greet host = L.unlines -- cgit v1.2.3