Implement progress reporting when downloading messages (#57)

This commit is contained in:
Alexey Golub
2018-06-25 23:11:34 +03:00
committed by GitHub
parent e4f0b8193f
commit 8678043f0d
6 changed files with 89 additions and 42 deletions

View File

@@ -25,6 +25,7 @@ namespace DiscordChatExporter.Gui.ViewModels
private readonly Dictionary<Guild, IReadOnlyList<Channel>> _guildChannelsMap;
private bool _isBusy;
private double _progress;
private string _token;
private IReadOnlyList<Guild> _availableGuilds;
private Guild _selectedGuild;
@@ -43,6 +44,18 @@ namespace DiscordChatExporter.Gui.ViewModels
public bool IsDataAvailable => AvailableGuilds.NotNullAndAny();
public bool IsProgressIndeterminate => Progress <= 0;
public double Progress
{
get => _progress;
private set
{
Set(ref _progress, value);
RaisePropertyChanged(() => IsProgressIndeterminate);
}
}
public string Token
{
get => _token;
@@ -225,10 +238,13 @@ namespace DiscordChatExporter.Gui.ViewModels
// Get guild
var guild = SelectedGuild;
// Create progress handler
var progressHandler = new Progress<double>(p => Progress = p);
try
{
// Get messages
var messages = await _dataService.GetChannelMessagesAsync(token, channel.Id, from, to);
var messages = await _dataService.GetChannelMessagesAsync(token, channel.Id, from, to, progressHandler);
// Group messages
var messageGroups = _messageGroupService.GroupMessages(messages);
@@ -253,6 +269,7 @@ namespace DiscordChatExporter.Gui.ViewModels
MessengerInstance.Send(new ShowNotificationMessage("You don't have access to this channel"));
}
Progress = 0;
IsBusy = false;
}
}