Fix #995, Move Category Implementation from IGuildChannel to INestedChannel (#1004)

* Fix #995 ICategoryChannel.CategoryID throws NotSupportedException

* Add tests

* change run mode of TestChannelCategories

* Add throw for GetCategoryAsync

* Add xml doc explaining why exception is thrown

* Add test coverage for text and voice channel categories

* initial implementation of INestedChannel

* more implementation of INestedChannel design

* Add case in RestChannel Create for Category type

* set the CategoryID for RestVoiceChannel

* rewrite channel category tests to work with existing pattern

* remove outdated todo

* Make IVoiceChannel implement INestedChannel

* remove redundant interface implementation

* Add c#7 feature from feedback

* Remove redundant GetCategoryAsync methods from socket entities

* Added configureawait to async methods

* change signature of interface GetCategoryAsync

* Add check for cachemode in rest channel GetCategory

* remove redundant IGuildChannel interface from ITextChannel and IVoiceChannel
This commit is contained in:
Chris Johnston
2018-05-26 11:06:35 -07:00
committed by Christopher F
parent 4d8764e124
commit f9cbff5e42
16 changed files with 168 additions and 51 deletions

View File

@@ -1,4 +1,4 @@
using Discord.Audio;
using Discord.Audio;
using Discord.Rest;
using System;
using System.Collections.Generic;
@@ -15,6 +15,9 @@ namespace Discord.WebSocket
{
public int Bitrate { get; private set; }
public int? UserLimit { get; private set; }
public ulong? CategoryId { get; private set; }
public ICategoryChannel Category
=> CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null;
public override IReadOnlyCollection<SocketGuildUser> Users
=> Guild.Users.Where(x => x.VoiceChannel?.Id == Id).ToImmutableArray();
@@ -32,7 +35,7 @@ namespace Discord.WebSocket
internal override void Update(ClientState state, Model model)
{
base.Update(state, model);
CategoryId = model.CategoryId;
Bitrate = model.Bitrate.Value;
UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null;
}
@@ -52,7 +55,7 @@ namespace Discord.WebSocket
return user;
return null;
}
private string DebuggerDisplay => $"{Name} ({Id}, Voice)";
internal new SocketVoiceChannel Clone() => MemberwiseClone() as SocketVoiceChannel;
@@ -61,5 +64,9 @@ namespace Discord.WebSocket
=> Task.FromResult<IGuildUser>(GetUser(id));
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
=> ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable();
// INestedChannel
Task<ICategoryChannel> INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult(Category);
}
}