|> cast(attrs, [:seen])
end
- @spec notifications_info_query(User.t()) :: Ecto.Queryable.t()
- def notifications_info_query(user) do
+ @spec unread_count_query(User.t()) :: Ecto.Queryable.t()
+ def unread_count_query(user) do
from(q in Pleroma.Notification,
where: q.user_id == ^user.id,
- select: %{
- unread_count: fragment("SUM( CASE WHEN seen = false THEN 1 ELSE 0 END )"),
- last_read_id:
- type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
- }
+ where: q.seen == false
+ )
+ end
+
+ @spec last_read_query(User.t()) :: Ecto.Queryable.t()
+ def last_read_query(user) do
+ from(q in Pleroma.Notification,
+ where: q.user_id == ^user.id,
+ where: q.seen == true,
+ select: type(q.id, :string),
+ limit: 1,
+ order_by: [desc: :id]
)
end
end
end
- def create_notifications(%Activity{data: %{"to" => _, "type" => type}} = activity)
- when type in ["Like", "Announce", "Follow"] do
+ def create_notifications(%Activity{data: %{"type" => type}} = activity)
+ when type in ["Like", "Announce", "Follow", "Move"] do
notifications =
activity
- |> get_notified_from_activity
+ |> get_notified_from_activity()
|> Enum.map(&create_notification(activity, &1))
{:ok, notifications}
def get_notified_from_activity(activity, local_only \\ true)
- def get_notified_from_activity(
- %Activity{data: %{"to" => _, "type" => type} = _data} = activity,
- local_only
- )
- when type in ["Create", "Like", "Announce", "Follow"] do
- recipients =
- []
- |> Utils.maybe_notify_to_recipients(activity)
- |> Utils.maybe_notify_mentioned_recipients(activity)
- |> Utils.maybe_notify_subscribers(activity)
- |> Enum.uniq()
-
- User.get_users_from_set(recipients, local_only)
+ def get_notified_from_activity(%Activity{data: %{"type" => type}} = activity, local_only)
+ when type in ["Create", "Like", "Announce", "Follow", "Move"] do
+ []
+ |> Utils.maybe_notify_to_recipients(activity)
+ |> Utils.maybe_notify_mentioned_recipients(activity)
+ |> Utils.maybe_notify_subscribers(activity)
+ |> Utils.maybe_notify_followers(activity)
+ |> Enum.uniq()
+ |> User.get_users_from_set(local_only)
end
def get_notified_from_activity(_, _local_only), do: []