add channel categories (#1727)

* add channel categories

* add specific class

* speed

* Update Channel.js

* fix type typo

* Update Channel.js

* rewrite position stuff in prep for category sorting

* fix small issues in generation of permissions

* Update Guild.js

* Update Constants.js

* Update GuildChannel.js

* doc fix

* Update GuildChannel.js

* <.<
This commit is contained in:
Gus Caplan
2017-09-09 07:11:54 -05:00
committed by Crawl
parent ac4b2b3193
commit c46c092d0d
5 changed files with 98 additions and 57 deletions

View File

@@ -891,10 +891,9 @@ class Guild extends Base {
/**
* Creates a new channel in the guild.
* @param {string} name The name of the new channel
* @param {string} type The type of the new channel, either `text` or `voice`
* @param {Object} [options={}] Options
* @param {string} type The type of the new channel, either `text`, `voice`, or `category`
* @param {Object} [options] Options
* @param {Array<PermissionOverwrites|ChannelCreationOverwrites>} [options.overwrites] Permission overwrites
* to apply to the new channel
* @param {string} [options.reason] Reason for creating this channel
* @returns {Promise<TextChannel|VoiceChannel>}
* @example
@@ -1205,31 +1204,17 @@ class Guild extends Base {
/**
* Fetches a collection of channels in the current guild sorted by position.
* @param {string} type The channel type
* @param {Channel} channel Channel
* @returns {Collection<Snowflake, GuildChannel>}
* @private
*/
_sortedChannels(type) {
return this._sortPositionWithID(this.channels.filter(c => {
if (type === 'voice' && c.type === 'voice') return true;
else if (type !== 'voice' && c.type !== 'voice') return true;
else return type === c.type;
}));
}
/**
* Sorts a collection by object position or ID if the positions are equivalent.
* Intended to be identical to Discord's sorting method.
* @param {Collection} collection The collection to sort
* @returns {Collection}
* @private
*/
_sortPositionWithID(collection) {
return collection.sort((a, b) =>
a.position !== b.position ?
a.position - b.position :
Long.fromString(a.id).sub(Long.fromString(b.id)).toNumber()
);
_sortedChannels(channel) {
const sort = col => col
.sort((a, b) => a.rawPosition - b.rawPosition || Long.fromString(a.id).sub(Long.fromString(b.id)).toNumber());
if (channel.type === Constants.ChannelTypes.CATEGORY) {
return sort(this.channels.filter(c => c.type === Constants.ChannelTypes.CATEGORY));
}
return sort(this.channels.filter(c => c.parent === channel.parent));
}
}