| @@ -1,4 +1,4 @@ | |||||
| using System; | |||||
| using System; | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
| using System.Diagnostics; | using System.Diagnostics; | ||||
| @@ -15,7 +15,9 @@ namespace Discord.WebSocket | |||||
| public class SocketCategoryChannel : SocketGuildChannel, ICategoryChannel | public class SocketCategoryChannel : SocketGuildChannel, ICategoryChannel | ||||
| { | { | ||||
| public override IReadOnlyCollection<SocketGuildUser> Users | public override IReadOnlyCollection<SocketGuildUser> Users | ||||
| => throw new NotSupportedException(); | |||||
| => Guild.Users.Where(x => Permissions.GetValue( | |||||
| Permissions.ResolveChannel(Guild, x, this, Permissions.ResolveGuild(Guild, x)), | |||||
| ChannelPermission.ViewChannel)).ToImmutableArray(); | |||||
| public IReadOnlyCollection<SocketGuildChannel> Channels | public IReadOnlyCollection<SocketGuildChannel> Channels | ||||
| => Guild.Channels.Where(x => x.CategoryId == Id).ToImmutableArray(); | => Guild.Channels.Where(x => x.CategoryId == Id).ToImmutableArray(); | ||||
| @@ -31,14 +33,28 @@ namespace Discord.WebSocket | |||||
| return entity; | return entity; | ||||
| } | } | ||||
| //Users | |||||
| public override SocketGuildUser GetUser(ulong id) | |||||
| { | |||||
| var user = Guild.GetUser(id); | |||||
| if (user != null) | |||||
| { | |||||
| var guildPerms = Permissions.ResolveGuild(Guild, user); | |||||
| var channelPerms = Permissions.ResolveChannel(Guild, user, this, guildPerms); | |||||
| if (Permissions.GetValue(channelPerms, ChannelPermission.ViewChannel)) | |||||
| return user; | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private string DebuggerDisplay => $"{Name} ({Id}, Category)"; | private string DebuggerDisplay => $"{Name} ({Id}, Category)"; | ||||
| internal new SocketCategoryChannel Clone() => MemberwiseClone() as SocketCategoryChannel; | |||||
| internal new SocketCategoryChannel Clone() => MemberwiseClone() as SocketCategoryChannel; | |||||
| // IGuildChannel | // IGuildChannel | ||||
| IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | ||||
| => throw new NotSupportedException(); | |||||
| => ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable(); | |||||
| Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | ||||
| => throw new NotSupportedException(); | |||||
| => Task.FromResult<IGuildUser>(GetUser(id)); | |||||
| Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) | Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) | ||||
| => throw new NotSupportedException(); | => throw new NotSupportedException(); | ||||
| Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options) | Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options) | ||||
| @@ -46,8 +62,8 @@ namespace Discord.WebSocket | |||||
| //IChannel | //IChannel | ||||
| IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | ||||
| => throw new NotSupportedException(); | |||||
| => ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable(); | |||||
| Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | ||||
| => throw new NotSupportedException(); | |||||
| => Task.FromResult<IUser>(GetUser(id)); | |||||
| } | } | ||||
| } | } | ||||