mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-24 10:07:24 +00:00
Merge branch '1976-status-view-fixes' into 'develop'
StatusView: Handle badly formatted emoji reactions. Closes #1976 See merge request pleroma/pleroma!2788
This commit is contained in:
commit
6100b90209
|
@ -297,13 +297,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
|
|
||||||
emoji_reactions =
|
emoji_reactions =
|
||||||
with %{data: %{"reactions" => emoji_reactions}} <- object do
|
with %{data: %{"reactions" => emoji_reactions}} <- object do
|
||||||
Enum.map(emoji_reactions, fn [emoji, users] ->
|
Enum.map(emoji_reactions, fn
|
||||||
%{
|
[emoji, users] when is_list(users) ->
|
||||||
name: emoji,
|
build_emoji_map(emoji, users, opts[:for])
|
||||||
count: length(users),
|
|
||||||
me: !!(opts[:for] && opts[:for].ap_id in users)
|
{emoji, users} when is_list(users) ->
|
||||||
}
|
build_emoji_map(emoji, users, opts[:for])
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
nil
|
||||||
end)
|
end)
|
||||||
|
|> Enum.reject(&is_nil/1)
|
||||||
else
|
else
|
||||||
_ -> []
|
_ -> []
|
||||||
end
|
end
|
||||||
|
@ -545,4 +549,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
|
|
||||||
defp pinned?(%Activity{id: id}, %User{pinned_activities: pinned_activities}),
|
defp pinned?(%Activity{id: id}, %User{pinned_activities: pinned_activities}),
|
||||||
do: id in pinned_activities
|
do: id in pinned_activities
|
||||||
|
|
||||||
|
defp build_emoji_map(emoji, users, current_user) do
|
||||||
|
%{
|
||||||
|
name: emoji,
|
||||||
|
count: length(users),
|
||||||
|
me: !!(current_user && current_user.ap_id in users)
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,6 +56,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "works correctly with badly formatted emojis" do
|
||||||
|
user = insert(:user)
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{status: "yo"})
|
||||||
|
|
||||||
|
activity
|
||||||
|
|> Object.normalize(false)
|
||||||
|
|> Object.update_data(%{"reactions" => %{"☕" => [user.ap_id], "x" => 1}})
|
||||||
|
|
||||||
|
activity = Activity.get_by_id(activity.id)
|
||||||
|
|
||||||
|
status = StatusView.render("show.json", activity: activity, for: user)
|
||||||
|
|
||||||
|
assert status[:pleroma][:emoji_reactions] == [
|
||||||
|
%{name: "☕", count: 1, me: true}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do
|
test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue