From f2f8b81fc45fde57c02009bad1658dddd179dd6d Mon Sep 17 00:00:00 2001 From: sn0w Date: Fri, 17 Jun 2022 14:17:48 +0200 Subject: [PATCH] Use mediaproxy for emoji notifications if enabled --- .../mastodon_api/views/notification_view.ex | 3 +- .../views/notification_view_test.exs | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/mastodon_api/views/notification_view.ex b/lib/pleroma/web/mastodon_api/views/notification_view.ex index ff7adeb2b..bb156799e 100644 --- a/lib/pleroma/web/mastodon_api/views/notification_view.ex +++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex @@ -14,6 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do alias Pleroma.Web.AdminAPI.Report alias Pleroma.Web.AdminAPI.ReportView alias Pleroma.Web.CommonAPI + alias Pleroma.Web.MediaProxy alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.MastodonAPI.NotificationView alias Pleroma.Web.MastodonAPI.StatusView @@ -140,7 +141,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do defp put_emoji(response, activity) do response |> Map.put(:emoji, activity.data["content"]) - |> Map.put(:emoji_url, Pleroma.Emoji.emoji_url(activity.data)) + |> Map.put(:emoji_url, MediaProxy.url(Pleroma.Emoji.emoji_url(activity.data))) end defp put_chat_message(response, activity, reading_user, opts) do diff --git a/test/pleroma/web/mastodon_api/views/notification_view_test.exs b/test/pleroma/web/mastodon_api/views/notification_view_test.exs index 31744a59d..b5e36c86b 100644 --- a/test/pleroma/web/mastodon_api/views/notification_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/notification_view_test.exs @@ -12,6 +12,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do alias Pleroma.Object alias Pleroma.Repo alias Pleroma.User + alias Pleroma.Web.ActivityPub.Builder + alias Pleroma.Web.ActivityPub.Pipeline alias Pleroma.Web.AdminAPI.Report alias Pleroma.Web.AdminAPI.ReportView alias Pleroma.Web.CommonAPI @@ -19,6 +21,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.MastodonAPI.NotificationView alias Pleroma.Web.MastodonAPI.StatusView + alias Pleroma.Web.MediaProxy alias Pleroma.Web.PleromaAPI.Chat.MessageReferenceView import Pleroma.Factory @@ -224,6 +227,47 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do test_notifications_rendering([notification], user, [expected]) end + test "EmojiReact notification with remote custom emoji" do + proxyBaseUrl = "https://cache.pleroma.social" + clear_config([:media_proxy, :base_url], proxyBaseUrl) + + for testProxy <- [true, false] do + clear_config([:media_proxy, :enabled], testProxy) + + user = insert(:user) + other_user = insert(:user, local: false) + + {:ok, activity} = CommonAPI.post(user, %{status: "#morb"}) + {:ok, emoji_react, _} = Builder.emoji_react(other_user, Object.normalize(activity, fetch: false), ":100a:") + + remoteUrl = "http://evil.website/emoji/100a.png" + [tag] = emoji_react["tag"] + tag = put_in(tag["id"], remoteUrl) + tag = put_in(tag["icon"]["url"], remoteUrl) + emoji_react = put_in(emoji_react["tag"], [tag]) + + {:ok, _activity, _} = Pipeline.common_pipeline(emoji_react, local: false) + + activity = Repo.get(Activity, activity.id) + + [notification] = Notification.for_user(user) + + assert notification + + expected = %{ + id: to_string(notification.id), + pleroma: %{is_seen: false, is_muted: false}, + type: "pleroma:emoji_reaction", + emoji: ":100a:", + emoji_url: (if testProxy, do: MediaProxy.encode_url(remoteUrl), else: remoteUrl), + account: AccountView.render("show.json", %{user: other_user, for: user}), + status: StatusView.render("show.json", %{activity: activity, for: user}), + created_at: Utils.to_masto_date(notification.inserted_at) + } + test_notifications_rendering([notification], user, [expected]) + end + end + test "Poll notification" do user = insert(:user) activity = insert(:question_activity, user: user)