return followers collection
This commit is contained in:
parent
75a26715d0
commit
0db710272a
4 changed files with 57 additions and 10 deletions
|
@ -80,7 +80,9 @@ routes db detailsFile =
|
||||||
, -- Followers
|
, -- Followers
|
||||||
Twain.get (Fedi.matchFollowers $ unsafePerformIO $ fetchUserDetails detailsFile) do
|
Twain.get (Fedi.matchFollowers $ unsafePerformIO $ fetchUserDetails detailsFile) do
|
||||||
details <- liftIO $ fetchUserDetails detailsFile
|
details <- liftIO $ fetchUserDetails detailsFile
|
||||||
Fedi.handleFollowers details
|
followers <- liftIO db.getFollowers
|
||||||
|
<&> map (\follower -> T.unpack follower.actorId)
|
||||||
|
Fedi.handleFollowers details followers
|
||||||
, -- Following
|
, -- Following
|
||||||
Twain.get (Fedi.matchFollowing $ unsafePerformIO $ fetchUserDetails detailsFile) do
|
Twain.get (Fedi.matchFollowing $ unsafePerformIO $ fetchUserDetails detailsFile) do
|
||||||
details <- liftIO $ fetchUserDetails detailsFile
|
details <- liftIO $ fetchUserDetails detailsFile
|
||||||
|
|
|
@ -15,16 +15,57 @@ matchFollowers :: UserDetails -> Twain.PathPattern
|
||||||
matchFollowers details =
|
matchFollowers details =
|
||||||
fromString ("/" <> details.username <> "/followers")
|
fromString ("/" <> details.username <> "/followers")
|
||||||
|
|
||||||
handleFollowers :: UserDetails -> Twain.ResponderM b
|
handleFollowers :: UserDetails -> [Url] -> Twain.ResponderM b
|
||||||
handleFollowers details = do
|
handleFollowers details items = do
|
||||||
|
isPage <- Twain.queryParamMaybe "page"
|
||||||
let
|
let
|
||||||
collection :: Collection ()
|
followersUrl =
|
||||||
collection =
|
"https://"
|
||||||
emptyUnorderedCollection
|
<> details.domain
|
||||||
{ id = Just $ ObjectId $ actorUrl details <> "/followers"
|
<> "/"
|
||||||
|
<> details.username
|
||||||
|
<> "/followers"
|
||||||
|
response =
|
||||||
|
case isPage of
|
||||||
|
Just True ->
|
||||||
|
let
|
||||||
|
empty = emptyOrderedCollectionPage followersUrl
|
||||||
|
content :: FollowersPage
|
||||||
|
content =
|
||||||
|
empty
|
||||||
|
{ id = Just $ ObjectId $ followersUrl <> "?page=true"
|
||||||
, summary = Just $ fromString $ details.username <> "'s followers"
|
, summary = Just $ fromString $ details.username <> "'s followers"
|
||||||
|
, otype =
|
||||||
|
empty.otype
|
||||||
|
{ ctype =
|
||||||
|
empty.otype.ctype
|
||||||
|
{ partOf = followersUrl
|
||||||
|
, porderedItems = items
|
||||||
}
|
}
|
||||||
Twain.send $ jsonLD (A.encode collection)
|
}
|
||||||
|
}
|
||||||
|
in
|
||||||
|
A.encode content
|
||||||
|
_ ->
|
||||||
|
let
|
||||||
|
content :: Followers
|
||||||
|
content =
|
||||||
|
emptyOrderedCollection
|
||||||
|
{ id = Just $ ObjectId followersUrl
|
||||||
|
, summary = Just $ fromString $ details.username <> "'s followers"
|
||||||
|
, otype =
|
||||||
|
emptyOrderedCollection.otype
|
||||||
|
{ ctype =
|
||||||
|
emptyOrderedCollection.otype.ctype
|
||||||
|
{ orderedItems = items
|
||||||
|
}
|
||||||
|
, first = Just $ followersUrl <> "?page=true"
|
||||||
|
, last = Just $ followersUrl <> "?page=true"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
in
|
||||||
|
A.encode content
|
||||||
|
Twain.send $ jsonLD response
|
||||||
|
|
||||||
-- * Following
|
-- * Following
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ handleOutbox details items = do
|
||||||
content =
|
content =
|
||||||
empty
|
empty
|
||||||
{ id = Just $ ObjectId $ outboxUrl <> "?page=true"
|
{ id = Just $ ObjectId $ outboxUrl <> "?page=true"
|
||||||
|
, summary = Just $ fromString $ details.username <> "'s notes"
|
||||||
, otype =
|
, otype =
|
||||||
empty.otype
|
empty.otype
|
||||||
{ ctype =
|
{ ctype =
|
||||||
|
|
|
@ -535,6 +535,9 @@ type Outbox = OrderedCollection AnyActivity
|
||||||
|
|
||||||
type OutboxPage = OrderedCollectionPage AnyActivity
|
type OutboxPage = OrderedCollectionPage AnyActivity
|
||||||
|
|
||||||
|
type Followers = OrderedCollection Url
|
||||||
|
type FollowersPage = OrderedCollectionPage Url
|
||||||
|
|
||||||
data CollectionType t
|
data CollectionType t
|
||||||
= CollectionType
|
= CollectionType
|
||||||
{ ctype :: t
|
{ ctype :: t
|
||||||
|
|
Loading…
Add table
Reference in a new issue