From: FloatingGhost Date: Sun, 12 Jun 2022 12:35:14 +0000 (+0100) Subject: Add emoji_url to notifications to allow rendering X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=0f5bea2465006bf6a0871812c056ec737ad61949;p=akkoma Add emoji_url to notifications to allow rendering Ref #5 --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e772de0a..4b3847049 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -## Unreleased +## 2.5.0 - 10/06/2022 ### Changed - Allow users to remove their emails if instance does not need email to register @@ -21,6 +21,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Ability to log slow Ecto queries by configuring `:pleroma, :telemetry, :slow_queries_logging` - Added Phoenix LiveDashboard at `/phoenix/live_dashboard` - Added `/manifest.json` for progressive web apps. +- Readded mastoFE +- Added support for custom emoji reactions +- Added `emoji_url` in notifications to allow for custom emoji rendering ### Fixed - Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex index d421f2ccb..f4043ac80 100644 --- a/lib/pleroma/emoji.ex +++ b/lib/pleroma/emoji.ex @@ -164,4 +164,22 @@ defmodule Pleroma.Emoji do end def maybe_quote(name), do: name + + def emoji_url(%{"type" => "EmojiReact", "content" => emoji, "tag" => []}), do: nil + + def emoji_url(%{"type" => "EmojiReact", "content" => emoji, "tag" => tags}) do + tag = + tags + |> Enum.find(fn tag -> tag["type"] == "Emoji" && tag["name"] == stripped_name(emoji) end) + + if is_nil(tag) do + nil + else + tag + |> Map.get("icon") + |> Map.get("url") + end + end + + def emoji_url(_), do: nil end diff --git a/lib/pleroma/web/mastodon_api/views/notification_view.ex b/lib/pleroma/web/mastodon_api/views/notification_view.ex index 35c636d4e..ff7adeb2b 100644 --- a/lib/pleroma/web/mastodon_api/views/notification_view.ex +++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex @@ -138,7 +138,9 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do end defp put_emoji(response, activity) do - Map.put(response, :emoji, activity.data["content"]) + response + |> Map.put(:emoji, activity.data["content"]) + |> Map.put(:emoji_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 8070c03c9..00e90239e 100644 --- a/test/pleroma/web/mastodon_api/views/notification_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/notification_view_test.exs @@ -188,6 +188,34 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do pleroma: %{is_seen: false, is_muted: false}, type: "pleroma:emoji_reaction", emoji: "☕", + emoji_url: nil, + 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 + + test "EmojiReact notification with custom emoji" do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{status: "#morb"}) + {:ok, _activity} = CommonAPI.react_with_emoji(activity.id, other_user, ":dinosaur:") + + 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: ":dinosaur:", + emoji_url: "http://localhost:4001/emoji/dino walking.gif", 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)