From 03b620ecece41963946db23163a2e3b227463b3b Mon Sep 17 00:00:00 2001 From: Martin Barker Date: Fri, 3 Feb 2023 18:59:07 +0000 Subject: [PATCH] Started work on #1 --- .../Core/NotifyManager.cs | 48 +++++++++++++++++++ .../Core/TwitchFetcher.cs | 9 +++- .../JsonStructure/SteamersToNotify.cs | 13 +++++ .../JsonStructure/Store.cs | 3 ++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 TwitchDesktopNotifications/Core/NotifyManager.cs create mode 100644 TwitchDesktopNotifications/JsonStructure/SteamersToNotify.cs diff --git a/TwitchDesktopNotifications/Core/NotifyManager.cs b/TwitchDesktopNotifications/Core/NotifyManager.cs new file mode 100644 index 0000000..2b865d1 --- /dev/null +++ b/TwitchDesktopNotifications/Core/NotifyManager.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TwitchDesktopNotifications.JsonStructure.Helix; + +namespace TwitchDesktopNotifications.Core +{ + internal class NotifyManager + { + + public Boolean shouldNotify(String streamerName) + { + return notifyAll || !DataStore.GetInstance().Store.SteamersToNotify.Streamers.Contains(streamerName); + } + + public void AddStreamerToNotifyList(String streamerName) + { + DataStore.GetInstance().Store.SteamersToNotify.Streamers.Add(streamerName); + DataStore.GetInstance().Save(); + } + + public void RemoveStreamerToNotifyList(String streamerName) + { + DataStore.GetInstance().Store.SteamersToNotify.Streamers.Remove(streamerName); + DataStore.GetInstance().Save(); + } + + public void ClearListOfEnabled() + { + DataStore.GetInstance().Store.SteamersToNotify.Streamers = new List(); + DataStore.GetInstance().Save(); + } + + public bool notifyAll + { + get + { + return DataStore.GetInstance().Store.SteamersToNotify.notifyAll; + } + set { + DataStore.GetInstance().Store.SteamersToNotify.notifyAll = value; + DataStore.GetInstance().Save(); + } + } + } +} diff --git a/TwitchDesktopNotifications/Core/TwitchFetcher.cs b/TwitchDesktopNotifications/Core/TwitchFetcher.cs index 4a3fd94..976ee1d 100644 --- a/TwitchDesktopNotifications/Core/TwitchFetcher.cs +++ b/TwitchDesktopNotifications/Core/TwitchFetcher.cs @@ -126,7 +126,14 @@ namespace TwitchDesktopNotifications.Core currentlyLive = following.Data; }catch(System.Exception ex) { - MessageBox.Show("Twitch Connection not authenticated you need to Reconnect it.", "Twitch Notify"); + if (!ex.Message.Contains("Notification")) + { + MessageBox.Show("Twitch Connection not authenticated you need to Reconnect it.", "Twitch Notify"); + } + else + { + MessageBox.Show("Unable to use Windows Notifications.", "Twitch Notify"); + } } } diff --git a/TwitchDesktopNotifications/JsonStructure/SteamersToNotify.cs b/TwitchDesktopNotifications/JsonStructure/SteamersToNotify.cs new file mode 100644 index 0000000..fca9363 --- /dev/null +++ b/TwitchDesktopNotifications/JsonStructure/SteamersToNotify.cs @@ -0,0 +1,13 @@ +using System.Text.Json.Serialization; + +namespace TwitchDesktopNotifications.JsonStructure +{ + internal class SteamersToNotify + { + [JsonPropertyName("notifyAll")] + public Boolean notifyAll = true; + + [JsonPropertyName("notify")] + public List Streamers { get; set; } = new List(); + } +} diff --git a/TwitchDesktopNotifications/JsonStructure/Store.cs b/TwitchDesktopNotifications/JsonStructure/Store.cs index 2d59f42..389c574 100644 --- a/TwitchDesktopNotifications/JsonStructure/Store.cs +++ b/TwitchDesktopNotifications/JsonStructure/Store.cs @@ -17,5 +17,8 @@ namespace TwitchDesktopNotifications.JsonStructure [JsonPropertyName("user_data")] public UserData UserData { get; set; } + + [JsonPropertyName("notifications_for")] + public SteamersToNotify SteamersToNotify { get; set; }; } }