forked from AkkomaGang/akkoma
Activity: Remove notifications-related functions.
This commit is contained in:
parent
127ccc4e1c
commit
37542a9dfa
4 changed files with 26 additions and 64 deletions
|
@ -24,16 +24,6 @@ defmodule Pleroma.Activity do
|
||||||
|
|
||||||
@primary_key {:id, FlakeId.Ecto.CompatType, autogenerate: true}
|
@primary_key {:id, FlakeId.Ecto.CompatType, autogenerate: true}
|
||||||
|
|
||||||
# https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19
|
|
||||||
@mastodon_notification_types %{
|
|
||||||
"Create" => "mention",
|
|
||||||
"Follow" => ["follow", "follow_request"],
|
|
||||||
"Announce" => "reblog",
|
|
||||||
"Like" => "favourite",
|
|
||||||
"Move" => "move",
|
|
||||||
"EmojiReact" => "pleroma:emoji_reaction"
|
|
||||||
}
|
|
||||||
|
|
||||||
schema "activities" do
|
schema "activities" do
|
||||||
field(:data, :map)
|
field(:data, :map)
|
||||||
field(:local, :boolean, default: true)
|
field(:local, :boolean, default: true)
|
||||||
|
@ -300,32 +290,6 @@ def follow_accepted?(
|
||||||
|
|
||||||
def follow_accepted?(_), do: false
|
def follow_accepted?(_), do: false
|
||||||
|
|
||||||
@spec mastodon_notification_type(Activity.t()) :: String.t() | nil
|
|
||||||
|
|
||||||
for {ap_type, type} <- @mastodon_notification_types, not is_list(type) do
|
|
||||||
def mastodon_notification_type(%Activity{data: %{"type" => unquote(ap_type)}}),
|
|
||||||
do: unquote(type)
|
|
||||||
end
|
|
||||||
|
|
||||||
def mastodon_notification_type(%Activity{data: %{"type" => "Follow"}} = activity) do
|
|
||||||
if follow_accepted?(activity) do
|
|
||||||
"follow"
|
|
||||||
else
|
|
||||||
"follow_request"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def mastodon_notification_type(%Activity{}), do: nil
|
|
||||||
|
|
||||||
@spec from_mastodon_notification_type(String.t()) :: String.t() | nil
|
|
||||||
@doc "Converts Mastodon notification type to AR activity type"
|
|
||||||
def from_mastodon_notification_type(type) do
|
|
||||||
with {k, _v} <-
|
|
||||||
Enum.find(@mastodon_notification_types, fn {_k, v} -> type in List.wrap(v) end) do
|
|
||||||
k
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def all_by_actor_and_id(actor, status_ids \\ [])
|
def all_by_actor_and_id(actor, status_ids \\ [])
|
||||||
def all_by_actor_and_id(_actor, []), do: []
|
def all_by_actor_and_id(_actor, []), do: []
|
||||||
|
|
||||||
|
|
|
@ -16,18 +16,17 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
|
||||||
alias Pleroma.Web.MastodonAPI.StatusView
|
alias Pleroma.Web.MastodonAPI.StatusView
|
||||||
alias Pleroma.Web.PleromaAPI.ChatMessageView
|
alias Pleroma.Web.PleromaAPI.ChatMessageView
|
||||||
|
|
||||||
|
@parent_types ~w{Like Announce EmojiReact}
|
||||||
|
|
||||||
def render("index.json", %{notifications: notifications, for: reading_user} = opts) do
|
def render("index.json", %{notifications: notifications, for: reading_user} = opts) do
|
||||||
activities = Enum.map(notifications, & &1.activity)
|
activities = Enum.map(notifications, & &1.activity)
|
||||||
|
|
||||||
parent_activities =
|
parent_activities =
|
||||||
activities
|
activities
|
||||||
|> Enum.filter(
|
|> Enum.filter(fn
|
||||||
&(Activity.mastodon_notification_type(&1) in [
|
%{data: %{"type" => type}} ->
|
||||||
"favourite",
|
type in @parent_types
|
||||||
"reblog",
|
end)
|
||||||
"pleroma:emoji_reaction"
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|> Enum.map(& &1.data["object"])
|
|> Enum.map(& &1.data["object"])
|
||||||
|> Activity.create_by_object_ap_id()
|
|> Activity.create_by_object_ap_id()
|
||||||
|> Activity.with_preloaded_object(:left)
|
|> Activity.with_preloaded_object(:left)
|
||||||
|
@ -44,7 +43,7 @@ def render("index.json", %{notifications: notifications, for: reading_user} = op
|
||||||
true ->
|
true ->
|
||||||
move_activities_targets =
|
move_activities_targets =
|
||||||
activities
|
activities
|
||||||
|> Enum.filter(&(Activity.mastodon_notification_type(&1) == "move"))
|
|> Enum.filter(&(&1.data["type"] == "Move"))
|
||||||
|> Enum.map(&User.get_cached_by_ap_id(&1.data["target"]))
|
|> Enum.map(&User.get_cached_by_ap_id(&1.data["target"]))
|
||||||
|
|
||||||
actors =
|
actors =
|
||||||
|
|
|
@ -16,8 +16,6 @@ defmodule Pleroma.Web.Push.Impl do
|
||||||
require Logger
|
require Logger
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
defdelegate mastodon_notification_type(activity), to: Activity
|
|
||||||
|
|
||||||
@types ["Create", "Follow", "Announce", "Like", "Move"]
|
@types ["Create", "Follow", "Announce", "Like", "Move"]
|
||||||
|
|
||||||
@doc "Performs sending notifications for user subscriptions"
|
@doc "Performs sending notifications for user subscriptions"
|
||||||
|
@ -31,7 +29,7 @@ def perform(
|
||||||
when activity_type in @types do
|
when activity_type in @types do
|
||||||
actor = User.get_cached_by_ap_id(notification.activity.data["actor"])
|
actor = User.get_cached_by_ap_id(notification.activity.data["actor"])
|
||||||
|
|
||||||
mastodon_type = mastodon_notification_type(notification.activity)
|
mastodon_type = notification.type
|
||||||
gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key)
|
gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key)
|
||||||
avatar_url = User.avatar_url(actor)
|
avatar_url = User.avatar_url(actor)
|
||||||
object = Object.normalize(activity)
|
object = Object.normalize(activity)
|
||||||
|
@ -116,7 +114,7 @@ def build_content(
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_content(notification, actor, object, mastodon_type) do
|
def build_content(notification, actor, object, mastodon_type) do
|
||||||
mastodon_type = mastodon_type || mastodon_notification_type(notification.activity)
|
mastodon_type = mastodon_type || notification.type
|
||||||
|
|
||||||
%{
|
%{
|
||||||
title: format_title(notification, mastodon_type),
|
title: format_title(notification, mastodon_type),
|
||||||
|
@ -151,7 +149,7 @@ def format_body(
|
||||||
mastodon_type
|
mastodon_type
|
||||||
)
|
)
|
||||||
when type in ["Follow", "Like"] do
|
when type in ["Follow", "Like"] do
|
||||||
mastodon_type = mastodon_type || mastodon_notification_type(notification.activity)
|
mastodon_type = mastodon_type || notification.type
|
||||||
|
|
||||||
case mastodon_type do
|
case mastodon_type do
|
||||||
"follow" -> "@#{actor.nickname} has followed you"
|
"follow" -> "@#{actor.nickname} has followed you"
|
||||||
|
@ -166,10 +164,8 @@ def format_title(%{activity: %{data: %{"directMessage" => true}}}, _mastodon_typ
|
||||||
"New Direct Message"
|
"New Direct Message"
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_title(%{activity: activity}, mastodon_type) do
|
def format_title(%{type: type}, mastodon_type) do
|
||||||
mastodon_type = mastodon_type || mastodon_notification_type(activity)
|
case mastodon_type || type do
|
||||||
|
|
||||||
case mastodon_type do
|
|
||||||
"mention" -> "New Mention"
|
"mention" -> "New Mention"
|
||||||
"follow" -> "New Follower"
|
"follow" -> "New Follower"
|
||||||
"follow_request" -> "New Follow Request"
|
"follow_request" -> "New Follow Request"
|
||||||
|
|
|
@ -60,7 +60,8 @@ test "performs sending notifications" do
|
||||||
notif =
|
notif =
|
||||||
insert(:notification,
|
insert(:notification,
|
||||||
user: user,
|
user: user,
|
||||||
activity: activity
|
activity: activity,
|
||||||
|
type: "mention"
|
||||||
)
|
)
|
||||||
|
|
||||||
assert Impl.perform(notif) == {:ok, [:ok, :ok]}
|
assert Impl.perform(notif) == {:ok, [:ok, :ok]}
|
||||||
|
@ -126,7 +127,7 @@ test "renders title and body for create activity" do
|
||||||
) ==
|
) ==
|
||||||
"@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
|
"@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
|
||||||
|
|
||||||
assert Impl.format_title(%{activity: activity}) ==
|
assert Impl.format_title(%{activity: activity, type: "mention"}) ==
|
||||||
"New Mention"
|
"New Mention"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -136,9 +137,10 @@ test "renders title and body for follow activity" do
|
||||||
{:ok, _, _, activity} = CommonAPI.follow(user, other_user)
|
{:ok, _, _, activity} = CommonAPI.follow(user, other_user)
|
||||||
object = Object.normalize(activity, false)
|
object = Object.normalize(activity, false)
|
||||||
|
|
||||||
assert Impl.format_body(%{activity: activity}, user, object) == "@Bob has followed you"
|
assert Impl.format_body(%{activity: activity, type: "follow"}, user, object) ==
|
||||||
|
"@Bob has followed you"
|
||||||
|
|
||||||
assert Impl.format_title(%{activity: activity}) ==
|
assert Impl.format_title(%{activity: activity, type: "follow"}) ==
|
||||||
"New Follower"
|
"New Follower"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -157,7 +159,7 @@ test "renders title and body for announce activity" do
|
||||||
assert Impl.format_body(%{activity: announce_activity}, user, object) ==
|
assert Impl.format_body(%{activity: announce_activity}, user, object) ==
|
||||||
"@#{user.nickname} repeated: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
|
"@#{user.nickname} repeated: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
|
||||||
|
|
||||||
assert Impl.format_title(%{activity: announce_activity}) ==
|
assert Impl.format_title(%{activity: announce_activity, type: "reblog"}) ==
|
||||||
"New Repeat"
|
"New Repeat"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -173,9 +175,10 @@ test "renders title and body for like activity" do
|
||||||
{:ok, activity} = CommonAPI.favorite(user, activity.id)
|
{:ok, activity} = CommonAPI.favorite(user, activity.id)
|
||||||
object = Object.normalize(activity)
|
object = Object.normalize(activity)
|
||||||
|
|
||||||
assert Impl.format_body(%{activity: activity}, user, object) == "@Bob has favorited your post"
|
assert Impl.format_body(%{activity: activity, type: "favourite"}, user, object) ==
|
||||||
|
"@Bob has favorited your post"
|
||||||
|
|
||||||
assert Impl.format_title(%{activity: activity}) ==
|
assert Impl.format_title(%{activity: activity, type: "favourite"}) ==
|
||||||
"New Favorite"
|
"New Favorite"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -218,7 +221,7 @@ test "hides details for notifications when privacy option enabled" do
|
||||||
status: "<Lorem ipsum dolor sit amet."
|
status: "<Lorem ipsum dolor sit amet."
|
||||||
})
|
})
|
||||||
|
|
||||||
notif = insert(:notification, user: user2, activity: activity)
|
notif = insert(:notification, user: user2, activity: activity, type: "mention")
|
||||||
|
|
||||||
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
|
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
|
||||||
object = Object.normalize(activity)
|
object = Object.normalize(activity)
|
||||||
|
@ -229,7 +232,7 @@ test "hides details for notifications when privacy option enabled" do
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.favorite(user, activity.id)
|
{:ok, activity} = CommonAPI.favorite(user, activity.id)
|
||||||
|
|
||||||
notif = insert(:notification, user: user2, activity: activity)
|
notif = insert(:notification, user: user2, activity: activity, type: "favourite")
|
||||||
|
|
||||||
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
|
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
|
||||||
object = Object.normalize(activity)
|
object = Object.normalize(activity)
|
||||||
|
@ -268,7 +271,7 @@ test "returns regular content for notifications with privacy option disabled" do
|
||||||
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
|
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
|
||||||
})
|
})
|
||||||
|
|
||||||
notif = insert(:notification, user: user2, activity: activity)
|
notif = insert(:notification, user: user2, activity: activity, type: "mention")
|
||||||
|
|
||||||
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
|
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
|
||||||
object = Object.normalize(activity)
|
object = Object.normalize(activity)
|
||||||
|
@ -281,7 +284,7 @@ test "returns regular content for notifications with privacy option disabled" do
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.favorite(user, activity.id)
|
{:ok, activity} = CommonAPI.favorite(user, activity.id)
|
||||||
|
|
||||||
notif = insert(:notification, user: user2, activity: activity)
|
notif = insert(:notification, user: user2, activity: activity, type: "favourite")
|
||||||
|
|
||||||
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
|
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
|
||||||
object = Object.normalize(activity)
|
object = Object.normalize(activity)
|
||||||
|
|
Loading…
Reference in a new issue