Skip to content

Commit

Permalink
Optimize thread inclusion UX across GUI and CLI
Browse files Browse the repository at this point in the history
Related to Tyrrrz#1119
  • Loading branch information
Tyrrrz committed Aug 28, 2023
1 parent d430f77 commit 3740d64
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 79 deletions.
14 changes: 5 additions & 9 deletions DiscordChatExporter.Cli/Commands/ExportAllCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@ public class ExportAllCommand : ExportCommandBase

[CommandOption(
"include-threads",
Description = "Specifies which types of threads should be included.",
Description = "Which types of threads should be included.",
Converter = typeof(ThreadInclusionBindingConverter)
)]
public ThreadInclusion ThreadInclusion { get; init; } = ThreadInclusion.None;

private bool IncludeThreads => ThreadInclusion != ThreadInclusion.None;

private bool IncludeArchivedThreads => ThreadInclusion.HasFlag(ThreadInclusion.Archived);

[CommandOption(
"data-package",
Description = "Path to the personal data package (ZIP file) requested from Discord. "
Expand Down Expand Up @@ -74,12 +70,12 @@ var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken)
}

// Threads
if (IncludeThreads)
if (ThreadInclusion != ThreadInclusion.None)
{
await foreach (
var thread in Discord.GetGuildThreadsAsync(
guild.Id,
IncludeArchivedThreads,
ThreadInclusion == ThreadInclusion.All,
cancellationToken
)
)
Expand Down Expand Up @@ -136,9 +132,9 @@ await console.Error.WriteLineAsync(
channels.RemoveAll(c => c.Kind.IsGuild());
if (!IncludeVoiceChannels)
channels.RemoveAll(c => c.Kind.IsVoice());
if (!IncludeThreads)
if (ThreadInclusion == ThreadInclusion.None)
channels.RemoveAll(c => c.Kind.IsThread());
if (!IncludeArchivedThreads)
if (ThreadInclusion != ThreadInclusion.All)
channels.RemoveAll(c => c.Kind.IsThread() && c.IsArchived);

await ExportAsync(console, channels);
Expand Down
10 changes: 3 additions & 7 deletions DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@ public class ExportGuildCommand : ExportCommandBase

[CommandOption(
"include-threads",
Description = "Specifies which types of threads should be included.",
Description = "Which types of threads should be included.",
Converter = typeof(ThreadInclusionBindingConverter)
)]
public ThreadInclusion ThreadInclusion { get; init; } = ThreadInclusion.None;

private bool IncludeThreads => ThreadInclusion != ThreadInclusion.None;

private bool IncludeArchivedThreads => ThreadInclusion.HasFlag(ThreadInclusion.Archived);

public override async ValueTask ExecuteAsync(IConsole console)
{
await base.ExecuteAsync(console);
Expand All @@ -52,12 +48,12 @@ public override async ValueTask ExecuteAsync(IConsole console)
}

// Threads
if (IncludeThreads)
if (ThreadInclusion != ThreadInclusion.None)
{
await foreach (
var thread in Discord.GetGuildThreadsAsync(
GuildId,
IncludeArchivedThreads,
ThreadInclusion == ThreadInclusion.All,
cancellationToken
)
)
Expand Down
27 changes: 12 additions & 15 deletions DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ public class GetChannelsCommand : DiscordCommandBase

[CommandOption(
"include-threads",
Description = "Specifies which types of threads should be included.",
Description = "Which types of threads should be included.",
Converter = typeof(ThreadInclusionBindingConverter)
)]
public ThreadInclusion ThreadInclusion { get; init; } = ThreadInclusion.None;

private bool IncludeThreads => ThreadInclusion != ThreadInclusion.None;

private bool IncludeArchivedThreads => ThreadInclusion.HasFlag(ThreadInclusion.Archived);

public override async ValueTask ExecuteAsync(IConsole console)
{
await base.ExecuteAsync(console);
Expand All @@ -50,17 +46,18 @@ public override async ValueTask ExecuteAsync(IConsole console)
.OrderDescending()
.FirstOrDefault();

var threads = IncludeThreads
? (
await Discord.GetGuildThreadsAsync(
GuildId,
IncludeArchivedThreads,
cancellationToken
var threads =
ThreadInclusion != ThreadInclusion.None
? (
await Discord.GetGuildThreadsAsync(
GuildId,
ThreadInclusion == ThreadInclusion.All,
cancellationToken
)
)
)
.OrderBy(c => c.Name)
.ToArray()
: Array.Empty<Channel>();
.OrderBy(c => c.Name)
.ToArray()
: Array.Empty<Channel>();

foreach (var channel in channels)
{
Expand Down
12 changes: 4 additions & 8 deletions DiscordChatExporter.Cli/Commands/Shared/ThreadInclusion.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System;
namespace DiscordChatExporter.Cli.Commands.Shared;

namespace DiscordChatExporter.Cli.Commands.Shared;

[Flags]
public enum ThreadInclusion
{
None = 0,
Active = 1,
Archived = 2,
All = Active | Archived
None,
Active,
All
}
8 changes: 8 additions & 0 deletions DiscordChatExporter.Gui/Models/ThreadInclusion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace DiscordChatExporter.Gui.Models;

public enum ThreadInclusion
{
None,
Active,
All
}
5 changes: 2 additions & 3 deletions DiscordChatExporter.Gui/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using Cogwheel;
using DiscordChatExporter.Core.Exporting;
using DiscordChatExporter.Gui.Models;
using Microsoft.Win32;

namespace DiscordChatExporter.Gui.Services;
Expand All @@ -16,9 +17,7 @@ public partial class SettingsService : SettingsBase

public bool IsTokenPersisted { get; set; } = true;

public bool ShouldShowThreads { get; set; }

public bool ShouldShowArchivedThreads { get; set; }
public ThreadInclusion ThreadInclusion { get; set; } = ThreadInclusion.None;

public string DateFormat { get; set; } = "MM/dd/yyyy h:mm tt";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using DiscordChatExporter.Core.Exceptions;
using DiscordChatExporter.Core.Exporting;
using DiscordChatExporter.Core.Utils.Extensions;
using DiscordChatExporter.Gui.Models;
using DiscordChatExporter.Gui.Services;
using DiscordChatExporter.Gui.Utils;
using DiscordChatExporter.Gui.ViewModels.Dialogs;
Expand Down Expand Up @@ -169,12 +170,12 @@ public async ValueTask PullChannelsAsync()
}

// Threads
if (_settingsService.ShouldShowThreads)
if (_settingsService.ThreadInclusion != ThreadInclusion.None)
{
await foreach (
var thread in _discord.GetGuildThreadsAsync(
SelectedGuild.Id,
_settingsService.ShouldShowArchivedThreads
_settingsService.ThreadInclusion == ThreadInclusion.All
)
)
{
Expand Down
22 changes: 7 additions & 15 deletions DiscordChatExporter.Gui/ViewModels/Dialogs/SettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using DiscordChatExporter.Gui.Models;
using DiscordChatExporter.Gui.Services;
using DiscordChatExporter.Gui.ViewModels.Framework;

Expand Down Expand Up @@ -26,23 +28,13 @@ public bool IsTokenPersisted
set => _settingsService.IsTokenPersisted = value;
}

public bool ShouldShowThreads
{
get => _settingsService.ShouldShowThreads;
set => _settingsService.ShouldShowThreads = value;
}
public IReadOnlyList<ThreadInclusion> AvailableThreadInclusions { get; } =
Enum.GetValues<ThreadInclusion>();

public bool ShouldShowArchivedThreads
public ThreadInclusion ThreadInclusion
{
get => _settingsService.ShouldShowArchivedThreads;
set
{
_settingsService.ShouldShowArchivedThreads = value;

// Enabling archived threads implicitly enables threads
if (value)
ShouldShowThreads = true;
}
get => _settingsService.ThreadInclusion;
set => _settingsService.ThreadInclusion = value;
}

public string DateFormat
Expand Down
25 changes: 5 additions & 20 deletions DiscordChatExporter.Gui/Views/Dialogs/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,21 @@
IsChecked="{Binding IsTokenPersisted}" />
</DockPanel>

<!-- Show threads -->
<!-- Thread inclusion -->
<DockPanel
Margin="16,8"
Background="Transparent"
LastChildFill="False"
ToolTip="Pull threads and show them in the channel list">
ToolTip="Which types of threads to show in the channel list">
<TextBlock
VerticalAlignment="Center"
DockPanel.Dock="Left"
Text="Show threads" />
<ToggleButton
VerticalAlignment="Center"
DockPanel.Dock="Right"
IsChecked="{Binding ShouldShowThreads}" />
</DockPanel>

<!-- Show archived threads -->
<DockPanel
Margin="16,8"
Background="Transparent"
LastChildFill="False"
ToolTip="Pull archived threads and show them in the channel list">
<TextBlock
VerticalAlignment="Center"
DockPanel.Dock="Left"
Text="Show archived threads" />
<ToggleButton
<ComboBox
VerticalAlignment="Center"
DockPanel.Dock="Right"
IsChecked="{Binding ShouldShowArchivedThreads}" />
ItemsSource="{Binding AvailableThreadInclusions}"
SelectedItem="{Binding ThreadInclusion}" />
</DockPanel>

<!-- Date format -->
Expand Down

0 comments on commit 3740d64

Please sign in to comment.