Browse Source

add option to set initial roster (#85)

master
Philipp Balzarek 10 years ago
parent
commit
62779c4d7f
  1. 28
      ChangeLog.md
  2. 13
      source/Network/Xmpp/Concurrent.hs
  3. 3
      source/Network/Xmpp/Concurrent/Types.hs

28
ChangeLog.md

@ -1,23 +1,5 @@
# 0.3 to 0.4 # 0.4.5 to 0.4.6
* Support for the session element is now determined from stream features, the
## Major changes establishSession option was removed
* Added Lenses * An initial roster can now be set with the initialRoster session configuration
* Added Plugins option
## newly exported functions
* simpleAuth
* jid (QuasiQuoter)
* presenceUnsubscribed
* associatedErrorType
* mkStanzaError
## major bugs fixed
* Didn't check jid of IQResults
## incompatible changes
### IQ
* sendIQ returns an STM action rather than a TMVar
* sendIQ' takes a timeout parameter
* removed IQResponseTimeout from IQResponse data type
* renamed listenIQChan to listenIQ and changed return type from TChan to STM
* renamed dropIQChan to unlistenIQ

13
source/Network/Xmpp/Concurrent.hs

@ -166,13 +166,20 @@ newSession stream config realm mbSasl = runErrorT $ do
stanzaChan <- lift newTChanIO stanzaChan <- lift newTChanIO
iqHands <- lift $ newTVarIO (Map.empty, Map.empty) iqHands <- lift $ newTVarIO (Map.empty, Map.empty)
eh <- lift $ newEmptyTMVarIO eh <- lift $ newEmptyTMVarIO
ros <- liftIO . newTVarIO $ Roster Nothing Map.empty ros <- case enableRoster config of
False -> return $ Roster Nothing Map.empty
True -> do
mbRos <- liftIO $ initialRoster config
return $ case mbRos of
Nothing -> Roster Nothing Map.empty
Just r -> r
rosRef <- liftIO $ newTVarIO ros
peers <- liftIO . newTVarIO $ Peers Map.empty peers <- liftIO . newTVarIO $ Peers Map.empty
rew <- lift $ newTVarIO 60 rew <- lift $ newTVarIO 60
let out = writeStanza writeSem let out = writeStanza writeSem
boundJid <- liftIO $ withStream' (gets streamJid) stream boundJid <- liftIO $ withStream' (gets streamJid) stream
let rosterH = if (enableRoster config) let rosterH = if (enableRoster config)
then [handleRoster boundJid ros then [handleRoster boundJid rosRef
(fromMaybe (\_ -> return ()) $ onRosterPush config) (fromMaybe (\_ -> return ()) $ onRosterPush config)
out] out]
else [] else []
@ -200,7 +207,7 @@ newSession stream config realm mbSasl = runErrorT $ do
, eventHandlers = eh , eventHandlers = eh
, stopThreads = kill , stopThreads = kill
, conf = config , conf = config
, rosterRef = ros , rosterRef = rosRef
, presenceRef = peers , presenceRef = peers
, sendStanza' = sStanza , sendStanza' = sStanza
, sRealm = realm , sRealm = realm

3
source/Network/Xmpp/Concurrent/Types.hs

@ -85,6 +85,8 @@ data SessionConfiguration = SessionConfiguration
-- | Enable roster handling according to rfc 6121. See 'getRoster' to -- | Enable roster handling according to rfc 6121. See 'getRoster' to
-- acquire the current roster -- acquire the current roster
, enableRoster :: Bool , enableRoster :: Bool
-- | Initial Roster to user when versioned rosters are supported
, initialRoster :: IO (Maybe Roster)
-- | Callback called on a roster Push. The callback is called after the -- | Callback called on a roster Push. The callback is called after the
-- roster is updated -- roster is updated
, onRosterPush :: Maybe (QueryItem -> IO ()) , onRosterPush :: Maybe (QueryItem -> IO ())
@ -115,6 +117,7 @@ instance Default SessionConfiguration where
return . Text.pack . show $ curId return . Text.pack . show $ curId
, plugins = [] , plugins = []
, enableRoster = True , enableRoster = True
, initialRoster = return Nothing
, onRosterPush = Nothing , onRosterPush = Nothing
, enablePresenceTracking = True , enablePresenceTracking = True
, onPresenceChange = Nothing , onPresenceChange = Nothing

Loading…
Cancel
Save