Skip to content
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

Closed
wants to merge 6 commits into from
Closed

Add support for channel categories #907

wants to merge 6 commits into from

Conversation

LDSpits
Copy link

@LDSpits LDSpits commented Dec 13, 2017

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).

pegasy and others added 5 commits September 24, 2017 15:49
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.
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class RestCategoryChannel : RestGuildChannel, ICategoryChannel
{
public string Mention => MentionUtils.MentionChannel(Id);
Copy link
Collaborator

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();

Copy link
Collaborator

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.

Copy link
Author

@LDSpits LDSpits Dec 14, 2017

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.

@LDSpits
Copy link
Author

LDSpits commented Dec 17, 2017

Any more feedback for this pull request? @AntiTcb @foxbot

Copy link
Member

@FiniteReality FiniteReality left a 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;
Copy link
Member

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;
Copy link
Member

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.

Copy link
Contributor

@Joe4evr Joe4evr Dec 20, 2017

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.

Copy link
Author

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.

Copy link
Contributor

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;
Copy link
Member

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);
Copy link
Member

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)
Copy link
Member

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

@foxbot
Copy link
Member

foxbot commented Jan 7, 2018

Thanks for your changes!

@foxbot foxbot closed this Jan 7, 2018
foxbot added a commit that referenced this pull request Jan 7, 2018
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)
FiniteReality pushed a commit to FiniteReality/Discord.Net that referenced this pull request May 5, 2018
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants