-
-
Notifications
You must be signed in to change notification settings - Fork 737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for channel categories #907
Conversation
Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories
… of ChannelCategory to be consistant with how text / voice channels are named.
…nto feature/channel-categories
[DebuggerDisplay(@"{DebuggerDisplay,nq}")] | ||
public class RestCategoryChannel : RestGuildChannel, ICategoryChannel | ||
{ | ||
public string Mention => MentionUtils.MentionChannel(Id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably shouldn't be implemented. Text Channels are the only channel types that have a full support for being mentioned.
{ | ||
public override IReadOnlyCollection<SocketGuildUser> Users | ||
=> Guild.Users.Where(x => x.VoiceChannel?.Id == Id).ToImmutableArray(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Channels
property should be implemented here since the cache is available to pull from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AntiTcb has been addressed, only card hasn't been closed since I added the feature under the selected line.
…operty to SocketCategoryChannel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this looks fine, only a few style tweaks which I would make.
@@ -16,6 +16,8 @@ public class RestGuildChannel : RestChannel, IGuildChannel, IUpdateable | |||
internal IGuild Guild { get; } | |||
public string Name { get; private set; } | |||
public int Position { get; private set; } | |||
public ulong? CategoryId { get; private set; } | |||
public async Task<ICategoryChannel> GetCategoryAsync() => CategoryId == null ? null : await Guild.GetChannelAsync(CategoryId.Value).ConfigureAwait(false) as ICategoryChannel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably best to put the body on a newline, to be consistent with the rest of the lib:
int MyMethod()
=> 5;
if (mode == CacheMode.AllowDownload) | ||
return await GetCategoryChannelsAsync(options).ConfigureAwait(false); | ||
else | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return an empty ImmutableArray here, as in GetVoiceChannels.
Furthermore, this method should be below GetVoiceChannelAsync and an accompanying GetCategoryAsync should be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can also wrap the empty array in a Task.FromResult()
and not await
the other method so we avoid allocating the statemachine at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Joe4evr looking at the other methods that return immutable arrays (GetVoiceChannelsAsync
) I see that they don't even use Task.FromResult
to return the immutable array. Ill just return a new instance. instead of wrapping it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair.
@@ -17,6 +17,9 @@ public class SocketGuildChannel : SocketChannel, IGuildChannel | |||
public SocketGuild Guild { get; } | |||
public string Name { get; private set; } | |||
public int Position { get; private set; } | |||
public ulong? CategoryId { get; private set; } | |||
public ICategoryChannel Category => CategoryId == null ? null : Guild.GetChannel(CategoryId.Value) as ICategoryChannel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getter should probably be on a new line to increase clarity.
@@ -17,6 +17,9 @@ public class SocketGuildChannel : SocketChannel, IGuildChannel | |||
public SocketGuild Guild { get; } | |||
public string Name { get; private set; } | |||
public int Position { get; private set; } | |||
public ulong? CategoryId { get; private set; } | |||
public ICategoryChannel Category => CategoryId == null ? null : Guild.GetChannel(CategoryId.Value) as ICategoryChannel; | |||
Task<ICategoryChannel> IGuildChannel.GetCategoryAsync() => Task.FromResult(Category); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method bodies should also be on a new line.
@@ -645,6 +650,8 @@ Task<ITextChannel> IGuild.GetTextChannelAsync(ulong id, CacheMode mode, RequestO | |||
=> Task.FromResult<ITextChannel>(GetTextChannel(id)); | |||
Task<IReadOnlyCollection<IVoiceChannel>> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options) | |||
=> Task.FromResult<IReadOnlyCollection<IVoiceChannel>>(VoiceChannels); | |||
Task<IReadOnlyCollection<ICategoryChannel>> IGuild.GetCategoriesAsync(CacheMode mode , RequestOptions options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, move this below GetVoiceChannelAsync and add GetCategoryAsync
Thanks for your changes! |
commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (#907) commit 41ed910 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c3 Merge: 4589d73 678a723 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777d Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (discord-net#907) commit 41ed910 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c3 Merge: 4589d73 678a723 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777d Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
This PR continues work from the (closed) #821 PR.
Credit for original work goes to Pegasy, However it looked like his work has gone stale so I've gone ahead and addressed the requested changes (and updated the branch).