@ -7,8 +7,8 @@ import Control.Concurrent.STM
import Network.Xmpp.Types
import Network.Xmpp.Types
import Network.Xmpp.Concurrent.Basic
import Network.Xmpp.Concurrent.Basic
-- | Read an element from the inbound stanza channel, discardes any
-- | Draw and discard stanzas from the inbound channel until a message or
-- non-Message stanzas from the channel
-- message error is found. Returns the message or message error with annotations.
pullMessage :: Session -> IO ( Either ( Annotated MessageError ) ( Annotated Message ) )
pullMessage :: Session -> IO ( Either ( Annotated MessageError ) ( Annotated Message ) )
pullMessage session = do
pullMessage session = do
( stanza , as ) <- atomically . readTChan $ stanzaCh session
( stanza , as ) <- atomically . readTChan $ stanzaCh session
@ -17,16 +17,18 @@ pullMessage session = do
MessageErrorS e -> return $ Left ( e , as )
MessageErrorS e -> return $ Left ( e , as )
_ -> pullMessage session
_ -> pullMessage session
-- | Get the next received message with plugin Annotations
-- | Draw and discard stanzas from the inbound channel until a message is
-- found. Returns the message with annotations.
getMessageA :: Session -> IO ( Annotated Message )
getMessageA :: Session -> IO ( Annotated Message )
getMessageA = waitForMessageA ( const True )
getMessageA = waitForMessageA ( const True )
-- | Get the next received message
-- | Draw and discard stanzas from the inbound channel until a message is
-- found. Returns the message.
getMessage :: Session -> IO Message
getMessage :: Session -> IO Message
getMessage s = fst <$> getMessageA s
getMessage s = fst <$> getMessageA s
-- | Pulls a (non-error) message and returns it if the given predicate returns
-- | Draw and discard stanzas from the inbound channel until a message matching
-- @True@ .
-- the given predicate is found. Returns the matching message with annotations .
waitForMessageA :: ( Annotated Message -> Bool ) -> Session -> IO ( Annotated Message )
waitForMessageA :: ( Annotated Message -> Bool ) -> Session -> IO ( Annotated Message )
waitForMessageA f session = do
waitForMessageA f session = do
s <- pullMessage session
s <- pullMessage session
@ -35,10 +37,14 @@ waitForMessageA f session = do
Right m | f m -> return m
Right m | f m -> return m
| otherwise -> waitForMessageA f session
| otherwise -> waitForMessageA f session
-- | Draw and discard stanzas from the inbound channel until a message matching
-- the given predicate is found. Returns the matching message.
waitForMessage :: ( Message -> Bool ) -> Session -> IO Message
waitForMessage :: ( Message -> Bool ) -> Session -> IO Message
waitForMessage f s = fst <$> waitForMessageA ( f . fst ) s
waitForMessage f s = fst <$> waitForMessageA ( f . fst ) s
-- | Pulls an error message and returns it if the given predicate returns @True@.
-- | Draw and discard stanzas from the inbound channel until a message error
-- matching the given predicate is found. Returns the matching message error with
-- annotations.
waitForMessageErrorA :: ( Annotated MessageError -> Bool )
waitForMessageErrorA :: ( Annotated MessageError -> Bool )
-> Session
-> Session
-> IO ( Annotated MessageError )
-> IO ( Annotated MessageError )
@ -49,10 +55,14 @@ waitForMessageErrorA f session = do
Left m | f m -> return m
Left m | f m -> return m
| otherwise -> waitForMessageErrorA f session
| otherwise -> waitForMessageErrorA f session
-- | Draw and discard stanzas from the inbound channel until a message error
-- matching the given predicate is found. Returns the matching message error
waitForMessageError :: ( MessageError -> Bool ) -> Session -> IO MessageError
waitForMessageError :: ( MessageError -> Bool ) -> Session -> IO MessageError
waitForMessageError f s = fst <$> waitForMessageErrorA ( f . fst ) s
waitForMessageError f s = fst <$> waitForMessageErrorA ( f . fst ) s
-- | Pulls a message and returns it if the given predicate returns @True@.
-- | Draw and discard stanzas from the inbound channel until a message or
-- message error matching the given respective predicate is found. Returns the
-- matching message or message error with annotations
filterMessagesA :: ( Annotated MessageError -> Bool )
filterMessagesA :: ( Annotated MessageError -> Bool )
-> ( Annotated Message -> Bool )
-> ( Annotated Message -> Bool )
-> Session -> IO ( Either ( Annotated MessageError )
-> Session -> IO ( Either ( Annotated MessageError )
@ -65,6 +75,9 @@ filterMessagesA f g session = do
Right m | g m -> return $ Right m
Right m | g m -> return $ Right m
| otherwise -> filterMessagesA f g session
| otherwise -> filterMessagesA f g session
-- | Draw and discard stanzas from the inbound channel until a message or
-- message error matching the given respective predicate is found. Returns the
-- matching message or message error.
filterMessages :: ( MessageError -> Bool )
filterMessages :: ( MessageError -> Bool )
-> ( Message -> Bool )
-> ( Message -> Bool )
-> Session
-> Session