Use mediaproxy for emoji notifications if enabled
authorsn0w <me@sn0w.cx>
Fri, 17 Jun 2022 12:17:48 +0000 (14:17 +0200)
committersn0w <me@sn0w.cx>
Fri, 17 Jun 2022 12:27:22 +0000 (14:27 +0200)
lib/pleroma/web/mastodon_api/views/notification_view.ex
test/pleroma/web/mastodon_api/views/notification_view_test.exs

index ff7adeb2b303e6ead43e32697f8569bc2266b6d5..bb156799ea21f0d9621bd296c334c295a3c73f19 100644 (file)
@@ -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
index 31744a59dc2dfededeaa06c3a56e1a3b35daad38..b5e36c86b3a6fa12b11e2c368dcb41383a040768 100644 (file)
@@ -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)