diff options
author | joe <joe@jerkface.net> | 2013-07-07 00:21:34 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2013-07-07 00:21:34 -0400 |
commit | 9080a6583fc0515c4a8a086cf5f23d08ec2dc260 (patch) | |
tree | bfb9ccd6b9d408d996c3ff1f4417aa5afa16593c /Presence/ConfigFiles.hs | |
parent | f183eca9bc5b531f32ec9302e7c9a538a88beb9c (diff) |
getters for three new lists: others,pending,solicited.
Diffstat (limited to 'Presence/ConfigFiles.hs')
-rw-r--r-- | Presence/ConfigFiles.hs | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/Presence/ConfigFiles.hs b/Presence/ConfigFiles.hs index 6d36f4cd..d0d2ef63 100644 --- a/Presence/ConfigFiles.hs +++ b/Presence/ConfigFiles.hs | |||
@@ -18,16 +18,16 @@ type User = ByteString | |||
18 | configDir = ".presence" | 18 | configDir = ".presence" |
19 | buddyFile = "buddies" | 19 | buddyFile = "buddies" |
20 | subscriberFile = "subscribers" | 20 | subscriberFile = "subscribers" |
21 | otherFile = "others" | ||
22 | pendingFile = "pending" | ||
23 | solicitedFile = "solicited" | ||
21 | 24 | ||
22 | buddyPath :: User -> IO String | ||
23 | buddyPath user = do | ||
24 | ue <- getUserEntryForName (unpack user) | ||
25 | return $ (++("/"++configDir++"/"++buddyFile)) $ homeDirectory ue | ||
26 | 25 | ||
27 | subscriberPath :: User -> IO String | 26 | configPath :: User -> String -> IO String |
28 | subscriberPath user = do | 27 | configPath user filename = do |
29 | ue <- getUserEntryForName (unpack user) | 28 | ue <- getUserEntryForName (unpack user) |
30 | return $ (++("/"++configDir++"/"++subscriberFile)) $ homeDirectory ue | 29 | return $ (++("/"++configDir++"/"++filename)) $ homeDirectory ue |
30 | |||
31 | 31 | ||
32 | createConfigFile tag path = do | 32 | createConfigFile tag path = do |
33 | let dir = dropFileName path | 33 | let dir = dropFileName path |
@@ -47,11 +47,11 @@ addItem item tag path = | |||
47 | 47 | ||
48 | addBuddy :: User -> ByteString -> IO () | 48 | addBuddy :: User -> ByteString -> IO () |
49 | addBuddy user buddy = | 49 | addBuddy user buddy = |
50 | buddyPath user >>= addItem buddy "<? buddies ?>" | 50 | configPath user buddyFile >>= addItem buddy "<? buddies ?>" |
51 | 51 | ||
52 | addSubscriber :: User -> ByteString -> IO () | 52 | addSubscriber :: User -> ByteString -> IO () |
53 | addSubscriber user subscriber = | 53 | addSubscriber user subscriber = |
54 | subscriberPath user >>= addItem subscriber "<? subscribers ?>" | 54 | configPath user subscriberFile >>= addItem subscriber "<? subscribers ?>" |
55 | 55 | ||
56 | getConfigList path = | 56 | getConfigList path = |
57 | handle (\e -> if isDoesNotExistError e then (return []) else throw e) | 57 | handle (\e -> if isDoesNotExistError e then (return []) else throw e) |
@@ -61,7 +61,16 @@ getConfigList path = | |||
61 | >=> (\a -> seq (rnf a) (return a)) | 61 | >=> (\a -> seq (rnf a) (return a)) |
62 | 62 | ||
63 | getBuddies :: User -> IO [ByteString] | 63 | getBuddies :: User -> IO [ByteString] |
64 | getBuddies user = buddyPath user >>= getConfigList | 64 | getBuddies user = configPath user buddyFile >>= getConfigList |
65 | 65 | ||
66 | getSubscribers :: User -> IO [ByteString] | 66 | getSubscribers :: User -> IO [ByteString] |
67 | getSubscribers user = subscriberPath user >>= getConfigList | 67 | getSubscribers user = configPath user subscriberFile >>= getConfigList |
68 | |||
69 | getOthers :: User -> IO [ByteString] | ||
70 | getOthers user = configPath user otherFile >>= getConfigList | ||
71 | |||
72 | getPending :: User -> IO [ByteString] | ||
73 | getPending user = configPath user pendingFile >>= getConfigList | ||
74 | |||
75 | getSolicited :: User -> IO [ByteString] | ||
76 | getSolicited user = configPath user solicitedFile >>= getConfigList | ||