Fix emoji reactions for legacy 2-tuple formats
This commit is contained in:
parent
6d0cc8fa2a
commit
c5d946bc92
8 changed files with 147 additions and 14 deletions
|
|
@ -425,4 +425,30 @@ defmodule Pleroma.Object do
|
|||
end
|
||||
|
||||
def object_data_hashtags(_), do: []
|
||||
|
||||
def get_emoji_reactions(object) do
|
||||
reactions = object.data["reactions"]
|
||||
|
||||
if is_list(reactions) or is_map(reactions) do
|
||||
reactions
|
||||
|> Enum.map(fn
|
||||
[_emoji, users, _maybe_url] = item when is_list(users) ->
|
||||
item
|
||||
|
||||
[emoji, users] when is_list(users) ->
|
||||
[emoji, users, nil]
|
||||
|
||||
# This case is here to process the Map situation, which will happen
|
||||
# only with the legacy two-value format.
|
||||
{emoji, users} when is_list(users) ->
|
||||
[emoji, users, nil]
|
||||
|
||||
_ ->
|
||||
nil
|
||||
end)
|
||||
|> Enum.reject(&is_nil/1)
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -408,11 +408,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
end
|
||||
|
||||
def get_cached_emoji_reactions(object) do
|
||||
if is_list(object.data["reactions"]) do
|
||||
object.data["reactions"]
|
||||
else
|
||||
[]
|
||||
end
|
||||
Object.get_emoji_reactions(object)
|
||||
end
|
||||
|
||||
@spec add_like_to_object(Activity.t(), Object.t()) ::
|
||||
|
|
|
|||
|
|
@ -334,8 +334,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
|||
end
|
||||
|
||||
emoji_reactions =
|
||||
object.data
|
||||
|> Map.get("reactions", [])
|
||||
object
|
||||
|> Object.get_emoji_reactions()
|
||||
|> EmojiReactionController.filter_allowed_users(
|
||||
opts[:for],
|
||||
Map.get(opts, :with_muted, false)
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionController do
|
|||
def index(%{assigns: %{user: user}} = conn, %{id: activity_id} = params) do
|
||||
with true <- Pleroma.Config.get([:instance, :show_reactions]),
|
||||
%Activity{} = activity <- Activity.get_by_id_with_object(activity_id),
|
||||
%Object{data: %{"reactions" => reactions}} when is_list(reactions) <-
|
||||
Object.normalize(activity, fetch: false) do
|
||||
%Object{} = object <- Object.normalize(activity, fetch: false),
|
||||
reactions <- Object.get_emoji_reactions(object) do
|
||||
reactions =
|
||||
reactions
|
||||
|> filter(params)
|
||||
|
|
@ -60,9 +60,6 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionController do
|
|||
reactions
|
||||
|> Stream.map(fn
|
||||
[emoji, users, url] when is_list(users) -> filter_emoji.(emoji, users, url)
|
||||
{emoji, users, url} when is_list(users) -> filter_emoji.(emoji, users, url)
|
||||
{emoji, users} when is_list(users) -> filter_emoji.(emoji, users, nil)
|
||||
_ -> nil
|
||||
end)
|
||||
|> Stream.reject(&is_nil/1)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue