forked from AkkomaGang/akkoma
Add check to prevent multiple follow notifications from the same user
This commit is contained in:
parent
8d047c7a72
commit
042852ecf3
2 changed files with 43 additions and 1 deletions
|
@ -109,7 +109,12 @@ def create_notifications(_), do: {:ok, []}
|
|||
# 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)
|
||||
|
|
|
@ -46,6 +46,43 @@ test "it doesn't create a notification for user if he is the activity author" do
|
|||
|
||||
assert nil == Notification.create_notification(activity, author)
|
||||
end
|
||||
|
||||
test "it doesn't create a notification for follow-unfollow-follow chains" do
|
||||
user = insert(:user)
|
||||
followed_user = insert(:user)
|
||||
{:ok, _, _, activity} = TwitterAPI.follow(user, %{"user_id" => followed_user.id})
|
||||
Notification.create_notification(activity, followed_user)
|
||||
TwitterAPI.unfollow(user, %{"user_id" => followed_user.id})
|
||||
{:ok, _, _, activity_dupe} = TwitterAPI.follow(user, %{"user_id" => followed_user.id})
|
||||
assert nil == Notification.create_notification(activity_dupe, followed_user)
|
||||
end
|
||||
|
||||
test "it doesn't create a notification for like-unlike-like chains" do
|
||||
user = insert(:user)
|
||||
liked_user = insert(:user)
|
||||
{:ok, status} = TwitterAPI.create_status(liked_user, %{"status" => "Yui is best yuru"})
|
||||
{:ok, fav_status} = TwitterAPI.fav(user, status.id)
|
||||
Notification.create_notification(fav_status, liked_user)
|
||||
TwitterAPI.unfav(user, status.id)
|
||||
{:ok, dupe} = TwitterAPI.fav(user, status.id)
|
||||
assert nil == Notification.create_notification(dupe, liked_user)
|
||||
end
|
||||
|
||||
test "it doesn't create a notification for repeat-unrepeat-repeat chains" do
|
||||
user = insert(:user)
|
||||
retweeted_user = insert(:user)
|
||||
|
||||
{:ok, status} =
|
||||
TwitterAPI.create_status(retweeted_user, %{
|
||||
"status" => "Send dupe notifications to the shadow realm"
|
||||
})
|
||||
|
||||
{:ok, retweeted_activity} = TwitterAPI.repeat(user, status.id)
|
||||
Notification.create_notification(retweeted_activity, retweeted_user)
|
||||
TwitterAPI.unrepeat(user, status.id)
|
||||
{:ok, dupe} = TwitterAPI.repeat(user, status.id)
|
||||
assert nil == Notification.create_notification(dupe, retweeted_user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "get notification" do
|
||||
|
|
Loading…
Reference in a new issue