Use mediaproxy for emoji notifications if enabled

This commit is contained in:
sn0w 2022-06-17 14:17:48 +02:00
parent f15c9e8b08
commit f2f8b81fc4
No known key found for this signature in database
GPG key ID: 52A4BAE175049057
2 changed files with 46 additions and 1 deletions

View 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

View 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)