From 9f5360bc6f3c82000d2eff4da81b9652a662358e Mon Sep 17 00:00:00 2001 From: RogueException Date: Wed, 7 Oct 2015 13:44:16 -0300 Subject: [PATCH] Channel reordering fixes --- src/Discord.Net/DiscordAPIClient.cs | 2 +- src/Discord.Net/DiscordClient.API.cs | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Discord.Net/DiscordAPIClient.cs b/src/Discord.Net/DiscordAPIClient.cs index b92b88d4c..25c106ddb 100644 --- a/src/Discord.Net/DiscordAPIClient.cs +++ b/src/Discord.Net/DiscordAPIClient.cs @@ -86,7 +86,7 @@ namespace Discord var request = new EditChannelRequest { Name = name, Topic = topic }; return _rest.Patch(Endpoints.Channel(channelId), request); } - public Task ReorderChannels(string serverId, int startPos, IEnumerable channelIds) + public Task ReorderChannels(string serverId, IEnumerable channelIds, int startPos = 0) { if (serverId == null) throw new ArgumentNullException(nameof(serverId)); if (channelIds == null) throw new ArgumentNullException(nameof(channelIds)); diff --git a/src/Discord.Net/DiscordClient.API.cs b/src/Discord.Net/DiscordClient.API.cs index bcbbab09c..28232ba1e 100644 --- a/src/Discord.Net/DiscordClient.API.cs +++ b/src/Discord.Net/DiscordClient.API.cs @@ -139,27 +139,29 @@ namespace Discord channels[i] = channels[i - 1]; channels[newPos] = channel; } - await _api.ReorderChannels(channel.ServerId, minPos, channels.Skip(minPos).Select(x => x.Id)); + await _api.ReorderChannels(channel.ServerId, channels.Skip(minPos).Select(x => x.Id), minPos); } } - public Task ReorderChannels(Server server, int startPos, IEnumerable channels) - => ReorderChannels(server.Id, startPos, channels); - public Task ReorderChannels(string serverId, int startPos, IEnumerable channels) + public Task ReorderChannels(Server server, IEnumerable channels, int startPos = 0) + => ReorderChannels(server.Id, channels, startPos); + public Task ReorderChannels(string serverId, IEnumerable channels, int startPos = 0) { if (serverId == null) throw new ArgumentNullException(nameof(serverId)); if (channels == null) throw new ArgumentNullException(nameof(channels)); if (startPos < 0) throw new ArgumentOutOfRangeException(nameof(startPos), "startPos must be a positive integer."); - return _api.ReorderChannels(serverId, startPos, channels.Select(x => + var channelIds = channels.Select(x => { if (x is string) return x as string; else if (x is Channel) - return (x as Role).Id; + return (x as Channel).Id; else throw new ArgumentException("Channels must be a collection of string or Channel.", nameof(channels)); - })); + }); + + return _api.ReorderChannels(serverId, channelIds, startPos); } /// Destroys the provided channel.