Browse Source

pass old roster to roster update callback

master
Philipp Balzarek 10 years ago
parent
commit
5ddfdc5815
  1. 2
      source/Network/Xmpp/Concurrent.hs
  2. 2
      source/Network/Xmpp/Concurrent/Types.hs
  3. 7
      source/Network/Xmpp/IM/Roster.hs

2
source/Network/Xmpp/Concurrent.hs

@ -188,7 +188,7 @@ newSession stream config realm mbSasl = runErrorT $ do
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 rosRef then [handleRoster boundJid rosRef
(fromMaybe (\_ -> return ()) $ onRosterPush config) (fromMaybe (\_ _ -> return ()) $ onRosterPush config)
(out)] (out)]
else [] else []
let presenceH = if (enablePresenceTracking config) let presenceH = if (enablePresenceTracking config)

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

@ -70,7 +70,7 @@ type Plugin = (XmppElement -> IO (Either XmppFailure ())) -- ^ pass stanza to
-- next plugin -- next plugin
-> ErrorT XmppFailure IO Plugin' -> ErrorT XmppFailure IO Plugin'
type RosterPushCallback = RosterUpdate -> IO () type RosterPushCallback = Roster -> RosterUpdate -> IO ()
-- | Configuration for the @Session@ object. -- | Configuration for the @Session@ object.
data SessionConfiguration = SessionConfiguration data SessionConfiguration = SessionConfiguration

7
source/Network/Xmpp/IM/Roster.hs

@ -133,15 +133,16 @@ handleRoster mbBoundJid ref onUpdate out sta _ = do
else return [(sta, [])] else return [(sta, [])]
_ -> return [(sta, [])] _ -> return [(sta, [])]
where where
handleUpdate v' update = handleUpdate v' update = do
oldRoster <- atomically $ readTVar ref
case qiSubscription update of case qiSubscription update of
Just Remove -> do Just Remove -> do
let j = qiJid update let j = qiJid update
onUpdate $ RosterUpdateRemove j onUpdate oldRoster $ RosterUpdateRemove j
updateRoster (Map.delete j) updateRoster (Map.delete j)
_ -> do _ -> do
let i = (toItem update) let i = (toItem update)
onUpdate $ RosterUpdateAdd i onUpdate oldRoster $ RosterUpdateAdd i
updateRoster $ Map.insert (qiJid update) i updateRoster $ Map.insert (qiJid update) i
where where
updateRoster f = atomically . modifyTVar ref $ updateRoster f = atomically . modifyTVar ref $

Loading…
Cancel
Save