mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-23 06:24:48 +00:00
[CLI] Fix sorting by channel/category position (#490)
This commit is contained in:
@@ -22,7 +22,7 @@ namespace DiscordChatExporter.Domain.Discord.Models
|
||||
}
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#channel-object
|
||||
public partial class Channel : IHasId
|
||||
public partial class Channel : IHasIdAndPosition
|
||||
{
|
||||
public Snowflake Id { get; }
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ using Tyrrrz.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Domain.Discord.Models
|
||||
{
|
||||
public partial class ChannelCategory : IHasId
|
||||
public partial class ChannelCategory : IHasIdAndPosition
|
||||
{
|
||||
public Snowflake Id { get; }
|
||||
|
||||
|
||||
@@ -2,29 +2,29 @@
|
||||
|
||||
namespace DiscordChatExporter.Domain.Discord.Models.Common
|
||||
{
|
||||
public partial class ChannelPositionBasedComparer : IComparer<Channel>
|
||||
public partial class PositionBasedComparer : IComparer<IHasIdAndPosition>
|
||||
{
|
||||
public int Compare(Channel? x, Channel? y)
|
||||
public int Compare(IHasIdAndPosition? x, IHasIdAndPosition? y)
|
||||
{
|
||||
int result;
|
||||
if (x != null)
|
||||
{
|
||||
result = x.Position.CompareTo(y?.Position);
|
||||
}
|
||||
else if (y != null)
|
||||
{
|
||||
result = -y.Position.CompareTo(x?.Position);
|
||||
if(result == 0)
|
||||
{
|
||||
result = x.Id.Value.CompareTo(y?.Id.Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
result = y == null ? 0 : -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ChannelPositionBasedComparer
|
||||
public partial class PositionBasedComparer
|
||||
{
|
||||
public static ChannelPositionBasedComparer Instance { get; } = new();
|
||||
public static PositionBasedComparer Instance { get; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace DiscordChatExporter.Domain.Discord.Models.Common
|
||||
{
|
||||
public interface IHasIdAndPosition : IHasId
|
||||
{
|
||||
int Position { get; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user