X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fnotification.ex;h=c7d01f63b83517c36b15779ec9a9772524d5b6d4;hb=aa37313416c155a37b40e09617eb2fe524edbf0b;hp=457cba9350244e748ffcb2454affbbc47631dab2;hpb=2bbec33c7112ede3f93a7d35e9d5f3ac5a31ce05;p=akkoma diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 457cba935..c7d01f63b 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Notification do use Ecto.Schema alias Pleroma.{User, Activity, Notification, Repo, Object} @@ -75,16 +79,11 @@ defmodule Pleroma.Notification do end end - def clear(%User{} = user) do + def clear(user) do from(n in Notification, where: n.user_id == ^user.id) |> Repo.delete_all() end - def clear(%Activity{} = activity) do - from(n in Notification, where: n.activity_id == ^activity.id) - |> Repo.delete_all() - end - def dismiss(%{id: user_id} = _user, id) do notification = Repo.get(Notification, id) @@ -110,7 +109,12 @@ defmodule Pleroma.Notification do # TODO move to sql, too. def create_notification(%Activity{} = activity, %User{} = user) do unless User.blocks?(user, %{ap_id: activity.data["actor"]}) or - user.ap_id == activity.data["actor"] do + user.ap_id == activity.data["actor"] or + (activity.data["type"] == "Follow" and + Enum.any?(Notification.for_user(user), fn notif -> + notif.activity.data["type"] == "Follow" and + notif.activity.data["actor"] == activity.data["actor"] + end)) do notification = %Notification{user_id: user.id, activity: activity} {:ok, notification} = Repo.insert(notification) Pleroma.Web.Streamer.stream("user", notification)