From 8051107d32e6e11d1f1982a18e3667904e3b5312 Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 1 May 2024 08:56:15 -0700 Subject: [PATCH] Stopped notifications from being sent if the source doesn't download (#218) --- lib/pinchflat/notifications/source_notifications.ex | 6 +++++- .../notifications/source_notifications_test.exs | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/pinchflat/notifications/source_notifications.ex b/lib/pinchflat/notifications/source_notifications.ex index 12058588..88cc1894 100644 --- a/lib/pinchflat/notifications/source_notifications.ex +++ b/lib/pinchflat/notifications/source_notifications.ex @@ -53,7 +53,11 @@ defmodule Pinchflat.Notifications.SourceNotifications do end defp relevant_media_item_count(source) do - pending_media_item_count(source) + downloaded_media_item_count(source) + if source.download_media do + pending_media_item_count(source) + downloaded_media_item_count(source) + else + 0 + end end defp pending_media_item_count(source) do diff --git a/test/pinchflat/notifications/source_notifications_test.exs b/test/pinchflat/notifications/source_notifications_test.exs index 0bf897e0..79757849 100644 --- a/test/pinchflat/notifications/source_notifications_test.exs +++ b/test/pinchflat/notifications/source_notifications_test.exs @@ -60,6 +60,17 @@ defmodule Pinchflat.Notifications.SourceNotificationsTest do end) end + test "does not send a notification if the source is set to not download media" do + source = source_fixture(%{download_media: false}) + + expect(AppriseRunnerMock, :run, 0, fn _, _ -> {:ok, ""} end) + + SourceNotifications.wrap_new_media_notification(@apprise_servers, source, fn -> + media_item_fixture(%{source_id: source.id, media_filepath: nil}) + media_item_fixture(%{source_id: source.id, media_filepath: "file.mp4"}) + end) + end + test "returns the value of the function" do source = source_fixture() expect(AppriseRunnerMock, :run, 0, fn _, _ -> {:ok, ""} end)