Skip to content

Commit

Permalink
Fix first time twitch adds authorization
Browse files Browse the repository at this point in the history
Simplify twitch authorization messaging
Fix querying streams in helix api
Remove no longer used configuration setting "TwitchAuthTokenInLivestreamerConfig"
  • Loading branch information
laurencee committed May 6, 2020
1 parent 369896c commit b935a88
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public async Task<List<Stream>> GetStreams(GetStreamsQuery getStreamsQuery, Canc
taken += take;
}
}

if (!streams.Any())
else
{
var streamRoot = await ExecuteRequest<StreamsRoot>(request, cancellationToken);
streams = streamRoot.Streams;
Expand Down
4 changes: 2 additions & 2 deletions GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
[assembly: AssemblyVersion("2.12.8.0")]
[assembly: AssemblyFileVersion("2.12.8.0")]
17 changes: 2 additions & 15 deletions Livestream.Monitor/Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -182,18 +182,6 @@ public bool PassthroughClientId
[JsonConverter(typeof(ExcludeNotifyConverter))]
public BindableCollection<UniqueStreamKey> ExcludeFromNotifying { get; } = new BindableCollection<UniqueStreamKey>();

[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
{
Expand All @@ -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
/// </summary>
public bool TwitchAuthTokenSet => TwitchAuthTokenInLivestreamerConfig ||
!string.IsNullOrWhiteSpace(TwitchAuthToken);
public bool TwitchAuthTokenSet => !string.IsNullOrWhiteSpace(TwitchAuthToken);

/// <summary>
/// Name of the livestreamer/streamlink exe without the file extension
Expand Down
20 changes: 2 additions & 18 deletions Livestream.Monitor/Model/ApiClients/TwitchApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/// <summary> Refreshing data for all followed livestreams </summary>
Task RefreshLivestreams();
Expand Down
9 changes: 7 additions & 2 deletions Livestream.Monitor/Model/Monitoring/MonitorStreamsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion Livestream.Monitor/ViewModels/HeaderViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit b935a88

Please sign in to comment.