forked from AkkomaGang/akkoma
Code style fixes
This commit is contained in:
parent
76c3e290fc
commit
56b60798c2
2 changed files with 33 additions and 40 deletions
|
@ -56,7 +56,8 @@ defmodule Pleroma.SubscriptionNotification do
|
||||||
if opts[:with_muted] do
|
if opts[:with_muted] do
|
||||||
query
|
query
|
||||||
else
|
else
|
||||||
where(query, [n, a], a.actor not in ^user.info.muted_notifications)
|
query
|
||||||
|
|> where([n, a], a.actor not in ^user.info.muted_notifications)
|
||||||
|> where([n, a], a.actor not in ^user.info.blocks)
|
|> where([n, a], a.actor not in ^user.info.blocks)
|
||||||
|> where(
|
|> where(
|
||||||
[n, a],
|
[n, a],
|
||||||
|
@ -88,9 +89,9 @@ defmodule Pleroma.SubscriptionNotification do
|
||||||
"""
|
"""
|
||||||
@spec for_user_since(Pleroma.User.t(), NaiveDateTime.t()) :: [t()]
|
@spec for_user_since(Pleroma.User.t(), NaiveDateTime.t()) :: [t()]
|
||||||
def for_user_since(user, date) do
|
def for_user_since(user, date) do
|
||||||
from(n in for_user_query(user),
|
user
|
||||||
where: n.updated_at > ^date
|
|> for_user_query()
|
||||||
)
|
|> where([n], n.updated_at > ^date)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -112,10 +113,8 @@ defmodule Pleroma.SubscriptionNotification do
|
||||||
preload: [activity: activity]
|
preload: [activity: activity]
|
||||||
)
|
)
|
||||||
|
|
||||||
notification = Repo.one(query)
|
case Repo.one(query) do
|
||||||
|
%{user_id: ^user_id} = notification ->
|
||||||
case notification do
|
|
||||||
%{user_id: ^user_id} ->
|
|
||||||
{:ok, notification}
|
{:ok, notification}
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -137,10 +136,8 @@ defmodule Pleroma.SubscriptionNotification do
|
||||||
end
|
end
|
||||||
|
|
||||||
def dismiss(%{id: user_id} = _user, id) do
|
def dismiss(%{id: user_id} = _user, id) do
|
||||||
notification = Repo.get(SubscriptionNotification, id)
|
case Repo.get(SubscriptionNotification, id) do
|
||||||
|
%{user_id: ^user_id} = notification ->
|
||||||
case notification do
|
|
||||||
%{user_id: ^user_id} ->
|
|
||||||
Repo.delete(notification)
|
Repo.delete(notification)
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -149,21 +146,24 @@ defmodule Pleroma.SubscriptionNotification do
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_notifications(%Activity{data: %{"to" => _, "type" => "Create"}} = activity) do
|
def create_notifications(%Activity{data: %{"to" => _, "type" => "Create"}} = activity) do
|
||||||
object = Object.normalize(activity)
|
case Object.normalize(activity) do
|
||||||
|
%{data: %{"type" => "Answer"}} ->
|
||||||
|
{:ok, []}
|
||||||
|
|
||||||
unless object && object.data["type"] == "Answer" do
|
_ ->
|
||||||
users = get_notified_from_activity(activity)
|
users = get_notified_from_activity(activity)
|
||||||
notifications = Enum.map(users, fn user -> create_notification(activity, user) end)
|
notifications = Enum.map(users, fn user -> create_notification(activity, user) end)
|
||||||
{:ok, notifications}
|
{:ok, notifications}
|
||||||
else
|
|
||||||
{:ok, []}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_notifications(%Activity{data: %{"to" => _, "type" => type}} = activity)
|
def create_notifications(%Activity{data: %{"to" => _, "type" => type}} = activity)
|
||||||
when type in ["Like", "Announce", "Follow"] do
|
when type in ["Like", "Announce", "Follow"] do
|
||||||
users = get_notified_from_activity(activity)
|
notifications =
|
||||||
notifications = Enum.map(users, fn user -> create_notification(activity, user) end)
|
activity
|
||||||
|
|> get_notified_from_activity()
|
||||||
|
|> Enum.map(&create_notification(activity, &1))
|
||||||
|
|
||||||
{:ok, notifications}
|
{:ok, notifications}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -188,12 +188,10 @@ defmodule Pleroma.SubscriptionNotification do
|
||||||
local_only
|
local_only
|
||||||
)
|
)
|
||||||
when type in ["Create", "Like", "Announce", "Follow"] do
|
when type in ["Create", "Like", "Announce", "Follow"] do
|
||||||
recipients =
|
[]
|
||||||
[]
|
|> Utils.maybe_notify_subscribers(activity)
|
||||||
|> Utils.maybe_notify_subscribers(activity)
|
|> Enum.uniq()
|
||||||
|> Enum.uniq()
|
|> User.get_users_from_set(local_only)
|
||||||
|
|
||||||
User.get_users_from_set(recipients, local_only)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_notified_from_activity(_, _local_only), do: []
|
def get_notified_from_activity(_, _local_only), do: []
|
||||||
|
@ -218,12 +216,12 @@ defmodule Pleroma.SubscriptionNotification do
|
||||||
|
|
||||||
def skip?(
|
def skip?(
|
||||||
:followers,
|
:followers,
|
||||||
activity,
|
%{data: %{"actor" => actor}},
|
||||||
%{info: %{notification_settings: %{"followers" => false}}} = user
|
%{info: %{notification_settings: %{"followers" => false}}} = user
|
||||||
) do
|
) do
|
||||||
actor = activity.data["actor"]
|
actor
|
||||||
follower = User.get_cached_by_ap_id(actor)
|
|> User.get_cached_by_ap_id()
|
||||||
User.following?(follower, user)
|
|> User.following?(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def skip?(
|
def skip?(
|
||||||
|
@ -252,14 +250,10 @@ defmodule Pleroma.SubscriptionNotification do
|
||||||
!User.following?(user, followed)
|
!User.following?(user, followed)
|
||||||
end
|
end
|
||||||
|
|
||||||
def skip?(:recently_followed, %{data: %{"type" => "Follow"}} = activity, user) do
|
def skip?(:recently_followed, %{data: %{"type" => "Follow", "actor" => actor}}, user) do
|
||||||
actor = activity.data["actor"]
|
user
|
||||||
|
|> SubscriptionNotification.for_user()
|
||||||
SubscriptionNotification.for_user(user)
|
|> Enum.any?(&match?(%{activity: %{data: %{"type" => "Follow", "actor" => ^actor}}}, &1))
|
||||||
|> Enum.any?(fn
|
|
||||||
%{activity: %{data: %{"type" => "Follow", "actor" => ^actor}}} -> true
|
|
||||||
_ -> false
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def skip?(_, _, _), do: false
|
def skip?(_, _, _), do: false
|
||||||
|
|
|
@ -6,7 +6,6 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionNotificationView do
|
||||||
use Pleroma.Web, :view
|
use Pleroma.Web, :view
|
||||||
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
# alias Pleroma.SubscriptionNotification
|
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.MastodonAPI.AccountView
|
alias Pleroma.Web.MastodonAPI.AccountView
|
||||||
|
|
Loading…
Reference in a new issue