You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
678 B
22 lines
678 B
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace DiscordChatExporter.Core.Discord.Data;
|
|
|
|
public record ChannelNode(Channel Channel, IReadOnlyList<ChannelNode> Children)
|
|
{
|
|
public static IReadOnlyList<ChannelNode> BuildTree(IReadOnlyList<Channel> channels)
|
|
{
|
|
IReadOnlyList<ChannelNode> GetChildren(Channel parent) =>
|
|
channels
|
|
.Where(c => c.Parent?.Id == parent.Id)
|
|
.Select(c => new ChannelNode(c, GetChildren(c)))
|
|
.ToArray();
|
|
|
|
return channels
|
|
.Where(c => c.Parent is null)
|
|
.Select(c => new ChannelNode(c, GetChildren(c)))
|
|
.ToArray();
|
|
}
|
|
}
|