forked from AkkomaGang/akkoma
Merge branch 'emoji-notifications' into 'develop'
Emoji notifications See merge request pleroma/pleroma!2130
This commit is contained in:
commit
dddebee047
7 changed files with 77 additions and 9 deletions
|
@ -96,6 +96,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Mastodon API: Add support for `account_id` param to filter notifications by the account
|
- Mastodon API: Add support for `account_id` param to filter notifications by the account
|
||||||
- Mastodon API: Add `emoji_reactions` property to Statuses
|
- Mastodon API: Add `emoji_reactions` property to Statuses
|
||||||
- Mastodon API: Change emoji reaction reply format
|
- Mastodon API: Change emoji reaction reply format
|
||||||
|
- Notifications: Added `pleroma:emoji_reaction` notification type
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -101,6 +101,14 @@ The `type` value is `move`. Has an additional field:
|
||||||
|
|
||||||
- `target`: new account
|
- `target`: new account
|
||||||
|
|
||||||
|
### EmojiReaction Notification
|
||||||
|
|
||||||
|
The `type` value is `pleroma:emoji_reaction`. Has these fields:
|
||||||
|
|
||||||
|
- `emoji`: The used emoji
|
||||||
|
- `account`: The account of the user who reacted
|
||||||
|
- `status`: The status that was reacted on
|
||||||
|
|
||||||
## GET `/api/v1/notifications`
|
## GET `/api/v1/notifications`
|
||||||
|
|
||||||
Accepts additional parameters:
|
Accepts additional parameters:
|
||||||
|
|
|
@ -30,7 +30,8 @@ defmodule Pleroma.Activity do
|
||||||
"Follow" => "follow",
|
"Follow" => "follow",
|
||||||
"Announce" => "reblog",
|
"Announce" => "reblog",
|
||||||
"Like" => "favourite",
|
"Like" => "favourite",
|
||||||
"Move" => "move"
|
"Move" => "move",
|
||||||
|
"EmojiReaction" => "pleroma:emoji_reaction"
|
||||||
}
|
}
|
||||||
|
|
||||||
@mastodon_to_ap_notification_types for {k, v} <- @mastodon_notification_types,
|
@mastodon_to_ap_notification_types for {k, v} <- @mastodon_notification_types,
|
||||||
|
|
|
@ -294,7 +294,7 @@ def create_notifications(%Activity{data: %{"to" => _, "type" => "Create"}} = act
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_notifications(%Activity{data: %{"type" => type}} = activity)
|
def create_notifications(%Activity{data: %{"type" => type}} = activity)
|
||||||
when type in ["Like", "Announce", "Follow", "Move"] do
|
when type in ["Like", "Announce", "Follow", "Move", "EmojiReaction"] do
|
||||||
notifications =
|
notifications =
|
||||||
activity
|
activity
|
||||||
|> get_notified_from_activity()
|
|> get_notified_from_activity()
|
||||||
|
@ -322,7 +322,7 @@ def create_notification(%Activity{} = activity, %User{} = user) do
|
||||||
def get_notified_from_activity(activity, local_only \\ true)
|
def get_notified_from_activity(activity, local_only \\ true)
|
||||||
|
|
||||||
def get_notified_from_activity(%Activity{data: %{"type" => type}} = activity, local_only)
|
def get_notified_from_activity(%Activity{data: %{"type" => type}} = activity, local_only)
|
||||||
when type in ["Create", "Like", "Announce", "Follow", "Move"] do
|
when type in ["Create", "Like", "Announce", "Follow", "Move", "EmojiReaction"] do
|
||||||
[]
|
[]
|
||||||
|> Utils.maybe_notify_to_recipients(activity)
|
|> Utils.maybe_notify_to_recipients(activity)
|
||||||
|> Utils.maybe_notify_mentioned_recipients(activity)
|
|> Utils.maybe_notify_mentioned_recipients(activity)
|
||||||
|
|
|
@ -37,18 +37,37 @@ def render("show.json", %{
|
||||||
}
|
}
|
||||||
|
|
||||||
case mastodon_type do
|
case mastodon_type do
|
||||||
"mention" -> put_status(response, activity, user)
|
"mention" ->
|
||||||
"favourite" -> put_status(response, parent_activity, user)
|
put_status(response, activity, user)
|
||||||
"reblog" -> put_status(response, parent_activity, user)
|
|
||||||
"move" -> put_target(response, activity, user)
|
"favourite" ->
|
||||||
"follow" -> response
|
put_status(response, parent_activity, user)
|
||||||
_ -> nil
|
|
||||||
|
"reblog" ->
|
||||||
|
put_status(response, parent_activity, user)
|
||||||
|
|
||||||
|
"move" ->
|
||||||
|
put_target(response, activity, user)
|
||||||
|
|
||||||
|
"follow" ->
|
||||||
|
response
|
||||||
|
|
||||||
|
"pleroma:emoji_reaction" ->
|
||||||
|
put_status(response, parent_activity, user) |> put_emoji(activity)
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
_ -> nil
|
_ -> nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp put_emoji(response, activity) do
|
||||||
|
response
|
||||||
|
|> Map.put(:emoji, activity.data["content"])
|
||||||
|
end
|
||||||
|
|
||||||
defp put_status(response, activity, user) do
|
defp put_status(response, activity, user) do
|
||||||
Map.put(response, :status, StatusView.render("show.json", %{activity: activity, for: user}))
|
Map.put(response, :status, StatusView.render("show.json", %{activity: activity, for: user}))
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,18 @@ defmodule Pleroma.NotificationTest do
|
||||||
alias Pleroma.Web.Streamer
|
alias Pleroma.Web.Streamer
|
||||||
|
|
||||||
describe "create_notifications" do
|
describe "create_notifications" do
|
||||||
|
test "creates a notification for an emoji reaction" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "yeah"})
|
||||||
|
{:ok, activity, _object} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
|
||||||
|
|
||||||
|
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||||
|
|
||||||
|
assert notification.user_id == user.id
|
||||||
|
end
|
||||||
|
|
||||||
test "notifies someone when they are directly addressed" do
|
test "notifies someone when they are directly addressed" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
|
@ -134,4 +134,31 @@ test "Move notification" do
|
||||||
assert [expected] ==
|
assert [expected] ==
|
||||||
NotificationView.render("index.json", %{notifications: [notification], for: follower})
|
NotificationView.render("index.json", %{notifications: [notification], for: follower})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "EmojiReaction notification" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
|
||||||
|
{:ok, _activity, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
|
||||||
|
|
||||||
|
activity = Repo.get(Activity, activity.id)
|
||||||
|
|
||||||
|
[notification] = Notification.for_user(user)
|
||||||
|
|
||||||
|
assert notification
|
||||||
|
|
||||||
|
expected = %{
|
||||||
|
id: to_string(notification.id),
|
||||||
|
pleroma: %{is_seen: false},
|
||||||
|
type: "pleroma:emoji_reaction",
|
||||||
|
emoji: "☕",
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert expected ==
|
||||||
|
NotificationView.render("show.json", %{notification: notification, for: user})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue