"Follow" => "follow",
"Announce" => "reblog",
"Like" => "favourite",
- "Move" => "move"
+ "Move" => "move",
+ "EmojiReaction" => "pleroma:emoji_reaction"
}
@mastodon_to_ap_notification_types for {k, v} <- @mastodon_notification_types,
end
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 =
activity
|> get_notified_from_activity()
def get_notified_from_activity(activity, local_only \\ true)
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_mentioned_recipients(activity)
}
case mastodon_type do
- "mention" -> put_status(response, activity, user)
- "favourite" -> put_status(response, parent_activity, user)
- "reblog" -> put_status(response, parent_activity, user)
- "move" -> put_target(response, activity, user)
- "follow" -> response
- _ -> nil
+ "mention" ->
+ put_status(response, activity, user)
+
+ "favourite" ->
+ put_status(response, parent_activity, user)
+
+ "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
else
_ -> nil
end
end
+ defp put_emoji(response, activity) do
+ response
+ |> Map.put(:emoji, activity.data["content"])
+ end
+
defp put_status(response, activity, user) do
Map.put(response, :status, StatusView.render("show.json", %{activity: activity, for: user}))
end
alias Pleroma.Web.Streamer
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
user = insert(:user)
other_user = insert(:user)
assert [expected] ==
NotificationView.render("index.json", %{notifications: [notification], for: follower})
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