Update
This commit is contained in:
parent
188bc08494
commit
4af88f3e1d
44 changed files with 1041 additions and 34 deletions
84
lib/nulla_web/controllers/activitypub/follow_json.ex
Normal file
84
lib/nulla_web/controllers/activitypub/follow_json.ex
Normal file
|
@ -0,0 +1,84 @@
|
|||
defmodule NullaWeb.ActivityPub.FollowJSON do
|
||||
def following(actor, total) do
|
||||
Jason.OrderedObject.new(
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
id: "#{actor.ap_id}/following",
|
||||
type: "OrderedCollection",
|
||||
totalItems: total,
|
||||
first: "#{actor.ap_id}/following?page=1"
|
||||
)
|
||||
end
|
||||
|
||||
def following(actor, total, following_list, page, limit) when is_integer(page) and page > 0 do
|
||||
data = [
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
id: "#{actor.ap_id}/following?page=#{page}",
|
||||
type: "OrderedCollectionPage",
|
||||
totalItems: total,
|
||||
next: "#{actor.ap_id}/following?page=#{page + 1}",
|
||||
prev: "#{actor.ap_id}/following?page=#{page - 1}",
|
||||
partOf: "#{actor.ap_id}/following",
|
||||
orderedItems: following_list
|
||||
]
|
||||
|
||||
data =
|
||||
if page <= 1 do
|
||||
Keyword.delete(data, :prev)
|
||||
else
|
||||
data
|
||||
end
|
||||
|
||||
data =
|
||||
if page * limit > total do
|
||||
data
|
||||
|> Keyword.delete(:next)
|
||||
|> Keyword.delete(:prev)
|
||||
else
|
||||
data
|
||||
end
|
||||
|
||||
Jason.OrderedObject.new(data)
|
||||
end
|
||||
|
||||
def followers(actor, total) do
|
||||
Jason.OrderedObject.new(
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
id: "#{actor.ap_id}/followers",
|
||||
type: "OrderedCollection",
|
||||
totalItems: total,
|
||||
first: "#{actor.ap_id}/followers?page=1"
|
||||
)
|
||||
end
|
||||
|
||||
def followers(actor, total, followers_list, page, limit)
|
||||
when is_integer(page) and page > 0 do
|
||||
data = [
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
id: "#{actor.ap_id}/followers?page=#{page}",
|
||||
type: "OrderedCollectionPage",
|
||||
totalItems: total,
|
||||
next: "#{actor.ap_id}/followers?page=#{page + 1}",
|
||||
prev: "#{actor.ap_id}/followers?page=#{page - 1}",
|
||||
partOf: "#{actor.ap_id}/followers",
|
||||
orderedItems: followers_list
|
||||
]
|
||||
|
||||
data =
|
||||
if page <= 1 do
|
||||
Keyword.delete(data, :prev)
|
||||
else
|
||||
data
|
||||
end
|
||||
|
||||
data =
|
||||
if page * limit > total do
|
||||
data
|
||||
|> Keyword.delete(:next)
|
||||
|> Keyword.delete(:prev)
|
||||
else
|
||||
data
|
||||
end
|
||||
|
||||
Jason.OrderedObject.new(data)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue