add pinned property to StatusView

This commit is contained in:
Egor Kislitsyn 2019-01-08 15:27:02 +07:00
parent 63dbd87568
commit e679da4c34
3 changed files with 11 additions and 5 deletions

View file

@ -76,6 +76,7 @@ def render(
reblogged: false, reblogged: false,
favourited: false, favourited: false,
muted: false, muted: false,
pinned: pinned?(activity, user),
sensitive: false, sensitive: false,
spoiler_text: "", spoiler_text: "",
visibility: "public", visibility: "public",
@ -142,6 +143,7 @@ def render("status.json", %{activity: %{data: %{"object" => object}} = activity}
reblogged: present?(repeated), reblogged: present?(repeated),
favourited: present?(favorited), favourited: present?(favorited),
muted: false, muted: false,
pinned: pinned?(activity, user),
sensitive: sensitive, sensitive: sensitive,
spoiler_text: object["summary"] || "", spoiler_text: object["summary"] || "",
visibility: get_visibility(object), visibility: get_visibility(object),
@ -295,4 +297,7 @@ def build_emojis(emojis) do
defp present?(nil), do: false defp present?(nil), do: false
defp present?(false), do: false defp present?(false), do: false
defp present?(_), do: true defp present?(_), do: true
defp pinned?(%Activity{id: id}, %User{info: %{pinned_activities: pinned_activities}}),
do: id in pinned_activities
end end

View file

@ -1489,7 +1489,7 @@ test "returns pinned statuses", %{conn: conn} do
id_str = Integer.to_string(activity.id) id_str = Integer.to_string(activity.id)
assert [%{"id" => ^id_str}] = result assert [%{"id" => ^id_str, "pinned" => true}] = result
end end
test "pin status", %{conn: conn} do test "pin status", %{conn: conn} do
@ -1499,14 +1499,14 @@ test "pin status", %{conn: conn} do
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"}) {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
id_str = Integer.to_string(activity.id) id_str = Integer.to_string(activity.id)
assert %{"id" => ^id_str} = assert %{"id" => ^id_str, "pinned" => true} =
conn conn
|> assign(:user, user) |> assign(:user, user)
|> post("/api/v1/statuses/#{activity.id}/pin") |> post("/api/v1/statuses/#{activity.id}/pin")
|> Map.get(:resp_body) |> Map.get(:resp_body)
|> Jason.decode!() |> Jason.decode!()
assert [%{"id" => ^id_str}] = assert [%{"id" => ^id_str, "pinned" => true}] =
conn conn
|> assign(:user, user) |> assign(:user, user)
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true") |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
@ -1524,7 +1524,7 @@ test "unpin status", %{conn: conn} do
id_str = Integer.to_string(activity.id) id_str = Integer.to_string(activity.id)
user = User.get_by_ap_id(user.ap_id) user = User.get_by_ap_id(user.ap_id)
assert %{"id" => ^id_str} = assert %{"id" => ^id_str, "pinned" => false} =
conn conn
|> assign(:user, user) |> assign(:user, user)
|> post("/api/v1/statuses/#{activity.id}/unpin") |> post("/api/v1/statuses/#{activity.id}/unpin")
@ -1549,7 +1549,7 @@ test "max pinned statuses", %{conn: conn} do
id_str_one = Integer.to_string(activity_one.id) id_str_one = Integer.to_string(activity_one.id)
assert %{"id" => ^id_str_one} = assert %{"id" => ^id_str_one, "pinned" => true} =
conn conn
|> assign(:user, user) |> assign(:user, user)
|> post("/api/v1/statuses/#{id_str_one}/pin") |> post("/api/v1/statuses/#{id_str_one}/pin")

View file

@ -63,6 +63,7 @@ test "a note activity" do
reblogged: false, reblogged: false,
favourited: false, favourited: false,
muted: false, muted: false,
pinned: false,
sensitive: false, sensitive: false,
spoiler_text: note.data["object"]["summary"], spoiler_text: note.data["object"]["summary"],
visibility: "public", visibility: "public",