diff --git a/ExternalAPIs/TwitchTv/Helix/TwitchTvHelixHelixReadonlyClient.cs b/ExternalAPIs/TwitchTv/Helix/TwitchTvHelixHelixReadonlyClient.cs index 51b7e4a..3c2a61a 100644 --- a/ExternalAPIs/TwitchTv/Helix/TwitchTvHelixHelixReadonlyClient.cs +++ b/ExternalAPIs/TwitchTv/Helix/TwitchTvHelixHelixReadonlyClient.cs @@ -73,8 +73,7 @@ public async Task> GetStreams(GetStreamsQuery getStreamsQuery, Canc taken += take; } } - - if (!streams.Any()) + else { var streamRoot = await ExecuteRequest(request, cancellationToken); streams = streamRoot.Streams; diff --git a/GlobalAssemblyInfo.cs b/GlobalAssemblyInfo.cs index 7b9a007..0856745 100644 --- a/GlobalAssemblyInfo.cs +++ b/GlobalAssemblyInfo.cs @@ -22,5 +22,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.12.7.0")] -[assembly: AssemblyFileVersion("2.12.7.0")] \ No newline at end of file +[assembly: AssemblyVersion("2.12.8.0")] +[assembly: AssemblyFileVersion("2.12.8.0")] \ No newline at end of file diff --git a/Livestream.Monitor/Core/Settings.cs b/Livestream.Monitor/Core/Settings.cs index a5388ee..70034b3 100644 --- a/Livestream.Monitor/Core/Settings.cs +++ b/Livestream.Monitor/Core/Settings.cs @@ -31,7 +31,7 @@ public class Settings : PropertyChangedBase private MetroThemeAccentColour? metroThemeAccentColour; private int minimumEventViewers = DEFAULT_MINIMUM_EVENT_VIEWERS; private string livestreamerFullPath, chatCommandLine, twitchAuthToken; - private bool disableNotifications, passthroughClientId, hideStreamOutputMessageBoxOnLoad, checkForNewVersions, disableRefreshErrorDialogs, twitchAuthTokenInLivestreamerConfig; + private bool disableNotifications, passthroughClientId, hideStreamOutputMessageBoxOnLoad, checkForNewVersions, disableRefreshErrorDialogs; private int settingsVersion; [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] @@ -182,18 +182,6 @@ public bool PassthroughClientId [JsonConverter(typeof(ExcludeNotifyConverter))] public BindableCollection ExcludeFromNotifying { get; } = new BindableCollection(); - [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] - public bool TwitchAuthTokenInLivestreamerConfig - { - get => twitchAuthTokenInLivestreamerConfig; - set - { - if (value == twitchAuthTokenInLivestreamerConfig) return; - twitchAuthTokenInLivestreamerConfig = value; - NotifyOfPropertyChange(() => TwitchAuthTokenInLivestreamerConfig); - } - } - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] public string TwitchAuthToken { @@ -210,8 +198,7 @@ public string TwitchAuthToken /// Flag to indicate if the twitch oauth token has been defined either in livestream monitor settings /// or in the livestreamer/streamlink configuration file /// - public bool TwitchAuthTokenSet => TwitchAuthTokenInLivestreamerConfig || - !string.IsNullOrWhiteSpace(TwitchAuthToken); + public bool TwitchAuthTokenSet => !string.IsNullOrWhiteSpace(TwitchAuthToken); /// /// Name of the livestreamer/streamlink exe without the file extension diff --git a/Livestream.Monitor/Model/ApiClients/TwitchApiClient.cs b/Livestream.Monitor/Model/ApiClients/TwitchApiClient.cs index 333bb32..3e88250 100644 --- a/Livestream.Monitor/Model/ApiClients/TwitchApiClient.cs +++ b/Livestream.Monitor/Model/ApiClients/TwitchApiClient.cs @@ -80,24 +80,8 @@ public string LivestreamerAuthorizationArg public async Task Authorize(IViewAware screen) { - var messageDialogResult = await screen.ShowMessageAsync(title: "Authorization", - message: $"Twitch requires authorization to connect to their services, have you set your oauth token in your {settingsHandler.Settings.LivestreamExeDisplayName} configuration file?", - messageDialogStyle: MessageDialogStyle.AffirmativeAndNegative, - dialogSettings: new MetroDialogSettings() - { - AffirmativeButtonText = "Yes", - NegativeButtonText = "No" - }); - - if (messageDialogResult == MessageDialogResult.Affirmative) - { - settingsHandler.Settings.TwitchAuthTokenInLivestreamerConfig = true; - settingsHandler.SaveSettings(); - return; - } - - messageDialogResult = await screen.ShowMessageAsync(title: "Authorization", - message: "Would you like to authorize this application now?", + var messageDialogResult = await screen.ShowMessageAsync(title: "Twitch Authorization", + message: "Twitch requires authorization for querying livestreams.\nWould you like to authorize this application now?", messageDialogStyle: MessageDialogStyle.AffirmativeAndNegative, dialogSettings: new MetroDialogSettings() { diff --git a/Livestream.Monitor/Model/Monitoring/FakeMonitorStreamsModel.cs b/Livestream.Monitor/Model/Monitoring/FakeMonitorStreamsModel.cs index dc32a2a..37d84e7 100644 --- a/Livestream.Monitor/Model/Monitoring/FakeMonitorStreamsModel.cs +++ b/Livestream.Monitor/Model/Monitoring/FakeMonitorStreamsModel.cs @@ -103,7 +103,7 @@ public Task AddLivestream(ChannelIdentifier channelIdentifier, IViewAware viewAw return Task.CompletedTask; } - public Task ImportFollows(string username, IApiClient apiClient) + public Task ImportFollows(string username, IApiClient apiClient, IViewAware viewAware) { return Task.CompletedTask; } diff --git a/Livestream.Monitor/Model/Monitoring/IMonitorStreamsModel.cs b/Livestream.Monitor/Model/Monitoring/IMonitorStreamsModel.cs index 4fa9503..51f6b87 100644 --- a/Livestream.Monitor/Model/Monitoring/IMonitorStreamsModel.cs +++ b/Livestream.Monitor/Model/Monitoring/IMonitorStreamsModel.cs @@ -31,7 +31,7 @@ public interface IMonitorStreamsModel : INotifyPropertyChangedEx Task RemoveLivestream(ChannelIdentifier channelIdentifier); - Task ImportFollows(string username, IApiClient apiClient); + Task ImportFollows(string username, IApiClient apiClient, IViewAware viewAware); /// Refreshing data for all followed livestreams Task RefreshLivestreams(); diff --git a/Livestream.Monitor/Model/Monitoring/MonitorStreamsModel.cs b/Livestream.Monitor/Model/Monitoring/MonitorStreamsModel.cs index a61a85b..60dc87d 100644 --- a/Livestream.Monitor/Model/Monitoring/MonitorStreamsModel.cs +++ b/Livestream.Monitor/Model/Monitoring/MonitorStreamsModel.cs @@ -157,19 +157,24 @@ public async Task AddLivestream(ChannelIdentifier channelIdentifier, IViewAware if (channelIdentifier == null) throw new ArgumentNullException(nameof(channelIdentifier)); if (channelIdentifiers.Contains(channelIdentifier)) return; // ignore duplicate requests - var livestreamQueryResults = await channelIdentifier.ApiClient.AddChannel(channelIdentifier); + var apiClient = channelIdentifier.ApiClient; + if (!apiClient.IsAuthorized) await apiClient.Authorize(viewAware); + + var livestreamQueryResults = await apiClient.AddChannel(channelIdentifier); livestreamQueryResults.EnsureAllQuerySuccess(); AddChannels(channelIdentifier); Livestreams.AddRange(livestreamQueryResults.Select(x => x.LivestreamModel)); } - public async Task ImportFollows(string username, IApiClient apiClient) + public async Task ImportFollows(string username, IApiClient apiClient, IViewAware viewAware) { if (username == null) throw new ArgumentNullException(nameof(username)); if (apiClient == null) throw new ArgumentNullException(nameof(apiClient)); if (!apiClient.HasUserFollowQuerySupport) throw new InvalidOperationException($"{apiClient.ApiName} does not have support for getting followed streams."); + if (!apiClient.IsAuthorized) await apiClient.Authorize(viewAware); + var followedChannelsQueryResults = await apiClient.GetUserFollows(username); followedChannelsQueryResults.EnsureAllQuerySuccess(); diff --git a/Livestream.Monitor/ViewModels/HeaderViewModel.cs b/Livestream.Monitor/ViewModels/HeaderViewModel.cs index 746e001..84b9017 100644 --- a/Livestream.Monitor/ViewModels/HeaderViewModel.cs +++ b/Livestream.Monitor/ViewModels/HeaderViewModel.cs @@ -165,7 +165,7 @@ await this.ShowMessageAsync("No import support", var dialogController = await this.ShowProgressAsync("Importing followed streams", $"Importing followed streams from '{SelectedApiClient.ApiName}' for username '{username}'"); try { - await MonitorStreamsModel.ImportFollows(username, SelectedApiClient); + await MonitorStreamsModel.ImportFollows(username, SelectedApiClient, this); } catch (Exception ex) {