diff options
author | 2012-11-02 21:13:06 -0400 | |
---|---|---|
committer | 2012-11-02 21:13:06 -0400 | |
commit | df24b5661e7728a1ca37ec8e7001ca50b300725e (patch) | |
tree | 87d044aade7598abe74e454f04d3c2708ca8ebd4 /Assistant/Types/Buddies.hs | |
parent | c3bd80207051ca96d9d172e29ba600dec25df113 (diff) |
add buddy list to pairing UI
Diffstat (limited to 'Assistant/Types/Buddies.hs')
-rw-r--r-- | Assistant/Types/Buddies.hs | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/Assistant/Types/Buddies.hs b/Assistant/Types/Buddies.hs index 06ac5526d..9c070aa6a 100644 --- a/Assistant/Types/Buddies.hs +++ b/Assistant/Types/Buddies.hs @@ -14,16 +14,37 @@ import Common.Annex import qualified Data.Map as M import Control.Concurrent.STM import Utility.NotificationBroadcaster +import Data.Text as T -{- When XMPP is enabled, this is an XMPP buddy map. - - Otherwise, it's an empty map, for simplicity. -} +{- For simplicity, dummy types are defined even when XMPP is disabled. -} #ifdef WITH_XMPP -import Assistant.XMPP.Buddies +import Network.Protocol.XMPP +import Data.Set as S +import Data.Ord + +newtype Client = Client JID + deriving (Eq, Show) + +instance Ord Client where + compare = comparing show + +data Buddy = Buddy + { buddyPresent :: S.Set Client + , buddyAway :: S.Set Client + , buddyAssistants :: S.Set Client + } #else -type Buddies = M.Map String Buddy data Buddy - deriving (Eq) #endif + deriving (Eq, Show) + +data BuddyID = BuddyID T.Text + deriving (Eq, Ord, Show, Read) + +data BuddyKey = BuddyKey T.Text + deriving (Eq, Ord, Show) + +type Buddies = M.Map BuddyKey Buddy {- A list of buddies, and a way to notify when it changes. -} type BuddyList = (TMVar Buddies, NotificationBroadcaster) @@ -39,6 +60,9 @@ newBuddyList = (,) getBuddyList :: BuddyList -> IO [Buddy] getBuddyList (v, _) = M.elems <$> atomically (readTMVar v) +getBuddyBroadcaster :: BuddyList -> NotificationBroadcaster +getBuddyBroadcaster (_, h) = h + {- Applies a function to modify the buddy list, and if it's changed, - sends notifications to any listeners. -} updateBuddyList :: (Buddies -> Buddies) -> BuddyList -> IO () @@ -50,8 +74,3 @@ updateBuddyList a (v, caster) = do return $ buds /= buds' when changed $ sendNotification caster - -{- Allocates a notification handle for a client to use to listen for - - changes to the buddy list. -} -newBuddyListNotificationHandle :: BuddyList -> IO NotificationHandle -newBuddyListNotificationHandle (_, caster) = newNotificationHandle caster |