# TODO move to sql, too.
def create_notification(%Activity{} = activity, %User{} = user) do
- notification = %Notification{user_id: user.id, activity_id: activity.id}
- {:ok, notification} = Repo.insert(notification)
- notification
+ unless User.blocks?(user, %{ap_id: activity.data["actor"]}) do
+ notification = %Notification{user_id: user.id, activity_id: activity.id}
+ {:ok, notification} = Repo.insert(notification)
+ notification
+ end
end
end
assert other_notification.activity_id == activity.id
end
end
+
+ describe "create_notification" do
+ test "it doesn't create a notification for user if the user blocks the activity author" do
+ activity = insert(:note_activity)
+ author = User.get_by_ap_id(activity.data["actor"])
+ user = insert(:user)
+ {:ok, user} = User.block(user, author)
+
+ assert nil == Notification.create_notification(activity, user)
+ end
+ end
end