forked from AkkomaGang/akkoma
Assign reblogged in the Mastodon reblog status view
This commit is contained in:
parent
050339c223
commit
679a8ef629
2 changed files with 44 additions and 7 deletions
|
@ -54,6 +54,11 @@ defp get_context_id(%{data: %{"context" => context}}) when is_binary(context),
|
||||||
|
|
||||||
defp get_context_id(_), do: nil
|
defp get_context_id(_), do: nil
|
||||||
|
|
||||||
|
defp reblogged?(activity, user) do
|
||||||
|
object = activity.data["object"] || %{}
|
||||||
|
present?(user && user.ap_id in (object["announcements"] || []))
|
||||||
|
end
|
||||||
|
|
||||||
def render("index.json", opts) do
|
def render("index.json", opts) do
|
||||||
replied_to_activities = get_replied_to_activities(opts.activities)
|
replied_to_activities = get_replied_to_activities(opts.activities)
|
||||||
|
|
||||||
|
@ -72,8 +77,8 @@ def render(
|
||||||
user = get_user(activity.data["actor"])
|
user = get_user(activity.data["actor"])
|
||||||
created_at = Utils.to_masto_date(activity.data["published"])
|
created_at = Utils.to_masto_date(activity.data["published"])
|
||||||
|
|
||||||
reblogged = Activity.get_create_by_object_ap_id(object)
|
reblogged_activity = Activity.get_create_by_object_ap_id(object)
|
||||||
reblogged = render("status.json", Map.put(opts, :activity, reblogged))
|
reblogged = render("status.json", Map.put(opts, :activity, reblogged_activity))
|
||||||
|
|
||||||
mentions =
|
mentions =
|
||||||
activity.recipients
|
activity.recipients
|
||||||
|
@ -94,7 +99,7 @@ def render(
|
||||||
reblogs_count: 0,
|
reblogs_count: 0,
|
||||||
replies_count: 0,
|
replies_count: 0,
|
||||||
favourites_count: 0,
|
favourites_count: 0,
|
||||||
reblogged: false,
|
reblogged: reblogged?(reblogged_activity, opts[:for]),
|
||||||
favourited: false,
|
favourited: false,
|
||||||
bookmarked: false,
|
bookmarked: false,
|
||||||
muted: false,
|
muted: false,
|
||||||
|
@ -132,7 +137,6 @@ def render("status.json", %{activity: %{data: %{"object" => object}} = activity}
|
||||||
|> Enum.filter(& &1)
|
|> Enum.filter(& &1)
|
||||||
|> Enum.map(fn user -> AccountView.render("mention.json", %{user: user}) end)
|
|> Enum.map(fn user -> AccountView.render("mention.json", %{user: user}) end)
|
||||||
|
|
||||||
repeated = opts[:for] && opts[:for].ap_id in (object["announcements"] || [])
|
|
||||||
favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || [])
|
favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || [])
|
||||||
bookmarked = opts[:for] && object["id"] in opts[:for].bookmarks
|
bookmarked = opts[:for] && object["id"] in opts[:for].bookmarks
|
||||||
|
|
||||||
|
@ -203,7 +207,7 @@ def render("status.json", %{activity: %{data: %{"object" => object}} = activity}
|
||||||
reblogs_count: announcement_count,
|
reblogs_count: announcement_count,
|
||||||
replies_count: object["repliesCount"] || 0,
|
replies_count: object["repliesCount"] || 0,
|
||||||
favourites_count: like_count,
|
favourites_count: like_count,
|
||||||
reblogged: present?(repeated),
|
reblogged: reblogged?(activity, opts[:for]),
|
||||||
favourited: present?(favorited),
|
favourited: present?(favorited),
|
||||||
bookmarked: present?(bookmarked),
|
bookmarked: present?(bookmarked),
|
||||||
muted: CommonAPI.thread_muted?(user, activity) || User.mutes?(opts[:for], user),
|
muted: CommonAPI.thread_muted?(user, activity) || User.mutes?(opts[:for], user),
|
||||||
|
|
|
@ -1008,8 +1008,41 @@ test "reblogs and returns the reblogged status", %{conn: conn} do
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> post("/api/v1/statuses/#{activity.id}/reblog")
|
|> post("/api/v1/statuses/#{activity.id}/reblog")
|
||||||
|
|
||||||
assert %{"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1}} =
|
assert %{
|
||||||
json_response(conn, 200)
|
"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},
|
||||||
|
"reblogged" => true
|
||||||
|
} = json_response(conn, 200)
|
||||||
|
|
||||||
|
assert to_string(activity.id) == id
|
||||||
|
end
|
||||||
|
|
||||||
|
test "reblogged status for another user", %{conn: conn} do
|
||||||
|
activity = insert(:note_activity)
|
||||||
|
user1 = insert(:user)
|
||||||
|
user2 = insert(:user)
|
||||||
|
user3 = insert(:user)
|
||||||
|
{:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)
|
||||||
|
{:ok, _, _object} = CommonAPI.repeat(activity.id, user2)
|
||||||
|
|
||||||
|
conn_res =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user3)
|
||||||
|
|> get("/api/v1/statuses/#{reblog_activity1.id}")
|
||||||
|
|
||||||
|
assert %{
|
||||||
|
"reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 2},
|
||||||
|
"reblogged" => false
|
||||||
|
} = json_response(conn_res, 200)
|
||||||
|
|
||||||
|
conn_res =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user2)
|
||||||
|
|> get("/api/v1/statuses/#{reblog_activity1.id}")
|
||||||
|
|
||||||
|
assert %{
|
||||||
|
"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 2},
|
||||||
|
"reblogged" => true
|
||||||
|
} = json_response(conn_res, 200)
|
||||||
|
|
||||||
assert to_string(activity.id) == id
|
assert to_string(activity.id) == id
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue