From 5049e573b3f696170ac5ce85695c00e7c60f9b5c Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sun, 31 Jul 2016 22:06:23 -0400 Subject: [PATCH] Support GET /channels/{id}/pins This commit adds GET /channels/{id}/pins to the ApiClient, and adds GetPinnedMessagesAsync to IMessageChannel. This method is only implemented on the REST entities, and the WebSocket entities do not include an override to retrieve pinned messages from cache. --- src/Discord.Net/API/DiscordRestApiClient.cs | 6 ++++++ src/Discord.Net/Entities/Channels/IMessageChannel.cs | 2 ++ src/Discord.Net/Rest/Entities/Channels/DMChannel.cs | 5 +++++ src/Discord.Net/Rest/Entities/Channels/GroupChannel.cs | 5 +++++ src/Discord.Net/Rest/Entities/Channels/TextChannel.cs | 7 ++++++- 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net/API/DiscordRestApiClient.cs b/src/Discord.Net/API/DiscordRestApiClient.cs index bf78f350c..2865430df 100644 --- a/src/Discord.Net/API/DiscordRestApiClient.cs +++ b/src/Discord.Net/API/DiscordRestApiClient.cs @@ -357,6 +357,12 @@ namespace Discord.API await SendAsync("DELETE", $"channels/{channelId}/pins/{messageId}", options: options).ConfigureAwait(false); } + public async Task> GetPinsAsync(ulong channelId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + + return await SendAsync>("GET", $"channels/{channelId}/pins", options: options).ConfigureAwait(false); + } //Channel Recipients public async Task AddGroupRecipientAsync(ulong channelId, ulong userId, RequestOptions options = null) diff --git a/src/Discord.Net/Entities/Channels/IMessageChannel.cs b/src/Discord.Net/Entities/Channels/IMessageChannel.cs index 2d1713a06..74e0188bc 100644 --- a/src/Discord.Net/Entities/Channels/IMessageChannel.cs +++ b/src/Discord.Net/Entities/Channels/IMessageChannel.cs @@ -23,6 +23,8 @@ namespace Discord Task> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch); /// Gets a collection of messages in this channel. Task> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch); + /// Gets a collection of pinned messages in this channel. + Task> GetPinnedMessagesAsync(); /// Bulk deletes multiple messages. Task DeleteMessagesAsync(IEnumerable messages); diff --git a/src/Discord.Net/Rest/Entities/Channels/DMChannel.cs b/src/Discord.Net/Rest/Entities/Channels/DMChannel.cs index 0ec4b5c36..c9972f745 100644 --- a/src/Discord.Net/Rest/Entities/Channels/DMChannel.cs +++ b/src/Discord.Net/Rest/Entities/Channels/DMChannel.cs @@ -108,6 +108,11 @@ namespace Discord { await Discord.ApiClient.DeleteDMMessagesAsync(Id, new DeleteMessagesParams { MessageIds = messages.Select(x => x.Id) }).ConfigureAwait(false); } + public async Task> GetPinnedMessagesAsync() + { + var models = await Discord.ApiClient.GetPinsAsync(Id); + return models.Select(x => new Message(this, new User(x.Author.Value), x)).ToImmutableArray(); + } public async Task TriggerTypingAsync() { diff --git a/src/Discord.Net/Rest/Entities/Channels/GroupChannel.cs b/src/Discord.Net/Rest/Entities/Channels/GroupChannel.cs index 745245bb3..a2143c66e 100644 --- a/src/Discord.Net/Rest/Entities/Channels/GroupChannel.cs +++ b/src/Discord.Net/Rest/Entities/Channels/GroupChannel.cs @@ -133,6 +133,11 @@ namespace Discord { await Discord.ApiClient.DeleteDMMessagesAsync(Id, new DeleteMessagesParams { MessageIds = messages.Select(x => x.Id) }).ConfigureAwait(false); } + public async Task> GetPinnedMessagesAsync() + { + var models = await Discord.ApiClient.GetPinsAsync(Id); + return models.Select(x => new Message(this, new User(x.Author.Value), x)).ToImmutableArray(); + } public async Task TriggerTypingAsync() { diff --git a/src/Discord.Net/Rest/Entities/Channels/TextChannel.cs b/src/Discord.Net/Rest/Entities/Channels/TextChannel.cs index f301a7e18..13acd0a22 100644 --- a/src/Discord.Net/Rest/Entities/Channels/TextChannel.cs +++ b/src/Discord.Net/Rest/Entities/Channels/TextChannel.cs @@ -102,7 +102,12 @@ namespace Discord { await Discord.ApiClient.DeleteMessagesAsync(Guild.Id, Id, new DeleteMessagesParams { MessageIds = messages.Select(x => x.Id) }).ConfigureAwait(false); } - + public async Task> GetPinnedMessagesAsync() + { + var models = await Discord.ApiClient.GetPinsAsync(Id); + return models.Select(x => new Message(this, new User(x.Author.Value), x)).ToImmutableArray(); + } + public async Task TriggerTypingAsync() { await Discord.ApiClient.TriggerTypingIndicatorAsync(Id).ConfigureAwait(false);