From 481b491f29ad269b94963033a41863d3aa6d5ee2 Mon Sep 17 00:00:00 2001 From: Simon Oxtoby Date: Sat, 12 Oct 2024 11:25:45 +1000 Subject: [PATCH] Removing nullability from all CancellationTokens and using default instead of null Resolves #213 --- SlackNet.Bot/BotMessage.cs | 2 +- SlackNet.Bot/IMessage.cs | 6 +- SlackNet.Bot/SlackBot.cs | 14 +-- SlackNet.Bot/SlackMessage.cs | 6 +- SlackNet.Tests/ApiLintTest.cs | 22 ++-- .../FactorySlackHandlerConfigurationTests.cs | 20 ++-- SlackNet.Tests/SlackBotTests.cs | 20 ++-- SlackNet/Http.cs | 6 +- SlackNet/ReconnectingWebSocket.cs | 4 +- SlackNet/SlackApiClient.cs | 40 +++---- SlackNet/SlackApiClientExtensions.cs | 4 +- SlackNet/SlackRtmClient.cs | 4 +- SlackNet/SlackSocketModeClient.cs | 4 +- SlackNet/SocketMode/CoreSocketModeClient.cs | 6 +- SlackNet/WebApi/ApiApi.cs | 4 +- SlackNet/WebApi/AppsConnectionsApi.cs | 4 +- SlackNet/WebApi/AppsEventAuthorizationsApi.cs | 4 +- SlackNet/WebApi/AuthApi.cs | 8 +- SlackNet/WebApi/BookmarksApi.cs | 16 +-- SlackNet/WebApi/BotsApi.cs | 4 +- SlackNet/WebApi/CallParticipantsApi.cs | 8 +- SlackNet/WebApi/CallsApi.cs | 16 +-- SlackNet/WebApi/ChatApi.cs | 40 +++---- SlackNet/WebApi/ConversationsApi.cs | 106 +++++++++--------- SlackNet/WebApi/DialogApi.cs | 4 +- SlackNet/WebApi/DndApi.cs | 24 ++-- SlackNet/WebApi/EmojiApi.cs | 4 +- SlackNet/WebApi/FileCommentsApi.cs | 4 +- SlackNet/WebApi/FilesApi.cs | 54 ++++----- SlackNet/WebApi/MigrationApi.cs | 4 +- SlackNet/WebApi/OAuthApi.cs | 4 +- SlackNet/WebApi/OAuthV2Api.cs | 4 +- SlackNet/WebApi/OpenIdApi.cs | 8 +- SlackNet/WebApi/PinsApi.cs | 20 ++-- SlackNet/WebApi/ReactionsApi.cs | 32 +++--- SlackNet/WebApi/RemindersApi.cs | 28 ++--- SlackNet/WebApi/RemoteFilesApi.cs | 70 ++++++------ SlackNet/WebApi/RtmApi.cs | 8 +- SlackNet/WebApi/ScheduledMessagesApi.cs | 4 +- SlackNet/WebApi/SearchApi.cs | 12 +- SlackNet/WebApi/TeamApi.cs | 20 ++-- SlackNet/WebApi/TeamBillingApi.cs | 4 +- SlackNet/WebApi/TeamPreferencesApi.cs | 4 +- SlackNet/WebApi/TeamProfileApi.cs | 4 +- SlackNet/WebApi/UserGroupUsersApi.cs | 8 +- SlackNet/WebApi/UserGroupsApi.cs | 20 ++-- SlackNet/WebApi/UserProfileApi.cs | 12 +- SlackNet/WebApi/UsersApi.cs | 44 ++++---- SlackNet/WebApi/ViewsApi.cs | 20 ++-- SlackNet/WebApi/WorkflowsApi.cs | 12 +- 50 files changed, 399 insertions(+), 401 deletions(-) diff --git a/SlackNet.Bot/BotMessage.cs b/SlackNet.Bot/BotMessage.cs index 20c2845a..3e8c9216 100644 --- a/SlackNet.Bot/BotMessage.cs +++ b/SlackNet.Bot/BotMessage.cs @@ -86,5 +86,5 @@ public HubIdentifier Hub /// /// Allows message sending to be cancelled, if it hasn't already been sent. /// - public CancellationToken? CancellationToken { get; set; } + public CancellationToken CancellationToken { get; set; } } \ No newline at end of file diff --git a/SlackNet.Bot/IMessage.cs b/SlackNet.Bot/IMessage.cs index 32bd279f..93b8d761 100644 --- a/SlackNet.Bot/IMessage.cs +++ b/SlackNet.Bot/IMessage.cs @@ -24,7 +24,7 @@ public interface IMessage IList Blocks { get; set; } bool IsInThread { get; } bool MentionsBot { get; } - Task ReplyWith(string text, bool createThread = false, CancellationToken? cancellationToken = null); - Task ReplyWith(BotMessage message, bool createThread = false, CancellationToken? cancellationToken = null); - Task ReplyWith(Func> createReply, bool createThread = false, CancellationToken? cancellationToken = null); + Task ReplyWith(string text, bool createThread = false, CancellationToken cancellationToken = default); + Task ReplyWith(BotMessage message, bool createThread = false, CancellationToken cancellationToken = default); + Task ReplyWith(Func> createReply, bool createThread = false, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/SlackNet.Bot/SlackBot.cs b/SlackNet.Bot/SlackBot.cs index c7210673..7c9cb628 100644 --- a/SlackNet.Bot/SlackBot.cs +++ b/SlackNet.Bot/SlackBot.cs @@ -32,7 +32,7 @@ public interface ISlackBot : IObserver /// /// Connect to Slack. /// - Task Connect(CancellationToken? cancellationToken = null); + Task Connect(CancellationToken cancellationToken = default); /// /// Transform stream of incoming messages. @@ -98,7 +98,7 @@ public interface ISlackBot : IObserver /// /// Send a message to Slack as the bot. /// - Task Send(BotMessage message, CancellationToken? cancellationToken = null); + Task Send(BotMessage message, CancellationToken cancellationToken = default); /// /// Show typing indicator in Slack while performing some action. @@ -210,7 +210,7 @@ public SlackBot(ISlackRtmClient rtmClient, ISlackApiClient apiClient, IScheduler .Where(m => m.User != Id) .SelectMany(CreateSlackMessage); _outgoingWithMiddlewareApplied = _outgoingMessages - .LimitFrequency(TimeSpan.FromSeconds(1), m => m.CancellationToken ?? CancellationToken.None, _scheduler); + .LimitFrequency(TimeSpan.FromSeconds(1), m => m.CancellationToken, _scheduler); } /// @@ -226,7 +226,7 @@ public SlackBot(ISlackRtmClient rtmClient, ISlackApiClient apiClient, IScheduler /// /// Connect to Slack. /// - public async Task Connect(CancellationToken? cancellationToken = null) + public async Task Connect(CancellationToken cancellationToken = default) { // If already connected, client will throw var connection = _rtm.Connect(cancellationToken: cancellationToken); @@ -451,11 +451,9 @@ private async Task> FetchUsers() /// /// Send a message to Slack as the bot. /// - public async Task Send(BotMessage message, CancellationToken? cancellationToken = null) + public async Task Send(BotMessage message, CancellationToken cancellationToken = default) { - var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource( - message.CancellationToken ?? CancellationToken.None, - cancellationToken ?? CancellationToken.None); + var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(message.CancellationToken, cancellationToken); message.CancellationToken = linkedTokenSource.Token; var sent = _sentMessages.FirstOrDefaultAsync(m => m.Message == message) diff --git a/SlackNet.Bot/SlackMessage.cs b/SlackNet.Bot/SlackMessage.cs index 77593c1c..b232229f 100644 --- a/SlackNet.Bot/SlackMessage.cs +++ b/SlackNet.Bot/SlackMessage.cs @@ -32,10 +32,10 @@ public class SlackMessage(ISlackBot bot) : IMessage || Text.IndexOf(bot.Name, StringComparison.OrdinalIgnoreCase) >= 0 || Conversation?.IsIm == true; - public Task ReplyWith(string text, bool createThread = false, CancellationToken? cancellationToken = null) => + public Task ReplyWith(string text, bool createThread = false, CancellationToken cancellationToken = default) => ReplyWith(new BotMessage { Text = text }, createThread, cancellationToken); - public async Task ReplyWith(Func> createReply, bool createThread = false, CancellationToken? cancellationToken = null) + public async Task ReplyWith(Func> createReply, bool createThread = false, CancellationToken cancellationToken = default) { await bot.WhileTyping(Conversation.Id, async () => { @@ -45,7 +45,7 @@ await bot.WhileTyping(Conversation.Id, async () => }).ConfigureAwait(false); } - public async Task ReplyWith(BotMessage message, bool createThread = false, CancellationToken? cancellationToken = null) + public async Task ReplyWith(BotMessage message, bool createThread = false, CancellationToken cancellationToken = default) { if (message == null) throw new ArgumentNullException(nameof(message)); diff --git a/SlackNet.Tests/ApiLintTest.cs b/SlackNet.Tests/ApiLintTest.cs index d939dad9..dc1ff4d6 100644 --- a/SlackNet.Tests/ApiLintTest.cs +++ b/SlackNet.Tests/ApiLintTest.cs @@ -84,7 +84,7 @@ private static IEnumerable ParameterTypes(MethodInfo method) private static void LastParamShouldBeOptionalCancellationToken(MethodInfo method) { var lastParam = method.GetParameters().Last(); - lastParam.ParameterType.ShouldBe(typeof(CancellationToken?), $"{method.DeclaringType!.Name}.{method.Name} is missing CancellationToken param"); + lastParam.ParameterType.ShouldBe(typeof(CancellationToken), $"{method.DeclaringType!.Name}.{method.Name} is missing CancellationToken param"); lastParam.DefaultValue.ShouldBeNull($"{method.DeclaringType.Name}.{method.Name} CancellationToken param isn't null by default"); } @@ -145,7 +145,7 @@ private static object DummyValue(ParameterInfo param) => ArgumentFactories.TryGe { typeof(IEnumerable), _ => Enumerable.Empty() }, { typeof(FileUpload), _ => new FileUpload(string.Empty, string.Empty) }, { typeof(IEnumerable), _ => Enumerable.Empty() }, - { typeof(CancellationToken?), _ => null }, + { typeof(CancellationToken), _ => null }, }; private static IEnumerable ApiClasses => typeof(ApiApi).Assembly @@ -163,47 +163,47 @@ public void Reset() Args = null; } - public Task Get(string apiMethod, Args args, CancellationToken? cancellationToken) + public Task Get(string apiMethod, Args args, CancellationToken cancellationToken) { SlackMethod = apiMethod; Args = args; return Task.FromResult(0); } - public Task Get(string apiMethod, Args args, CancellationToken? cancellationToken) where T : class + public Task Get(string apiMethod, Args args, CancellationToken cancellationToken) where T : class { SlackMethod = apiMethod; Args = args; return Task.FromResult(Activator.CreateInstance()); } - public Task Post(string apiMethod, Args args, HttpContent content, CancellationToken? cancellationToken) + public Task Post(string apiMethod, Args args, HttpContent content, CancellationToken cancellationToken) { SlackMethod = apiMethod; Args = args; return Task.FromResult(0); } - public Task Post(string apiMethod, Args args, CancellationToken? cancellationToken) => + public Task Post(string apiMethod, Args args, CancellationToken cancellationToken) => Post(apiMethod, args, cancellationToken); - public Task Post(string apiMethod, Args args, CancellationToken? cancellationToken) where T : class + public Task Post(string apiMethod, Args args, CancellationToken cancellationToken) where T : class { SlackMethod = apiMethod; Args = args; return Task.FromResult(Activator.CreateInstance()); } - public Task Post(string apiMethod, Args args, HttpContent content, CancellationToken? cancellationToken) where T : class + public Task Post(string apiMethod, Args args, HttpContent content, CancellationToken cancellationToken) where T : class { SlackMethod = apiMethod; Args = args; return Task.FromResult(Activator.CreateInstance()); } - public Task Respond(string responseUrl, IReadOnlyMessage message, CancellationToken? cancellationToken) => throw new NotImplementedException(); + public Task Respond(string responseUrl, IReadOnlyMessage message, CancellationToken cancellationToken) => throw new NotImplementedException(); - public Task PostToWebhook(string webhookUrl, Message message, CancellationToken? cancellationToken) => throw new NotImplementedException(); + public Task PostToWebhook(string webhookUrl, Message message, CancellationToken cancellationToken) => throw new NotImplementedException(); public ISlackApiClient WithAccessToken(string accessToken) => this; @@ -247,6 +247,6 @@ public Task Post(string apiMethod, Args args, HttpContent content, Cancell class FakeHttp : IHttp { - public Task Execute(HttpRequestMessage requestMessage, CancellationToken? cancellationToken = null) => Task.FromResult(Activator.CreateInstance()); + public Task Execute(HttpRequestMessage requestMessage, CancellationToken cancellationToken = default) => Task.FromResult(Activator.CreateInstance()); } } \ No newline at end of file diff --git a/SlackNet.Tests/Configuration/FactorySlackHandlerConfigurationTests.cs b/SlackNet.Tests/Configuration/FactorySlackHandlerConfigurationTests.cs index a79c769a..8a70e6c7 100644 --- a/SlackNet.Tests/Configuration/FactorySlackHandlerConfigurationTests.cs +++ b/SlackNet.Tests/Configuration/FactorySlackHandlerConfigurationTests.cs @@ -921,7 +921,7 @@ private THandler SecondRequestInstance() where THandler : TrackedClass protected class TestHttp : IHttp { - public Task Execute(HttpRequestMessage requestMessage, CancellationToken? cancellationToken = null) => throw new NotImplementedException(); + public Task Execute(HttpRequestMessage requestMessage, CancellationToken cancellationToken = default) => throw new NotImplementedException(); } protected class TestJsonSettings() : SlackJsonSettings(new JsonSerializerSettings()); @@ -999,21 +999,21 @@ protected class TestApiClient : ISlackApiClient public IUserProfileApi UserProfile { get; } public IViewsApi Views { get; } public IWorkflowsApi Workflows { get; } - public Task Get(string apiMethod, Dictionary args, CancellationToken? cancellationToken) => throw new NotImplementedException(); - public Task Get(string apiMethod, Dictionary args, CancellationToken? cancellationToken) where T : class => throw new NotImplementedException(); - public Task Post(string apiMethod, Dictionary args, CancellationToken? cancellationToken) => throw new NotImplementedException(); - public Task Post(string apiMethod, Dictionary args, CancellationToken? cancellationToken) where T : class => throw new NotImplementedException(); - public Task Post(string apiMethod, Dictionary args, HttpContent content, CancellationToken? cancellationToken) => throw new NotImplementedException(); - public Task Post(string apiMethod, Dictionary args, HttpContent content, CancellationToken? cancellationToken) where T : class => throw new NotImplementedException(); - public Task Respond(string responseUrl, IReadOnlyMessage message, CancellationToken? cancellationToken) => throw new NotImplementedException(); - public Task PostToWebhook(string webhookUrl, Message message, CancellationToken? cancellationToken) => throw new NotImplementedException(); + public Task Get(string apiMethod, Dictionary args, CancellationToken cancellationToken) => throw new NotImplementedException(); + public Task Get(string apiMethod, Dictionary args, CancellationToken cancellationToken) where T : class => throw new NotImplementedException(); + public Task Post(string apiMethod, Dictionary args, CancellationToken cancellationToken) => throw new NotImplementedException(); + public Task Post(string apiMethod, Dictionary args, CancellationToken cancellationToken) where T : class => throw new NotImplementedException(); + public Task Post(string apiMethod, Dictionary args, HttpContent content, CancellationToken cancellationToken) => throw new NotImplementedException(); + public Task Post(string apiMethod, Dictionary args, HttpContent content, CancellationToken cancellationToken) where T : class => throw new NotImplementedException(); + public Task Respond(string responseUrl, IReadOnlyMessage message, CancellationToken cancellationToken) => throw new NotImplementedException(); + public Task PostToWebhook(string webhookUrl, Message message, CancellationToken cancellationToken) => throw new NotImplementedException(); public ISlackApiClient WithAccessToken(string accessToken) => throw new NotImplementedException(); } protected class TestSocketModeClient : ISlackSocketModeClient { public void Dispose() => throw new NotImplementedException(); - public Task Connect(SocketModeConnectionOptions connectionOptions = null, CancellationToken? cancellationToken = null) => throw new NotImplementedException(); + public Task Connect(SocketModeConnectionOptions connectionOptions = null, CancellationToken cancellationToken = default) => throw new NotImplementedException(); public void Disconnect() { throw new NotImplementedException(); } public bool Connected { get; } } diff --git a/SlackNet.Tests/SlackBotTests.cs b/SlackNet.Tests/SlackBotTests.cs index 82def6b1..9d455530 100644 --- a/SlackNet.Tests/SlackBotTests.cs +++ b/SlackNet.Tests/SlackBotTests.cs @@ -80,7 +80,7 @@ public async Task AddOutgoingMiddleware_AppliedToOutgoingMessages() _sut.OnNext(new BotMessage { Text = "foo" }); - await _api.Chat.Received().PostMessage(Arg.Is(m => m.Text == "foo++"), Arg.Any()).ConfigureAwait(false); + await _api.Chat.Received().PostMessage(Arg.Is(m => m.Text == "foo++"), Arg.Any()).ConfigureAwait(false); } [Test] @@ -162,7 +162,7 @@ public async Task IncomingMessage_CanReply() _incomingMessages.OnNext(new MessageEvent()); await observer.Messages[0].Value.Value.ReplyWith("foo").ConfigureAwait(false); - await _api.Chat.Received().PostMessage(Arg.Is(m => m.Text == "foo"), Arg.Any()).ConfigureAwait(false); + await _api.Chat.Received().PostMessage(Arg.Is(m => m.Text == "foo"), Arg.Any()).ConfigureAwait(false); } [Test] @@ -372,7 +372,7 @@ public async Task Send_ReplyInChannel() await _sut.Send(new BotMessage { ReplyTo = slackMessage, CreateThread = false }).ConfigureAwait(false); - await _api.Chat.Received().PostMessage(Arg.Is(message => message.ThreadTs == null), Arg.Any()).ConfigureAwait(false); + await _api.Chat.Received().PostMessage(Arg.Is(message => message.ThreadTs == null), Arg.Any()).ConfigureAwait(false); } [Test] @@ -388,7 +388,7 @@ public async Task Send_ReplyInExistingThread() await _sut.Send(new BotMessage { ReplyTo = slackMessage, CreateThread = false }).ConfigureAwait(false); - await _api.Chat.Received().PostMessage(Arg.Is(message => message.ThreadTs == slackMessage.ThreadTs), Arg.Any()).ConfigureAwait(false); + await _api.Chat.Received().PostMessage(Arg.Is(message => message.ThreadTs == slackMessage.ThreadTs), Arg.Any()).ConfigureAwait(false); } [Test] @@ -403,7 +403,7 @@ public async Task Send_ReplyInNewThread() await _sut.Send(new BotMessage { ReplyTo = slackMessage, CreateThread = true }).ConfigureAwait(false); - await _api.Chat.Received().PostMessage(Arg.Is(message => message.ThreadTs == slackMessage.Ts), Arg.Any()).ConfigureAwait(false); + await _api.Chat.Received().PostMessage(Arg.Is(message => message.ThreadTs == slackMessage.Ts), Arg.Any()).ConfigureAwait(false); } [Test] @@ -419,7 +419,7 @@ public async Task Send_ReplyInDifferentConversation() await _sut.Send(new BotMessage { ReplyTo = slackMessage, Conversation = new Conversation { Id = "other_channel" } }).ConfigureAwait(false); - await _api.Chat.Received().PostMessage(Arg.Is(message => message.ThreadTs == null && message.Channel == "other_channel"), Arg.Any()).ConfigureAwait(false); + await _api.Chat.Received().PostMessage(Arg.Is(message => message.ThreadTs == null && message.Channel == "other_channel"), Arg.Any()).ConfigureAwait(false); } [Test] @@ -430,19 +430,19 @@ public async Task Send_MessagesLimitedTo1PerSecond() var sent1 = _sut.Send(new BotMessage { Text = "foo" }); var sent2 = _sut.Send(new BotMessage { Text = "bar" }); - await _api.Chat.Received().PostMessage(Arg.Is(message => message.Text == "foo"), Arg.Any()).ConfigureAwait(false); - await _api.Chat.DidNotReceive().PostMessage(Arg.Is(message => message.Text == "bar"), Arg.Any()).ConfigureAwait(false); + await _api.Chat.Received().PostMessage(Arg.Is(message => message.Text == "foo"), Arg.Any()).ConfigureAwait(false); + await _api.Chat.DidNotReceive().PostMessage(Arg.Is(message => message.Text == "bar"), Arg.Any()).ConfigureAwait(false); _scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks); - await _api.Chat.Received().PostMessage(Arg.Is(message => message.Text == "bar"), Arg.Any()).ConfigureAwait(false); + await _api.Chat.Received().PostMessage(Arg.Is(message => message.Text == "bar"), Arg.Any()).ConfigureAwait(false); } [Test] public async Task Send_PostMessageFails_ExceptionPropagated() { var expectedException = new SlackException(new ErrorResponse()); - _api.Chat.PostMessage(Arg.Any(), Arg.Any()).Throws(expectedException); + _api.Chat.PostMessage(Arg.Any(), Arg.Any()).Throws(expectedException); await Connect().ConfigureAwait(false); _sut.Send(new BotMessage()) diff --git a/SlackNet/Http.cs b/SlackNet/Http.cs index ed0b1aae..48d99fb7 100644 --- a/SlackNet/Http.cs +++ b/SlackNet/Http.cs @@ -9,14 +9,14 @@ namespace SlackNet; public interface IHttp { - Task Execute(HttpRequestMessage requestMessage, CancellationToken? cancellationToken = null); + Task Execute(HttpRequestMessage requestMessage, CancellationToken cancellationToken = default); } class Http(Func getHttpClient, SlackJsonSettings jsonSettings, ILogger logger) : IHttp { private readonly ILogger _log = logger.ForSource(); - public async Task Execute(HttpRequestMessage requestMessage, CancellationToken? cancellationToken = null) + public async Task Execute(HttpRequestMessage requestMessage, CancellationToken cancellationToken = default) { HttpResponseMessage response; @@ -26,7 +26,7 @@ public async Task Execute(HttpRequestMessage requestMessage, CancellationT try { - response = await getHttpClient().SendAsync(requestMessage, cancellationToken ?? CancellationToken.None).ConfigureAwait(false); + response = await getHttpClient().SendAsync(requestMessage, cancellationToken).ConfigureAwait(false); requestLog .WithContext("ResponseStatus", response.StatusCode) .WithContext("ResponseReason", response.ReasonPhrase) diff --git a/SlackNet/ReconnectingWebSocket.cs b/SlackNet/ReconnectingWebSocket.cs index 0bd7fff7..63a4bf95 100644 --- a/SlackNet/ReconnectingWebSocket.cs +++ b/SlackNet/ReconnectingWebSocket.cs @@ -32,9 +32,9 @@ public ReconnectingWebSocket(IWebSocketFactory webSocketFactory, IScheduler sche _messages = Subject.Synchronize(_messagesSubject); } - public async Task Connect(Func> getWebSocketUrl, CancellationToken? cancellationToken = null) + public async Task Connect(Func> getWebSocketUrl, CancellationToken cancellationToken = default) { - using var cancel = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken ?? CancellationToken.None, _disposed.Token); + using var cancel = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _disposed.Token); // Retry as long as not cancelled and Slack doesn't return an error response await Observable.FromAsync(() => ConnectInternal(getWebSocketUrl, cancel.Token), _scheduler) diff --git a/SlackNet/SlackApiClient.cs b/SlackNet/SlackApiClient.cs index 60c4c50c..ace5e44a 100644 --- a/SlackNet/SlackApiClient.cs +++ b/SlackNet/SlackApiClient.cs @@ -57,7 +57,7 @@ public interface ISlackApiClient /// Name of Slack method. /// Arguments to send to Slack. The "token" parameter will be filled in automatically. /// - Task Get(string apiMethod, Args args, CancellationToken? cancellationToken); + Task Get(string apiMethod, Args args, CancellationToken cancellationToken); /// /// Calls a Slack API method. @@ -66,7 +66,7 @@ public interface ISlackApiClient /// Name of Slack method. /// Arguments to send to Slack. The "token" parameter will be filled in automatically. /// - Task Get(string apiMethod, Args args, CancellationToken? cancellationToken) where T : class; + Task Get(string apiMethod, Args args, CancellationToken cancellationToken) where T : class; /// /// Calls a Slack API that requires POST content. @@ -74,7 +74,7 @@ public interface ISlackApiClient /// Name of Slack method. /// Arguments to send to Slack. Authorization headers will be added automatically. /// - Task Post(string apiMethod, Args args, CancellationToken? cancellationToken); + Task Post(string apiMethod, Args args, CancellationToken cancellationToken); /// /// Calls a Slack API that requires POST content. @@ -83,7 +83,7 @@ public interface ISlackApiClient /// Name of Slack method. /// Arguments to send to Slack. Authorization headers will be added automatically. /// - Task Post(string apiMethod, Args args, CancellationToken? cancellationToken) where T : class; + Task Post(string apiMethod, Args args, CancellationToken cancellationToken) where T : class; /// /// Calls a Slack API that requires POST content. @@ -92,7 +92,7 @@ public interface ISlackApiClient /// Arguments to send to Slack. The "token" parameter will be filled in automatically. /// POST body content. Should be either or . /// - Task Post(string apiMethod, Args args, HttpContent content, CancellationToken? cancellationToken); + Task Post(string apiMethod, Args args, HttpContent content, CancellationToken cancellationToken); /// /// Calls a Slack API that requires POST content. @@ -102,7 +102,7 @@ public interface ISlackApiClient /// Arguments to send to Slack. The "token" parameter will be filled in automatically. /// POST body content. Should be either or . /// - Task Post(string apiMethod, Args args, HttpContent content, CancellationToken? cancellationToken) where T : class; + Task Post(string apiMethod, Args args, HttpContent content, CancellationToken cancellationToken) where T : class; /// /// Posts a message to a response URL provided by e.g. or . @@ -110,7 +110,7 @@ public interface ISlackApiClient /// A temporary webhook that can be used to send messages in response to interactions. /// The message to respond with. /// - Task Respond(string responseUrl, IReadOnlyMessage message, CancellationToken? cancellationToken); + Task Respond(string responseUrl, IReadOnlyMessage message, CancellationToken cancellationToken); /// /// Posts a message to an incoming webhook. @@ -119,7 +119,7 @@ public interface ISlackApiClient /// The message to send to the incoming webhook. /// /// See the Slack documentation for more information. - Task PostToWebhook(string webhookUrl, Message message, CancellationToken? cancellationToken = null); + Task PostToWebhook(string webhookUrl, Message message, CancellationToken cancellationToken = default); /// /// Returns a copy of the client using a different access token. @@ -193,33 +193,33 @@ public ISlackApiClient WithAccessToken(string accessToken) => public IViewsApi Views => new ViewsApi(this); public IWorkflowsApi Workflows => new WorkflowsApi(this); - public Task Get(string apiMethod, Args args, CancellationToken? cancellationToken) => + public Task Get(string apiMethod, Args args, CancellationToken cancellationToken) => Get(apiMethod, args, cancellationToken); - public Task Get(string apiMethod, Args args, CancellationToken? cancellationToken) where T : class => + public Task Get(string apiMethod, Args args, CancellationToken cancellationToken) where T : class => WebApiRequest(() => new HttpRequestMessage(HttpMethod.Get, Url(apiMethod, args)), cancellationToken); - public Task Post(string apiMethod, Args args, CancellationToken? cancellationToken) => + public Task Post(string apiMethod, Args args, CancellationToken cancellationToken) => Post(apiMethod, args, cancellationToken); - public Task Post(string apiMethod, Args args, CancellationToken? cancellationToken) where T : class => + public Task Post(string apiMethod, Args args, CancellationToken cancellationToken) where T : class => Post(Url(apiMethod), (object)StripNullArgs(args), cancellationToken); - public Task Post(string apiMethod, Args args, HttpContent content, CancellationToken? cancellationToken) => + public Task Post(string apiMethod, Args args, HttpContent content, CancellationToken cancellationToken) => Post(apiMethod, args, content, cancellationToken); - public Task Post(string apiMethod, Args args, HttpContent content, CancellationToken? cancellationToken) where T : class => + public Task Post(string apiMethod, Args args, HttpContent content, CancellationToken cancellationToken) where T : class => WebApiRequest(() => new HttpRequestMessage(HttpMethod.Post, Url(apiMethod, args)) { Content = content }, cancellationToken); - public Task Respond(string responseUrl, IReadOnlyMessage message, CancellationToken? cancellationToken) => + public Task Respond(string responseUrl, IReadOnlyMessage message, CancellationToken cancellationToken) => Post(responseUrl, message, cancellationToken); - public Task PostToWebhook(string webhookUrl, Message message, CancellationToken? cancellationToken = null) => + public Task PostToWebhook(string webhookUrl, Message message, CancellationToken cancellationToken = default) => string.IsNullOrEmpty(_token) ? Post(webhookUrl, message, cancellationToken) : WithAccessToken(string.Empty).PostToWebhook(webhookUrl, message, cancellationToken); - private Task Post(string requestUri, object body, CancellationToken? cancellationToken) where T : class => + private Task Post(string requestUri, object body, CancellationToken cancellationToken) where T : class => WebApiRequest(() => new HttpRequestMessage(HttpMethod.Post, requestUri) { Content = new StringContent(JsonConvert.SerializeObject(body, _jsonSettings.SerializerSettings), Encoding.UTF8, "application/json") @@ -229,7 +229,7 @@ private Task Post(string requestUri, object body, CancellationToken? cance private string Url(string apiMethod, Args args = null) => _urlBuilder.Url(apiMethod, args ?? new Args()); - private async Task WebApiRequest(Func createRequest, CancellationToken? cancellationToken) where T : class + private async Task WebApiRequest(Func createRequest, CancellationToken cancellationToken) where T : class { while (true) { @@ -239,14 +239,14 @@ private async Task WebApiRequest(Func createRequest, C if (!string.IsNullOrEmpty(_token)) // Token is cleared by methods that don't require authentication (e.g. OAuthV2Api.Access) request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _token); - var response = await _http.Execute(request, cancellationToken ?? CancellationToken.None).ConfigureAwait(false) + var response = await _http.Execute(request, cancellationToken).ConfigureAwait(false) ?? new WebApiResponse { Ok = true }; return Deserialize(response); } catch (SlackRateLimitException e) when (!DisableRetryOnRateLimit) { - await Task.Delay(e.RetryAfter ?? TimeSpan.FromSeconds(1), cancellationToken ?? CancellationToken.None).ConfigureAwait(false); + await Task.Delay(e.RetryAfter ?? TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); } } } diff --git a/SlackNet/SlackApiClientExtensions.cs b/SlackNet/SlackApiClientExtensions.cs index 4ddb6ed6..0656f80b 100644 --- a/SlackNet/SlackApiClientExtensions.cs +++ b/SlackNet/SlackApiClientExtensions.cs @@ -6,9 +6,9 @@ namespace SlackNet; public static class SlackApiClientExtensions { - public static Task Respond(this ISlackApiClient client, InteractionRequest request, MessageResponse response, CancellationToken? cancellationToken = null) => + public static Task Respond(this ISlackApiClient client, InteractionRequest request, MessageResponse response, CancellationToken cancellationToken = default) => client.Respond(request.ResponseUrl, new MessageUpdateResponse(response), cancellationToken); - public static Task Respond(this ISlackApiClient client, SlashCommand slashCommand, SlashCommandResponse response, CancellationToken? cancellationToken = null) => + public static Task Respond(this ISlackApiClient client, SlashCommand slashCommand, SlashCommandResponse response, CancellationToken cancellationToken = default) => client.Respond(slashCommand.ResponseUrl, new SlashCommandMessageResponse(response), cancellationToken); } \ No newline at end of file diff --git a/SlackNet/SlackRtmClient.cs b/SlackNet/SlackRtmClient.cs index c91b0038..0adb06d5 100644 --- a/SlackNet/SlackRtmClient.cs +++ b/SlackNet/SlackRtmClient.cs @@ -40,7 +40,7 @@ public interface ISlackRtmClient : IDisposable /// Only deliver presence events when requested by subscription. /// Group presence change notices in events when possible. /// - Task Connect(bool batchPresenceAware = false, bool manualPresenceSubscription = false, CancellationToken? cancellationToken = null); + Task Connect(bool batchPresenceAware = false, bool manualPresenceSubscription = false, CancellationToken cancellationToken = default); /// /// Send a simple message. For more complicated messages, use instead. @@ -123,7 +123,7 @@ private static IObservable DeserializeEvents(ReconnectingWebSocket webSoc /// Only deliver presence events when requested by subscription. /// Group presence change notices in events when possible. /// - public async Task Connect(bool batchPresenceAware = false, bool manualPresenceSubscription = false, CancellationToken? cancellationToken = null) + public async Task Connect(bool batchPresenceAware = false, bool manualPresenceSubscription = false, CancellationToken cancellationToken = default) { if (Connected) throw new InvalidOperationException("Already connecting or connected"); diff --git a/SlackNet/SlackSocketModeClient.cs b/SlackNet/SlackSocketModeClient.cs index 64a4bd44..4db83df0 100644 --- a/SlackNet/SlackSocketModeClient.cs +++ b/SlackNet/SlackSocketModeClient.cs @@ -18,7 +18,7 @@ namespace SlackNet; public interface ISlackSocketModeClient : IDisposable { - Task Connect(SocketModeConnectionOptions connectionOptions = null, CancellationToken? cancellationToken = null); + Task Connect(SocketModeConnectionOptions connectionOptions = null, CancellationToken cancellationToken = default); void Disconnect(); @@ -57,7 +57,7 @@ public SlackSocketModeClient( .Subscribe(); } - public Task Connect(SocketModeConnectionOptions connectionOptions = null, CancellationToken? cancellationToken = null) => + public Task Connect(SocketModeConnectionOptions connectionOptions = null, CancellationToken cancellationToken = default) => _socket.Connect(connectionOptions, cancellationToken); public void Disconnect() => _socket.Disconnect(); diff --git a/SlackNet/SocketMode/CoreSocketModeClient.cs b/SlackNet/SocketMode/CoreSocketModeClient.cs index 48ae2821..e2963388 100644 --- a/SlackNet/SocketMode/CoreSocketModeClient.cs +++ b/SlackNet/SocketMode/CoreSocketModeClient.cs @@ -14,7 +14,7 @@ namespace SlackNet.SocketMode; public interface ICoreSocketModeClient : IDisposable { - Task Connect(SocketModeConnectionOptions? connectionOptions = null, CancellationToken? cancellationToken = null); + Task Connect(SocketModeConnectionOptions? connectionOptions = null, CancellationToken cancellationToken = default); void Disconnect(); /// @@ -110,7 +110,7 @@ public CoreSocketModeClient( } } - public async Task Connect(SocketModeConnectionOptions? connectionOptions = null, CancellationToken? cancellationToken = null) + public async Task Connect(SocketModeConnectionOptions? connectionOptions = null, CancellationToken cancellationToken = default) { if (Connected) throw new InvalidOperationException("Already connecting or connected"); @@ -123,7 +123,7 @@ public async Task Connect(SocketModeConnectionOptions? connectionOptions = null, Disconnect(); _disconnectCancellation = new CancellationTokenSource(); - _connectionCancelled = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken ?? CancellationToken.None, _disconnectCancellation.Token); + _connectionCancelled = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _disconnectCancellation.Token); _webSockets = Enumerable.Range(0, connectionOptions.NumberOfConnections) .Select(i => new ReconnectingWebSocket(_webSocketFactory, _scheduler, _log, i)) diff --git a/SlackNet/WebApi/ApiApi.cs b/SlackNet/WebApi/ApiApi.cs index dacc7e1b..822b08fa 100644 --- a/SlackNet/WebApi/ApiApi.cs +++ b/SlackNet/WebApi/ApiApi.cs @@ -18,7 +18,7 @@ public interface IApiApi /// The response includes any supplied arguments. /// If called with an error argument an error response is returned. /// - Task> Test(string error, Args args, CancellationToken? cancellationToken = null); + Task> Test(string error, Args args, CancellationToken cancellationToken = default); } public class ApiApi : IApiApi @@ -26,7 +26,7 @@ public class ApiApi : IApiApi private readonly ISlackApiClient _client; public ApiApi(ISlackApiClient client) => _client = client; - public async Task> Test(string error, Args args, CancellationToken? cancellationToken = null) + public async Task> Test(string error, Args args, CancellationToken cancellationToken = default) { var query = new Args(args) { ["error"] = error }; return (await _client.Post("api.test", query, cancellationToken).ConfigureAwait(false)).Args; diff --git a/SlackNet/WebApi/AppsConnectionsApi.cs b/SlackNet/WebApi/AppsConnectionsApi.cs index 088725c1..7b6285cc 100644 --- a/SlackNet/WebApi/AppsConnectionsApi.cs +++ b/SlackNet/WebApi/AppsConnectionsApi.cs @@ -13,7 +13,7 @@ public interface IAppsConnectionsApi /// /// See the Slack documentation for more information. /// - Task Open(CancellationToken? cancellationToken = null); + Task Open(CancellationToken cancellationToken = default); } public class AppsConnectionsApi : IAppsConnectionsApi @@ -21,6 +21,6 @@ public class AppsConnectionsApi : IAppsConnectionsApi private readonly ISlackApiClient _client; public AppsConnectionsApi(ISlackApiClient client) => _client = client; - public Task Open(CancellationToken? cancellationToken = null) => + public Task Open(CancellationToken cancellationToken = default) => _client.Post("apps.connections.open", new Args(), cancellationToken); } \ No newline at end of file diff --git a/SlackNet/WebApi/AppsEventAuthorizationsApi.cs b/SlackNet/WebApi/AppsEventAuthorizationsApi.cs index a170f001..0ef19cac 100644 --- a/SlackNet/WebApi/AppsEventAuthorizationsApi.cs +++ b/SlackNet/WebApi/AppsEventAuthorizationsApi.cs @@ -22,7 +22,7 @@ Task List( string eventContext, int limit = 100, string cursor = null, - CancellationToken? cancellationToken = null); + CancellationToken cancellationToken = default); } public class AppsEventAuthorizationsApi : IAppsEventAuthorizationsApi @@ -34,7 +34,7 @@ public Task List( string eventContext, int limit = 100, string cursor = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => _client.Post("apps.event.authorizations.list", new Args { diff --git a/SlackNet/WebApi/AuthApi.cs b/SlackNet/WebApi/AuthApi.cs index aa691752..7827c985 100644 --- a/SlackNet/WebApi/AuthApi.cs +++ b/SlackNet/WebApi/AuthApi.cs @@ -14,14 +14,14 @@ public interface IAuthApi /// Setting this parameter to True triggers a testing mode where the specified token will not actually be revoked. /// /// Whether or not the access token was revoked. - Task Revoke(bool test, CancellationToken? cancellationToken); + Task Revoke(bool test, CancellationToken cancellationToken); /// /// Checks authentication and tells you who you are. /// /// See the Slack documentation for more information. /// - Task Test(CancellationToken? cancellationToken = null); + Task Test(CancellationToken cancellationToken = default); } public class AuthApi : IAuthApi @@ -29,9 +29,9 @@ public class AuthApi : IAuthApi private readonly ISlackApiClient _client; public AuthApi(ISlackApiClient client) => _client = client; - public async Task Revoke(bool test, CancellationToken? cancellationToken = null) => + public async Task Revoke(bool test, CancellationToken cancellationToken = default) => (await _client.Get("auth.revoke", new Args { { "test", test } }, cancellationToken).ConfigureAwait(false)).Revoked; - public Task Test(CancellationToken? cancellationToken = null) => + public Task Test(CancellationToken cancellationToken = default) => _client.Post("auth.test", new Args(), cancellationToken); } \ No newline at end of file diff --git a/SlackNet/WebApi/BookmarksApi.cs b/SlackNet/WebApi/BookmarksApi.cs index f96d2c22..87a50731 100644 --- a/SlackNet/WebApi/BookmarksApi.cs +++ b/SlackNet/WebApi/BookmarksApi.cs @@ -26,7 +26,7 @@ Task Add( string entityId = null, string link = null, string parentId = null, - CancellationToken? cancellationToken = null); + CancellationToken cancellationToken = default); /// /// Edit bookmark. @@ -44,7 +44,7 @@ Task Edit( string emoji = null, string link = null, string title = null, - CancellationToken? cancellationToken = null); + CancellationToken cancellationToken = default); /// /// List bookmarks for the channel. @@ -52,7 +52,7 @@ Task Edit( /// See the Slack documentation for more information. /// Channel to list bookmarks in. /// - Task List(string channelId, CancellationToken? cancellationToken = null); + Task List(string channelId, CancellationToken cancellationToken = default); /// /// Remove bookmark from the channel. @@ -61,7 +61,7 @@ Task Edit( /// Bookmark to remove. /// Channel to remove bookmark from. /// - Task Remove(string bookmarkId, string channelId, CancellationToken? cancellationToken = null); + Task Remove(string bookmarkId, string channelId, CancellationToken cancellationToken = default); } public class BookmarksApi(ISlackApiClient client) : IBookmarksApi @@ -74,7 +74,7 @@ public async Task Add( string entityId = null, string link = null, string parentId = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => (await client.Post("bookmarks.add", new Args { @@ -94,7 +94,7 @@ public async Task Edit( string emoji = null, string link = null, string title = null, - CancellationToken? cancellationToken = null) => + CancellationToken cancellationToken = default) => (await client.Post("bookmarks.add", new Args { { "bookmark_id", bookmarkId }, @@ -105,10 +105,10 @@ public async Task Edit( }, cancellationToken).ConfigureAwait(false)) .Bookmark; - public Task List(string channelId, CancellationToken? cancellationToken = null) => + public Task List(string channelId, CancellationToken cancellationToken = default) => client.Post("bookmarks.list", new Args { { "channel_id", channelId } }, cancellationToken); - public Task Remove(string bookmarkId, string channelId, CancellationToken? cancellationToken = null) => + public Task Remove(string bookmarkId, string channelId, CancellationToken cancellationToken = default) => client.Post("bookmarks.remove", new Args { { "bookmark_id", bookmarkId }, diff --git a/SlackNet/WebApi/BotsApi.cs b/SlackNet/WebApi/BotsApi.cs index a15a67c6..8869b008 100644 --- a/SlackNet/WebApi/BotsApi.cs +++ b/SlackNet/WebApi/BotsApi.cs @@ -14,7 +14,7 @@ public interface IBotsApi /// See the Slack documentation for more information. /// Bot user to get info on. /// - Task Info(string botId, CancellationToken? cancellationToken = null); + Task Info(string botId, CancellationToken cancellationToken = default); } public class BotsApi : IBotsApi @@ -22,6 +22,6 @@ public class BotsApi : IBotsApi private readonly ISlackApiClient _client; public BotsApi(ISlackApiClient client) => _client = client; - public async Task Info(string botId, CancellationToken? cancellationToken = null) => + public async Task Info(string botId, CancellationToken cancellationToken = default) => (await _client.Get("bots.info", new Args { { "bot", botId } }, cancellationToken).ConfigureAwait(false)).Bot; } \ No newline at end of file diff --git a/SlackNet/WebApi/CallParticipantsApi.cs b/SlackNet/WebApi/CallParticipantsApi.cs index 8a5a8ecb..7b6598cb 100644 --- a/SlackNet/WebApi/CallParticipantsApi.cs +++ b/SlackNet/WebApi/CallParticipantsApi.cs @@ -14,7 +14,7 @@ public interface ICallParticipantsApi /// returned by the method. /// The list of users to add as participants in the Call. /// - Task Add(string id, IEnumerable users, CancellationToken? cancellationToken = null); + Task Add(string id, IEnumerable users, CancellationToken cancellationToken = default); /// /// Registers participants removed from a Call. @@ -23,7 +23,7 @@ public interface ICallParticipantsApi /// returned by the method. /// The list of users to remove as participants in the Call. /// - Task Remove(string id, IEnumerable users, CancellationToken? cancellationToken = null); + Task Remove(string id, IEnumerable users, CancellationToken cancellationToken = default); } public class CallParticipantsApi : ICallParticipantsApi @@ -31,14 +31,14 @@ public class CallParticipantsApi : ICallParticipantsApi private readonly ISlackApiClient _client; public CallParticipantsApi(ISlackApiClient client) => _client = client; - public Task Add(string id, IEnumerable users, CancellationToken? cancellationToken = null) => + public Task Add(string id, IEnumerable users, CancellationToken cancellationToken = default) => _client.Post("calls.participants.add", new Args { { "id", id }, { "users", users } }, cancellationToken); - public Task Remove(string id, IEnumerable users, CancellationToken? cancellationToken = null) => + public Task Remove(string id, IEnumerable users, CancellationToken cancellationToken = default) => _client.Post("calls.participants.remove", new Args { { "id", id }, diff --git a/SlackNet/WebApi/CallsApi.cs b/SlackNet/WebApi/CallsApi.cs index 0c252da7..b6a09101 100644 --- a/SlackNet/WebApi/CallsApi.cs +++ b/SlackNet/WebApi/CallsApi.cs @@ -30,7 +30,7 @@ Task Add( string externalDisplayId = null, string title = null, IEnumerable users = null, - CancellationToken? cancellationToken = null); + CancellationToken cancellationToken = default); /// /// Ends a Call. @@ -39,7 +39,7 @@ Task Add( /// returned when registering the call using the method. /// Call duration. /// - Task End(string id, TimeSpan? duration = null, CancellationToken? cancellationToken = null); + Task End(string id, TimeSpan? duration = null, CancellationToken cancellationToken = default); /// /// Returns information about a Call. @@ -47,7 +47,7 @@ Task Add( /// See the Slack documentation for more information. /// returned by the method. /// - Task Info(string id, CancellationToken? cancellationToken = null); + Task Info(string id, CancellationToken cancellationToken = default); /// /// Updates information about a Call. @@ -58,7 +58,7 @@ Task Add( /// The URL required for a client to join the Call. /// The name of the Call. /// - Task Update(string id, string desktopAppJoinUrl = null, string joinUrl = null, string title = null, CancellationToken? cancellationToken = null); + Task Update(string id, string desktopAppJoinUrl = null, string joinUrl = null, string title = null, CancellationToken cancellationToken = default); } public class CallsApi(ISlackApiClient client) : ICallsApi @@ -72,7 +72,7 @@ public async Task Add( string externalDisplayId = null, string title = null, IEnumerable users = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => (await client.Post("calls.add", new Args { @@ -87,17 +87,17 @@ public async Task Add( }, cancellationToken).ConfigureAwait(false)) .Call; - public Task End(string id, TimeSpan? duration = null, CancellationToken? cancellationToken = null) => + public Task End(string id, TimeSpan? duration = null, CancellationToken cancellationToken = default) => client.Post("calls.end", new Args { { "id", id }, { "duration", duration?.TotalSeconds } }, cancellationToken); - public async Task Info(string id, CancellationToken? cancellationToken = null) => + public async Task Info(string id, CancellationToken cancellationToken = default) => (await client.Post("calls.info", new Args { { "id", id } }, cancellationToken).ConfigureAwait(false)).Call; - public async Task Update(string id, string desktopAppJoinUrl = null, string joinUrl = null, string title = null, CancellationToken? cancellationToken = null) => + public async Task Update(string id, string desktopAppJoinUrl = null, string joinUrl = null, string title = null, CancellationToken cancellationToken = default) => (await client.Post("calls.update", new Args { { "id", id }, diff --git a/SlackNet/WebApi/ChatApi.cs b/SlackNet/WebApi/ChatApi.cs index e5f49e50..6fef8f93 100644 --- a/SlackNet/WebApi/ChatApi.cs +++ b/SlackNet/WebApi/ChatApi.cs @@ -18,7 +18,7 @@ public interface IChatApi /// Channel containing the message to be deleted. /// Pass True to delete the message as the authed user. Bot users in this context are considered authed users. /// - Task Delete(string ts, string channelId, bool asUser = false, CancellationToken? cancellationToken = null); + Task Delete(string ts, string channelId, bool asUser = false, CancellationToken cancellationToken = default); /// /// Sends a /me message to a channel from the calling user. @@ -27,7 +27,7 @@ public interface IChatApi /// Channel to send message to. Can be a public channel, private group or IM channel. Can be an encoded ID, or a name. /// Text of the message to send. /// - Task MeMessage(string channel, string text, CancellationToken? cancellationToken = null); + Task MeMessage(string channel, string text, CancellationToken cancellationToken = default); /// /// Posts a message to a public channel, private channel, or direct message/IM channel. @@ -35,7 +35,7 @@ public interface IChatApi /// See the Slack documentation for more information. /// The message to post /// - Task PostMessage(Message message, CancellationToken? cancellationToken = null); + Task PostMessage(Message message, CancellationToken cancellationToken = default); /// /// Schedules a message for delivery to a public channel, private channel, or direct message/IM channel at a specified time in the future. @@ -44,7 +44,7 @@ public interface IChatApi /// The message to post. /// Time in the future to send the message. /// - Task ScheduleMessage(Message message, DateTime postAt, CancellationToken? cancellationToken = null); + Task ScheduleMessage(Message message, DateTime postAt, CancellationToken cancellationToken = default); /// /// Deletes a scheduled message. @@ -54,7 +54,7 @@ public interface IChatApi /// The channel ID of the scheduled message. /// Pass True to delete the message as the authed user. Bot users in this context are considered authed users. /// - Task DeleteScheduledMessage(string messageId, string channelId, bool? asUser = null, CancellationToken? cancellationToken = null); + Task DeleteScheduledMessage(string messageId, string channelId, bool? asUser = null, CancellationToken cancellationToken = default); /// /// Sends an ephemeral message to a user in a channel. @@ -63,7 +63,7 @@ public interface IChatApi /// ID of the user who will receive the ephemeral message. The user should be in the channel specified by the channel argument. /// The message to post. Not all message properties are supported by PostEphemeral. /// - Task PostEphemeral(string userId, Message message, CancellationToken? cancellationToken = null); + Task PostEphemeral(string userId, Message message, CancellationToken cancellationToken = default); /// /// Attaches Slack app unfurl behavior to a specified and relevant message. @@ -94,7 +94,7 @@ Task Unfurl( IEnumerable userAuthBlocks = null, string userAuthMessage = null, string userAuthUrl = null, - CancellationToken? cancellationToken = null); + CancellationToken cancellationToken = default); /// /// Attaches Slack app unfurl behavior to a specified and relevant message. @@ -125,7 +125,7 @@ Task Unfurl( IEnumerable userAuthBlocks = null, string userAuthMessage = null, string userAuthUrl = null, - CancellationToken? cancellationToken = null); + CancellationToken cancellationToken = default); /// /// Updates a message in a channel. @@ -133,7 +133,7 @@ Task Unfurl( /// Message to update. /// /// See the Slack documentation for more information. - Task Update(MessageUpdate messageUpdate, CancellationToken? cancellationToken = null); + Task Update(MessageUpdate messageUpdate, CancellationToken cancellationToken = default); /// /// Retrieve a permalink URL for a specific extant message. @@ -142,7 +142,7 @@ Task Unfurl( /// The ID of the conversation or channel containing the message. /// A message's timestamp, uniquely identifying it within a channel. /// - Task GetPermalink(string channelId, string messageTs, CancellationToken? cancellationToken = null); + Task GetPermalink(string channelId, string messageTs, CancellationToken cancellationToken = default); } public class ChatApi : IChatApi @@ -156,7 +156,7 @@ public ChatApi(ISlackApiClient client, SlackJsonSettings jsonSettings) _jsonSettings = jsonSettings; } - public Task Delete(string ts, string channelId, bool asUser = false, CancellationToken? cancellationToken = null) => + public Task Delete(string ts, string channelId, bool asUser = false, CancellationToken cancellationToken = default) => _client.Post("chat.delete", new Args { { "ts", ts }, @@ -164,25 +164,25 @@ public Task Delete(string ts, string channelId, bool asUser = { "as_user", asUser } }, cancellationToken); - public Task GetPermalink(string channelId, string messageTs, CancellationToken? cancellationToken = null) => + public Task GetPermalink(string channelId, string messageTs, CancellationToken cancellationToken = default) => _client.Get("chat.getPermalink", new Args { { "channel", channelId }, { "message_ts", messageTs } }, cancellationToken); - public Task MeMessage(string channel, string text, CancellationToken? cancellationToken = null) => + public Task MeMessage(string channel, string text, CancellationToken cancellationToken = default) => _client.Post("chat.meMessage", new Args { { "channel", channel }, { "text", text } }, cancellationToken); - public Task PostMessage(Message message, CancellationToken? cancellationToken = null) => + public Task PostMessage(Message message, CancellationToken cancellationToken = default) => _client.Post("chat.postMessage", PopulateMessageArgs(message, new Args()), cancellationToken); - public Task ScheduleMessage(Message message, DateTime postAt, CancellationToken? cancellationToken = null) => + public Task ScheduleMessage(Message message, DateTime postAt, CancellationToken cancellationToken = default) => _client.Post("chat.scheduleMessage", PopulateMessageArgs(message, new Args { { "post_at", postAt.ToTimestamp() } @@ -209,7 +209,7 @@ private Args PopulateMessageArgs(Message message, Args args) return args; } - public Task DeleteScheduledMessage(string messageId, string channelId, bool? asUser = null, CancellationToken? cancellationToken = null) => + public Task DeleteScheduledMessage(string messageId, string channelId, bool? asUser = null, CancellationToken cancellationToken = default) => _client.Post("chat.deleteScheduledMessage", new Args { { "scheduled_message_id", messageId }, @@ -218,7 +218,7 @@ public Task DeleteScheduledMessage(string messageId, string channelId, bool? asU }, cancellationToken); - public Task PostEphemeral(string userId, Message message, CancellationToken? cancellationToken = null) => + public Task PostEphemeral(string userId, Message message, CancellationToken cancellationToken = default) => _client.Post("chat.postEphemeral", new Args { { "channel", message.Channel }, @@ -241,7 +241,7 @@ public Task Unfurl( IEnumerable userAuthBlocks = null, string userAuthMessage = null, string userAuthUrl = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => _client.Post("chat.unfurl", new Args { @@ -262,7 +262,7 @@ public Task Unfurl( IEnumerable userAuthBlocks = null, string userAuthMessage = null, string userAuthUrl = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => _client.Post("chat.unfurl", new Args { @@ -275,7 +275,7 @@ public Task Unfurl( { "user_auth_url", userAuthUrl } }, cancellationToken); - public Task Update(MessageUpdate messageUpdate, CancellationToken? cancellationToken = null) => + public Task Update(MessageUpdate messageUpdate, CancellationToken cancellationToken = default) => _client.Post("chat.update", new Args { { "ts", messageUpdate.Ts }, diff --git a/SlackNet/WebApi/ConversationsApi.cs b/SlackNet/WebApi/ConversationsApi.cs index 24015a8c..0450a5dd 100644 --- a/SlackNet/WebApi/ConversationsApi.cs +++ b/SlackNet/WebApi/ConversationsApi.cs @@ -18,7 +18,7 @@ public interface IConversationsApi /// Whether the channel should be private. /// The ID of the workspace to accept the channel in. If an org-level token is used to call this method, the argument is required. /// - Task AcceptSharedInvite(string channelName, string inviteId = null, string channelId = null, bool freeTrialAccepted = false, bool isPrivate = false, string teamId = null, CancellationToken? cancellationToken = null); + Task AcceptSharedInvite(string channelName, string inviteId = null, string channelId = null, bool freeTrialAccepted = false, bool isPrivate = false, string teamId = null, CancellationToken cancellationToken = default); /// /// Approves an invitation to a Slack Connect channel. @@ -27,7 +27,7 @@ public interface IConversationsApi /// ID of the shared channel invite to approve. Subscribe to the event to receive IDs of Slack Connect channel invites that have been accepted and are awaiting approval. /// The team or enterprise id of the other party involved in the invitation you are approving. /// - Task ApproveSharedInvite(string inviteId, string targetTeam = null, CancellationToken? cancellationToken = null); + Task ApproveSharedInvite(string inviteId, string targetTeam = null, CancellationToken cancellationToken = default); /// /// Archives a conversation. Not all types of conversations can be archived. @@ -35,7 +35,7 @@ public interface IConversationsApi /// See the Slack documentation for more information. /// ID of conversation to archive. /// - Task Archive(string channelId, CancellationToken? cancellationToken = null); + Task Archive(string channelId, CancellationToken cancellationToken = default); /// /// Closes a direct message or multi-person direct message. @@ -43,7 +43,7 @@ public interface IConversationsApi /// See the Slack documentation for more information. /// Conversation to close. /// - Task Close(string channelId, CancellationToken? cancellationToken = null); + Task Close(string channelId, CancellationToken cancellationToken = default); /// /// Initiates a public or private channel-based conversation. @@ -54,7 +54,7 @@ public interface IConversationsApi /// Create a private channel instead of a public one. /// Encoded team id to create the channel in, required if org token is used /// - Task Create(string name, bool isPrivate, string teamId = null, CancellationToken? cancellationToken = null); + Task Create(string name, bool isPrivate, string teamId = null, CancellationToken cancellationToken = default); /// /// Declines a Slack Connect channel invite. @@ -63,7 +63,7 @@ public interface IConversationsApi /// ID of the Slack Connect invite to decline. Subscribe to the event to receive IDs of Slack Connect channel invites that have been accepted and are awaiting approval. /// The team or enterprise id of the other party involved in the invitation you are declining. /// - Task DeclineSharedInvite(string inviteId, string targetTeam = null, CancellationToken? cancellationToken = null); + Task DeclineSharedInvite(string inviteId, string targetTeam = null, CancellationToken cancellationToken = default); /// /// Fetches a conversation's history of messages and events. @@ -81,7 +81,7 @@ public interface IConversationsApi /// Default value fetches the first "page" of the collection. /// /// - Task History(string channelId, string latestTs = null, string oldestTs = null, bool inclusive = false, int limit = 100, bool includeAllMetadata = false, string cursor = null, CancellationToken? cancellationToken = null); + Task History(string channelId, string latestTs = null, string oldestTs = null, bool inclusive = false, int limit = 100, bool includeAllMetadata = false, string cursor = null, CancellationToken cancellationToken = default); /// /// Retrieve information about a conversation. @@ -91,7 +91,7 @@ public interface IConversationsApi /// Set this to true to receive the locale for this conversation. /// /// - Task Info(string channelId, bool includeLocale = false, bool includeNumMembers = false, CancellationToken? cancellationToken = null); + Task Info(string channelId, bool includeLocale = false, bool includeNumMembers = false, CancellationToken cancellationToken = default); /// /// Invites users to a channel. @@ -100,7 +100,7 @@ public interface IConversationsApi /// The ID of the public or private channel to invite user(s) to. /// A comma separated list of user IDs. Up to 30 users may be listed. /// - Task Invite(string channelId, IEnumerable userIds, CancellationToken? cancellationToken = null); + Task Invite(string channelId, IEnumerable userIds, CancellationToken cancellationToken = default); /// /// Sends an invitation to a Slack Connect channel. @@ -111,7 +111,7 @@ public interface IConversationsApi /// User IDs to receive this invite. Either or must be provided. /// Whether invite is to an external limited member. /// - Task InviteShared(string channelId, IEnumerable emails, IEnumerable userIds, bool externalLimited = true, CancellationToken? cancellationToken = null); + Task InviteShared(string channelId, IEnumerable emails, IEnumerable userIds, bool externalLimited = true, CancellationToken cancellationToken = default); /// /// Joins an existing conversation. @@ -119,7 +119,7 @@ public interface IConversationsApi /// See the Slack documentation for more information. /// ID of conversation to join. /// - Task Join(string channelId, CancellationToken? cancellationToken = null); + Task Join(string channelId, CancellationToken cancellationToken = default); /// /// Removes a user from a conversation. @@ -128,7 +128,7 @@ public interface IConversationsApi /// ID of conversation to remove user from. /// User ID to be removed. /// - Task Kick(string channelId, string userId, CancellationToken? cancellationToken = null); + Task Kick(string channelId, string userId, CancellationToken cancellationToken = default); /// /// Leaves a conversation. @@ -136,7 +136,7 @@ public interface IConversationsApi /// See the Slack documentation for more information. /// Conversation to leave. /// - Task Leave(string channelId, CancellationToken? cancellationToken = null); + Task Leave(string channelId, CancellationToken cancellationToken = default); /// /// Lists all channels in a Slack team. @@ -152,7 +152,7 @@ public interface IConversationsApi /// /// encoded team id to list channels in, required if token belongs to org-wide app /// - Task List(bool excludeArchived = false, int limit = 100, IEnumerable types = null, string cursor = null, string teamId = null, CancellationToken? cancellationToken = null); + Task List(bool excludeArchived = false, int limit = 100, IEnumerable types = null, string cursor = null, string teamId = null, CancellationToken cancellationToken = default); /// /// Lists shared channel invites that have been generated or received but have not been approved by all parties. @@ -162,7 +162,7 @@ public interface IConversationsApi /// Set to returned by previous call to list items in subsequent page. /// Encoded team id for the workspace to retrieve invites for, required if org token is used. /// - Task ListConnectInvites(int count = 100, string cursor = null, string teamId = null, CancellationToken? cancellationToken = null); + Task ListConnectInvites(int count = 100, string cursor = null, string teamId = null, CancellationToken cancellationToken = default); /// /// Sets the read cursor in a channel. @@ -171,7 +171,7 @@ public interface IConversationsApi /// Channel or conversation to set the read cursor for. /// Unique identifier of message you want marked as most recently seen in this conversation. /// - Task Mark(string channelId, string messageTs, CancellationToken? cancellationToken = null); + Task Mark(string channelId, string messageTs, CancellationToken cancellationToken = default); /// /// Retrieve members of a conversation. @@ -185,7 +185,7 @@ public interface IConversationsApi /// Default value fetches the first "page" of the collection. /// /// - Task Members(string channelId, int limit = 100, string cursor = null, CancellationToken? cancellationToken = null); + Task Members(string channelId, int limit = 100, string cursor = null, CancellationToken cancellationToken = default); /// /// Opens or resumes a direct message or multi-person direct message. @@ -195,7 +195,7 @@ public interface IConversationsApi /// Resume a conversation by supplying an im or mpim's ID. /// /// The opened channel's ID - Task Open(string channelId, CancellationToken? cancellationToken = null); + Task Open(string channelId, CancellationToken cancellationToken = default); /// /// Opens or resumes a direct message or multi-person direct message. @@ -205,7 +205,7 @@ public interface IConversationsApi /// List of users. If only one user is included, this creates a 1:1 DM. The ordering of the users is preserved whenever a multi-person direct message is returned. /// /// The opened channel's ID - Task Open(IEnumerable userIds, CancellationToken? cancellationToken = null); + Task Open(IEnumerable userIds, CancellationToken cancellationToken = default); /// /// Opens or resumes a direct message or multi-person direct message. @@ -214,7 +214,7 @@ public interface IConversationsApi /// See the Slack documentation for more information. /// Resume a conversation by supplying an im or mpim's ID. /// - Task OpenAndReturnInfo(string channelId, CancellationToken? cancellationToken = null); + Task OpenAndReturnInfo(string channelId, CancellationToken cancellationToken = default); /// /// Opens or resumes a direct message or multi-person direct message. @@ -223,7 +223,7 @@ public interface IConversationsApi /// See the Slack documentation for more information. /// List of users. If only one user is included, this creates a 1:1 DM. The ordering of the users is preserved whenever a multi-person direct message is returned. /// - Task OpenAndReturnInfo(IEnumerable userIds, CancellationToken? cancellationToken = null); + Task OpenAndReturnInfo(IEnumerable userIds, CancellationToken cancellationToken = default); /// /// Renames a conversation. @@ -232,7 +232,7 @@ public interface IConversationsApi /// ID of conversation to rename. /// New name for conversation. /// - Task Rename(string channelId, string name, CancellationToken? cancellationToken = null); + Task Rename(string channelId, string name, CancellationToken cancellationToken = default); /// /// Retrieve a thread of messages posted to a conversation. @@ -250,7 +250,7 @@ public interface IConversationsApi /// Default value fetches the first "page" of the collection. /// /// - Task Replies(string channelId, string threadTs, string latestTs = null, string oldestTs = null, bool inclusive = false, int limit = 10, string cursor = null, CancellationToken? cancellationToken = null); + Task Replies(string channelId, string threadTs, string latestTs = null, string oldestTs = null, bool inclusive = false, int limit = 10, string cursor = null, CancellationToken cancellationToken = default); /// /// Sets the purpose for a conversation. @@ -259,7 +259,7 @@ public interface IConversationsApi /// Conversation to set the purpose of. /// A new, specialer purpose. /// - Task SetPurpose(string channelId, string purpose, CancellationToken? cancellationToken = null); + Task SetPurpose(string channelId, string purpose, CancellationToken cancellationToken = default); /// /// Sets the topic for a conversation. @@ -268,7 +268,7 @@ public interface IConversationsApi /// Conversation to set the topic of. /// The new topic string. Does not support formatting or linkification. /// - Task SetTopic(string channelId, string topic, CancellationToken? cancellationToken = null); + Task SetTopic(string channelId, string topic, CancellationToken cancellationToken = default); /// /// Reverses conversation archival. @@ -276,12 +276,12 @@ public interface IConversationsApi /// See the Slack documentation for more information. /// ID of conversation to unarchive. /// - Task Unarchive(string channelId, CancellationToken? cancellationToken = null); + Task Unarchive(string channelId, CancellationToken cancellationToken = default); } public class ConversationsApi(ISlackApiClient client) : IConversationsApi { - public Task AcceptSharedInvite(string channelName, string inviteId = null, string channelId = null, bool freeTrialAccepted = false, bool isPrivate = false, string teamId = null, CancellationToken? cancellationToken = null) => + public Task AcceptSharedInvite(string channelName, string inviteId = null, string channelId = null, bool freeTrialAccepted = false, bool isPrivate = false, string teamId = null, CancellationToken cancellationToken = default) => client.Post("conversations.acceptSharedInvite", new Args { { "channel_name", channelName }, @@ -292,20 +292,20 @@ public Task AcceptSharedInvite(string channelName, s { "team_id", teamId } }, cancellationToken); - public Task ApproveSharedInvite(string inviteId, string targetTeam = null, CancellationToken? cancellationToken = null) => + public Task ApproveSharedInvite(string inviteId, string targetTeam = null, CancellationToken cancellationToken = default) => client.Post("conversations.approveSharedInvite", new Args { { "invite_id", inviteId }, { "target_team", targetTeam } }, cancellationToken); - public Task Archive(string channelId, CancellationToken? cancellationToken = null) => + public Task Archive(string channelId, CancellationToken cancellationToken = default) => client.Post("conversations.archive", new Args { { "channel", channelId } }, cancellationToken); - public Task Close(string channelId, CancellationToken? cancellationToken = null) => + public Task Close(string channelId, CancellationToken cancellationToken = default) => client.Post("conversations.close", new Args { { "channel", channelId } }, cancellationToken); - public async Task Create(string name, bool isPrivate, string teamId = null, CancellationToken? cancellationToken = null) => + public async Task Create(string name, bool isPrivate, string teamId = null, CancellationToken cancellationToken = default) => (await client.Post("conversations.create", new Args { { "name", name }, @@ -314,14 +314,14 @@ public async Task Create(string name, bool isPrivate, string teamI }, cancellationToken).ConfigureAwait(false)) .Channel; - public Task DeclineSharedInvite(string inviteId, string targetTeam = null, CancellationToken? cancellationToken = null) => + public Task DeclineSharedInvite(string inviteId, string targetTeam = null, CancellationToken cancellationToken = default) => client.Get("conversations.declineSharedInvite", new Args { { "invite_id", inviteId }, { "target_team", targetTeam } }, cancellationToken); - public Task History(string channelId, string latestTs = null, string oldestTs = null, bool inclusive = false, int limit = 100, bool includeAllMetadata = false, string cursor = null, CancellationToken? cancellationToken = null) => + public Task History(string channelId, string latestTs = null, string oldestTs = null, bool inclusive = false, int limit = 100, bool includeAllMetadata = false, string cursor = null, CancellationToken cancellationToken = default) => client.Get("conversations.history", new Args { { "channel", channelId }, @@ -333,7 +333,7 @@ public Task History(string channelId, string latest { "include_all_metadata", includeAllMetadata } }, cancellationToken); - public async Task Info(string channelId, bool includeLocale = false, bool includeNumMembers = false, CancellationToken? cancellationToken = null) => + public async Task Info(string channelId, bool includeLocale = false, bool includeNumMembers = false, CancellationToken cancellationToken = default) => (await client.Get("conversations.info", new Args { { "channel", channelId }, @@ -342,7 +342,7 @@ public async Task Info(string channelId, bool includeLocale = fals }, cancellationToken).ConfigureAwait(false)) .Channel; - public async Task Invite(string channelId, IEnumerable userIds, CancellationToken? cancellationToken = null) => + public async Task Invite(string channelId, IEnumerable userIds, CancellationToken cancellationToken = default) => (await client.Post("conversations.invite", new Args { { "channel", channelId }, @@ -350,7 +350,7 @@ public async Task Invite(string channelId, IEnumerable use }, cancellationToken).ConfigureAwait(false)) .Channel; - public Task InviteShared(string channelId, IEnumerable emails, IEnumerable userIds, bool externalLimited = true, CancellationToken? cancellationToken = null) => + public Task InviteShared(string channelId, IEnumerable emails, IEnumerable userIds, bool externalLimited = true, CancellationToken cancellationToken = default) => client.Get("conversations.inviteShared", new Args() { { "channel", channelId }, @@ -359,20 +359,20 @@ public Task InviteShared(string channelId, IEnumerable Join(string channelId, CancellationToken? cancellationToken = null) => + public Task Join(string channelId, CancellationToken cancellationToken = default) => client.Post("conversations.join", new Args { { "channel", channelId } }, cancellationToken); - public Task Kick(string channelId, string userId, CancellationToken? cancellationToken = null) => + public Task Kick(string channelId, string userId, CancellationToken cancellationToken = default) => client.Post("conversations.kick", new Args { { "channel", channelId }, { "user", userId } }, cancellationToken); - public Task Leave(string channelId, CancellationToken? cancellationToken = null) => + public Task Leave(string channelId, CancellationToken cancellationToken = default) => client.Post("conversations.leave", new Args { { "channel", channelId } }, cancellationToken); - public Task List(bool excludeArchived = false, int limit = 100, IEnumerable types = null, string cursor = null, string teamId = null, CancellationToken? cancellationToken = null) => + public Task List(bool excludeArchived = false, int limit = 100, IEnumerable types = null, string cursor = null, string teamId = null, CancellationToken cancellationToken = default) => client.Get("conversations.list", new Args { { "cursor", cursor }, @@ -382,7 +382,7 @@ public Task List(bool excludeArchived = false, int lim { "team_id", teamId } }, cancellationToken); - public Task ListConnectInvites(int count = 100, string cursor = null, string teamId = null, CancellationToken? cancellationToken = null) => + public Task ListConnectInvites(int count = 100, string cursor = null, string teamId = null, CancellationToken cancellationToken = default) => client.Post("conversations.listConnectInvites", new Args { { "count", count }, @@ -390,14 +390,14 @@ public Task ListConnectInvites(int count = 100, stri { "team_id", teamId } }, cancellationToken); - public Task Mark(string channelId, string messageTs, CancellationToken? cancellationToken = null) => + public Task Mark(string channelId, string messageTs, CancellationToken cancellationToken = default) => client.Post("conversations.mark", new Args { { "channel", channelId }, { "ts", messageTs } }, cancellationToken); - public Task Members(string channelId, int limit = 100, string cursor = null, CancellationToken? cancellationToken = null) => + public Task Members(string channelId, int limit = 100, string cursor = null, CancellationToken cancellationToken = default) => client.Get("conversations.members", new Args { { "channel", channelId }, @@ -405,19 +405,19 @@ public Task Members(string channelId, int limit = 1 { "limit", limit } }, cancellationToken); - public async Task Open(string channelId, CancellationToken? cancellationToken = null) => + public async Task Open(string channelId, CancellationToken cancellationToken = default) => (await Open(false, channelId, null, cancellationToken).ConfigureAwait(false)).Channel.Id; - public async Task Open(IEnumerable userIds, CancellationToken? cancellationToken = null) => + public async Task Open(IEnumerable userIds, CancellationToken cancellationToken = default) => (await Open(false, null, userIds, cancellationToken).ConfigureAwait(false)).Channel.Id; - public Task OpenAndReturnInfo(string channelId, CancellationToken? cancellationToken = null) => + public Task OpenAndReturnInfo(string channelId, CancellationToken cancellationToken = default) => Open(true, channelId, null, cancellationToken); - public Task OpenAndReturnInfo(IEnumerable userIds, CancellationToken? cancellationToken = null) => + public Task OpenAndReturnInfo(IEnumerable userIds, CancellationToken cancellationToken = default) => Open(true, null, userIds, cancellationToken); - private Task Open(bool returnIm, string channelId = null, IEnumerable userIds = null, CancellationToken? cancellationToken = null) where T : class => + private Task Open(bool returnIm, string channelId = null, IEnumerable userIds = null, CancellationToken cancellationToken = default) where T : class => client.Post("conversations.open", new Args { { "channel", channelId }, @@ -425,7 +425,7 @@ private Task Open(bool returnIm, string channelId = null, IEnumerable Rename(string channelId, string name, CancellationToken? cancellationToken = null) => + public async Task Rename(string channelId, string name, CancellationToken cancellationToken = default) => (await client.Post("conversations.rename", new Args { { "channel", channelId }, @@ -433,7 +433,7 @@ public async Task Rename(string channelId, string name, Cancellati }, cancellationToken).ConfigureAwait(false)) .Channel; - public Task Replies(string channelId, string threadTs, string latestTs = null, string oldestTs = null, bool inclusive = false, int limit = 10, string cursor = null, CancellationToken? cancellationToken = null) => + public Task Replies(string channelId, string threadTs, string latestTs = null, string oldestTs = null, bool inclusive = false, int limit = 10, string cursor = null, CancellationToken cancellationToken = default) => client.Get("conversations.replies", new Args { { "channel", channelId }, @@ -445,7 +445,7 @@ public Task Replies(string channelId, string threa { "oldest", oldestTs } }, cancellationToken); - public async Task SetPurpose(string channelId, string purpose, CancellationToken? cancellationToken = null) => + public async Task SetPurpose(string channelId, string purpose, CancellationToken cancellationToken = default) => (await client.Post("conversations.setPurpose", new Args { { "channel", channelId }, @@ -453,7 +453,7 @@ public async Task SetPurpose(string channelId, string purpose, Cancellat }, cancellationToken).ConfigureAwait(false)) .Purpose; - public async Task SetTopic(string channelId, string topic, CancellationToken? cancellationToken = null) => + public async Task SetTopic(string channelId, string topic, CancellationToken cancellationToken = default) => (await client.Post("conversations.setTopic", new Args { { "channel", channelId }, @@ -461,6 +461,6 @@ public async Task SetTopic(string channelId, string topic, CancellationT }, cancellationToken).ConfigureAwait(false)) .Topic; - public Task Unarchive(string channelId, CancellationToken? cancellationToken = null) => + public Task Unarchive(string channelId, CancellationToken cancellationToken = default) => client.Post("conversations.unarchive", new Args { { "channel", channelId } }, cancellationToken); } \ No newline at end of file diff --git a/SlackNet/WebApi/DialogApi.cs b/SlackNet/WebApi/DialogApi.cs index 47c41dbd..27930cba 100644 --- a/SlackNet/WebApi/DialogApi.cs +++ b/SlackNet/WebApi/DialogApi.cs @@ -14,7 +14,7 @@ public interface IDialogApi /// Exchange a trigger to post to the user. /// The dialog definition. /// - Task Open(string triggerId, Dialog dialog, CancellationToken? cancellationToken = null); + Task Open(string triggerId, Dialog dialog, CancellationToken cancellationToken = default); } public class DialogApi : IDialogApi @@ -22,7 +22,7 @@ public class DialogApi : IDialogApi private readonly ISlackApiClient _client; public DialogApi(ISlackApiClient client) => _client = client; - public Task Open(string triggerId, Dialog dialog, CancellationToken? cancellationToken = null) => + public Task Open(string triggerId, Dialog dialog, CancellationToken cancellationToken = default) => _client.Post("dialog.open", new Args { { "dialog", dialog }, diff --git a/SlackNet/WebApi/DndApi.cs b/SlackNet/WebApi/DndApi.cs index 7332b440..bf09c7d7 100644 --- a/SlackNet/WebApi/DndApi.cs +++ b/SlackNet/WebApi/DndApi.cs @@ -12,21 +12,21 @@ public interface IDndApi /// /// See the Slack documentation for more information. /// - Task EndDnd(CancellationToken? cancellationToken = null); + Task EndDnd(CancellationToken cancellationToken = default); /// /// Ends the current user's snooze mode immediately. /// /// See the Slack documentation for more information. /// - Task EndSnooze(CancellationToken? cancellationToken = null); + Task EndSnooze(CancellationToken cancellationToken = default); /// /// Provides information about the current user's Do Not Disturb settings. /// /// See the Slack documentation for more information. /// - Task Info(CancellationToken? cancellationToken = null); + Task Info(CancellationToken cancellationToken = default); /// /// Provides information about a user's current Do Not Disturb settings. @@ -34,7 +34,7 @@ public interface IDndApi /// See the Slack documentation for more information. /// User to fetch status for. /// - Task Info(string userId, CancellationToken? cancellationToken = null); + Task Info(string userId, CancellationToken cancellationToken = default); /// /// Adjusts the snooze duration for a user's Do Not Disturb settings. @@ -43,7 +43,7 @@ public interface IDndApi /// See the Slack documentation for more information. /// Number of minutes, from now, to snooze until. /// - Task SetSnooze(int numMinutes, CancellationToken? cancellationToken); + Task SetSnooze(int numMinutes, CancellationToken cancellationToken); /// /// Provides information about the current Do Not Disturb settings for users of a Slack team. @@ -52,7 +52,7 @@ public interface IDndApi /// List of users to fetch Do Not Disturb status for (defaults to entire team). /// /// Mapping of user to DnD status. - Task> TeamInfo(IEnumerable userIds, CancellationToken? cancellationToken = null); + Task> TeamInfo(IEnumerable userIds, CancellationToken cancellationToken = default); } public class DndApi : IDndApi @@ -60,21 +60,21 @@ public class DndApi : IDndApi private readonly ISlackApiClient _client; public DndApi(ISlackApiClient client) => _client = client; - public Task EndDnd(CancellationToken? cancellationToken = null) => + public Task EndDnd(CancellationToken cancellationToken = default) => _client.Post("dnd.endDnd", new Args(), cancellationToken); - public Task EndSnooze(CancellationToken? cancellationToken = null) => + public Task EndSnooze(CancellationToken cancellationToken = default) => _client.Post("dnd.endSnooze", new Args(), cancellationToken); - public Task Info(CancellationToken? cancellationToken = null) => + public Task Info(CancellationToken cancellationToken = default) => _client.Get("dnd.info", new Args(), cancellationToken); - public Task Info(string userId, CancellationToken? cancellationToken = null) => + public Task Info(string userId, CancellationToken cancellationToken = default) => _client.Get("dnd.info", new Args { { "user", userId } }, cancellationToken); - public Task SetSnooze(int numMinutes, CancellationToken? cancellationToken = null) => + public Task SetSnooze(int numMinutes, CancellationToken cancellationToken = default) => _client.Get("dnd.setSnooze", new Args { { "num_minutes", numMinutes } }, cancellationToken); - public async Task> TeamInfo(IEnumerable userIds, CancellationToken? cancellationToken = null) => + public async Task> TeamInfo(IEnumerable userIds, CancellationToken cancellationToken = default) => (await _client.Get("dnd.teamInfo", new Args { { "users", userIds } }, cancellationToken).ConfigureAwait(false)).Users; } \ No newline at end of file diff --git a/SlackNet/WebApi/EmojiApi.cs b/SlackNet/WebApi/EmojiApi.cs index 0340dd37..fda46ed2 100644 --- a/SlackNet/WebApi/EmojiApi.cs +++ b/SlackNet/WebApi/EmojiApi.cs @@ -17,11 +17,11 @@ public interface IEmojiApi /// The alias: pseudo-protocol will be used where the emoji is an alias, /// the string following the colon is the name of the other emoji this emoji is an alias to. /// - Task> List(CancellationToken? cancellationToken = null); + Task> List(CancellationToken cancellationToken = default); } public class EmojiApi(ISlackApiClient client) : IEmojiApi { - public async Task> List(CancellationToken? cancellationToken = null) => + public async Task> List(CancellationToken cancellationToken = default) => (await client.Get("emoji.list", new Args(), cancellationToken).ConfigureAwait(false)).Emoji; } \ No newline at end of file diff --git a/SlackNet/WebApi/FileCommentsApi.cs b/SlackNet/WebApi/FileCommentsApi.cs index 3adb5c77..1204fa1c 100644 --- a/SlackNet/WebApi/FileCommentsApi.cs +++ b/SlackNet/WebApi/FileCommentsApi.cs @@ -14,7 +14,7 @@ public interface IFileCommentsApi /// File to delete a comment from. /// The comment to delete. /// - Task Delete(string fileId, string commentId, CancellationToken? cancellationToken = null); + Task Delete(string fileId, string commentId, CancellationToken cancellationToken = default); } public class FileCommentsApi : IFileCommentsApi @@ -22,7 +22,7 @@ public class FileCommentsApi : IFileCommentsApi private readonly ISlackApiClient _client; public FileCommentsApi(ISlackApiClient client) => _client = client; - public Task Delete(string fileId, string commentId, CancellationToken? cancellationToken = null) => + public Task Delete(string fileId, string commentId, CancellationToken cancellationToken = default) => _client.Post("files.comments.delete", new Args { { "file", fileId }, diff --git a/SlackNet/WebApi/FilesApi.cs b/SlackNet/WebApi/FilesApi.cs index 5ab4214a..c27a506a 100644 --- a/SlackNet/WebApi/FilesApi.cs +++ b/SlackNet/WebApi/FilesApi.cs @@ -18,7 +18,7 @@ public interface IFilesApi /// See the Slack documentation for more information. /// ID of file to delete. /// - Task Delete(string fileId, CancellationToken? cancellationToken = null); + Task Delete(string fileId, CancellationToken cancellationToken = default); /// /// Returns information about a file in your team. @@ -32,7 +32,7 @@ public interface IFilesApi /// Set cursor equal to the returned by the previous request's . /// /// - Task Info(string fileId, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null); + Task Info(string fileId, int count = 100, int page = 1, string cursor = null, CancellationToken cancellationToken = default); /// /// Returns a list of files within the team. It can be filtered and sliced in various ways. @@ -59,7 +59,7 @@ Task List( int count = 100, int page = 1, string cursor = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -68,7 +68,7 @@ Task List( /// See the Slack documentation for more information. /// File to revoke /// - Task RevokePublicUrl(string fileId, CancellationToken? cancellationToken = null); + Task RevokePublicUrl(string fileId, CancellationToken cancellationToken = default); /// /// Enables public/external sharing for a file. @@ -76,7 +76,7 @@ Task List( /// See the Slack documentation for more information. /// File to share. /// - Task SharedPublicUrl(string fileId, CancellationToken? cancellationToken = null); + Task SharedPublicUrl(string fileId, CancellationToken cancellationToken = default); /// /// Allows you to create or upload an existing file. @@ -99,7 +99,7 @@ Task Upload( string initialComment = null, string threadTs = null, IEnumerable channels = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -123,7 +123,7 @@ Task Upload( string initialComment = null, string threadTs = null, IEnumerable channels = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -147,7 +147,7 @@ Task Upload( string initialComment = null, string threadTs = null, IEnumerable channels = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -173,7 +173,7 @@ Task UploadSnippet( string initialComment = null, string threadTs = null, IEnumerable channels = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -190,7 +190,7 @@ Task Upload( string channelId = null, string threadTs = null, string initialComment = null, - CancellationToken? cancellationToken = null); + CancellationToken cancellationToken = default); /// /// Uploads external files. @@ -206,7 +206,7 @@ Task> Upload( string channelId = null, string threadTs = null, string initialComment = null, - CancellationToken? cancellationToken = null); + CancellationToken cancellationToken = default); /// /// Gets a URL for an edge external file upload. @@ -223,7 +223,7 @@ Task GetUploadUrlExternal( int length, string altText = null, string snippetType = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -240,7 +240,7 @@ Task> CompleteUploadExternal( string channelId = null, string initialComment = null, string threadTs = null, - CancellationToken? cancellationToken = null); + CancellationToken cancellationToken = default); } public class FilesApi(ISlackApiClient client, IHttp http) : IFilesApi @@ -248,10 +248,10 @@ public class FilesApi(ISlackApiClient client, IHttp http) : IFilesApi [Obsolete("Include IHttp parameter.")] public FilesApi(ISlackApiClient client) : this(client, Default.Http()) { } - public Task Delete(string fileId, CancellationToken? cancellationToken = null) => + public Task Delete(string fileId, CancellationToken cancellationToken = default) => client.Post("files.delete", new Args { { "file", fileId } }, cancellationToken); - public Task Info(string fileId, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null) => + public Task Info(string fileId, int count = 100, int page = 1, string cursor = null, CancellationToken cancellationToken = default) => client.Get("files.info", new Args { { "file", fileId }, @@ -269,7 +269,7 @@ public Task List( int count = 100, int page = 1, string cursor = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => client.Get("files.list", new Args { @@ -283,10 +283,10 @@ public Task List( { "cursor", cursor } }, cancellationToken); - public Task RevokePublicUrl(string fileId, CancellationToken? cancellationToken = null) => + public Task RevokePublicUrl(string fileId, CancellationToken cancellationToken = default) => client.Post("files.revokePublicURL", new Args { { "file", fileId } }, cancellationToken); - public Task SharedPublicUrl(string fileId, CancellationToken? cancellationToken = null) => + public Task SharedPublicUrl(string fileId, CancellationToken cancellationToken = default) => client.Post("files.sharedPublicURL", new Args { { "file", fileId } }, cancellationToken); public async Task Upload( @@ -297,7 +297,7 @@ public async Task Upload( string initialComment = null, string threadTs = null, IEnumerable channels = null, - CancellationToken? cancellationToken = null) + CancellationToken cancellationToken = default) { using var content = new StringContent(fileContents); return await Upload(content, fileType, fileName, title, initialComment, threadTs, channels, cancellationToken).ConfigureAwait(false); @@ -311,7 +311,7 @@ public async Task Upload( string initialComment = null, string threadTs = null, IEnumerable channels = null, - CancellationToken? cancellationToken = null) + CancellationToken cancellationToken = default) { using var content = new ByteArrayContent(fileContents); return await Upload(content, fileType, fileName, title, initialComment, threadTs, channels, cancellationToken).ConfigureAwait(false); @@ -325,7 +325,7 @@ public Task Upload( string initialComment = null, string threadTs = null, IEnumerable channels = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => Upload(new StreamContent(fileContents), fileType, fileName, title, initialComment, threadTs, channels, cancellationToken); @@ -337,7 +337,7 @@ private async Task Upload( string initialComment, string threadTs, IEnumerable channels, - CancellationToken? cancellationToken + CancellationToken cancellationToken ) { using var content = new MultipartFormDataContent(); @@ -364,7 +364,7 @@ public Task UploadSnippet( string initialComment = null, string threadTs = null, IEnumerable channels = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => client.Post("files.upload", new Args(), new SlackFormContent { @@ -383,10 +383,10 @@ public async Task Upload( string channelId = null, string threadTs = null, string initialComment = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => (await Upload([fileUpload], channelId, threadTs, initialComment, cancellationToken).ConfigureAwait(false)).Single(); - public async Task> Upload(IEnumerable files, string channelId = null, string threadTs = null, string initialComment = null, CancellationToken? cancellationToken = null) + public async Task> Upload(IEnumerable files, string channelId = null, string threadTs = null, string initialComment = null, CancellationToken cancellationToken = default) { var fileReferences = await Task.WhenAll(files .Select(async file => @@ -406,7 +406,7 @@ public Task GetUploadUrlExternal( int length, string altText = null, string snippetType = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => client.Get("files.getUploadURLExternal", new Args { @@ -421,7 +421,7 @@ public async Task> CompleteUploadExternal( string channelId = null, string threadTs = null, string initialComment = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => (await client.Post("files.completeUploadExternal", new Args { diff --git a/SlackNet/WebApi/MigrationApi.cs b/SlackNet/WebApi/MigrationApi.cs index 35a8dc8a..c6ecf4cd 100644 --- a/SlackNet/WebApi/MigrationApi.cs +++ b/SlackNet/WebApi/MigrationApi.cs @@ -14,7 +14,7 @@ public interface IMigrationApi /// List of user ids, up to 400 per request. /// Specify true to convert W global user IDs to workspace-specific U IDs. Defaults to False. /// - Task Exchange(IEnumerable userIds, bool toOld = false, CancellationToken? cancellationToken = null); + Task Exchange(IEnumerable userIds, bool toOld = false, CancellationToken cancellationToken = default); } public class MigrationApi : IMigrationApi @@ -22,7 +22,7 @@ public class MigrationApi : IMigrationApi private readonly ISlackApiClient _client; public MigrationApi(ISlackApiClient client) => _client = client; - public Task Exchange(IEnumerable userIds, bool toOld = false, CancellationToken? cancellationToken = null) => + public Task Exchange(IEnumerable userIds, bool toOld = false, CancellationToken cancellationToken = default) => _client.Get("migration.exchange", new Args { { "users", userIds }, diff --git a/SlackNet/WebApi/OAuthApi.cs b/SlackNet/WebApi/OAuthApi.cs index a6d44550..84d38309 100644 --- a/SlackNet/WebApi/OAuthApi.cs +++ b/SlackNet/WebApi/OAuthApi.cs @@ -15,7 +15,7 @@ public interface IOAuthApi /// The code param returned via the OAuth callback. /// This must match the originally submitted URI (if one was sent). /// - Task Access(string clientId, string clientSecret, string code, string redirectUrl, CancellationToken? cancellationToken = null); + Task Access(string clientId, string clientSecret, string code, string redirectUrl, CancellationToken cancellationToken = default); } public class OAuthApi : IOAuthApi @@ -23,7 +23,7 @@ public class OAuthApi : IOAuthApi private readonly ISlackApiClient _client; public OAuthApi(ISlackApiClient client) => _client = client; - public Task Access(string clientId, string clientSecret, string code, string redirectUrl, CancellationToken? cancellationToken = null) => + public Task Access(string clientId, string clientSecret, string code, string redirectUrl, CancellationToken cancellationToken = default) => _client.Get("oauth.access", new Args { { "client_id", clientId }, diff --git a/SlackNet/WebApi/OAuthV2Api.cs b/SlackNet/WebApi/OAuthV2Api.cs index 3b443988..b88d1cf2 100644 --- a/SlackNet/WebApi/OAuthV2Api.cs +++ b/SlackNet/WebApi/OAuthV2Api.cs @@ -27,7 +27,7 @@ Task Access( string? redirectUrl, string? refreshToken, #nullable disable - CancellationToken? cancellationToken + CancellationToken cancellationToken ); } @@ -46,7 +46,7 @@ public Task Access( string? redirectUrl, string? refreshToken, #nullable disable - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => _client.WithAccessToken(string.Empty) // Since this endpoint is for getting an access token, it doesn't make sense to include an existing token in the request .Post("oauth.v2.access", new Args(), new SlackFormContent diff --git a/SlackNet/WebApi/OpenIdApi.cs b/SlackNet/WebApi/OpenIdApi.cs index 04921518..c88cdf9f 100644 --- a/SlackNet/WebApi/OpenIdApi.cs +++ b/SlackNet/WebApi/OpenIdApi.cs @@ -27,7 +27,7 @@ Task Token( string? redirectUrl, string? refreshToken, #nullable disable - CancellationToken? cancellationToken + CancellationToken cancellationToken ); /// @@ -38,7 +38,7 @@ Task Token( /// /// See the Slack documentation for more information. /// - Task UserInfo(CancellationToken? cancellationToken); + Task UserInfo(CancellationToken cancellationToken); } public class OpenIdApi : IOpenIdApi @@ -55,7 +55,7 @@ public Task Token( string? redirectUrl = null, string? refreshToken = null, #nullable disable - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => _client.Post("openid.connect.token", new Args(), new SlackFormContent { @@ -68,6 +68,6 @@ public Task Token( } , cancellationToken); - public Task UserInfo(CancellationToken? cancellationToken = null) => + public Task UserInfo(CancellationToken cancellationToken = default) => _client.Post("openid.connect.userInfo", new Args(), cancellationToken); } \ No newline at end of file diff --git a/SlackNet/WebApi/PinsApi.cs b/SlackNet/WebApi/PinsApi.cs index 359bb082..acc32b6b 100644 --- a/SlackNet/WebApi/PinsApi.cs +++ b/SlackNet/WebApi/PinsApi.cs @@ -14,7 +14,7 @@ public interface IPinsApi /// Channel to pin the message in. /// Timestamp of the message to pin. /// - Task AddMessage(string channelId, string ts = null, CancellationToken? cancellationToken = null); + Task AddMessage(string channelId, string ts = null, CancellationToken cancellationToken = default); /// /// Lists the items pinned to a channel. @@ -22,7 +22,7 @@ public interface IPinsApi /// See the Slack documentation for more information. /// Channel to get pinned items for. /// - Task> List(string channelId, CancellationToken? cancellationToken = null); + Task> List(string channelId, CancellationToken cancellationToken = default); /// /// Un-pins a file from a channel. @@ -31,7 +31,7 @@ public interface IPinsApi /// Channel where the file is pinned to. /// File to un-pin. /// - Task RemoveFile(string channelId, string fileId, CancellationToken? cancellationToken = null); + Task RemoveFile(string channelId, string fileId, CancellationToken cancellationToken = default); /// /// Un-pins a file comment from a channel. @@ -40,7 +40,7 @@ public interface IPinsApi /// Channel where the file comment is pinned to. /// File comment to un-pin. /// - Task RemoveFileComment(string channelId, string fileCommentId, CancellationToken? cancellationToken = null); + Task RemoveFileComment(string channelId, string fileCommentId, CancellationToken cancellationToken = default); /// /// Un-pins a message from a channel. @@ -49,7 +49,7 @@ public interface IPinsApi /// Channel where the message is pinned to. /// Timestamp of the message to un-pin. /// - Task RemoveMessage(string channelId, string ts, CancellationToken? cancellationToken = null); + Task RemoveMessage(string channelId, string ts, CancellationToken cancellationToken = default); } public class PinsApi : IPinsApi @@ -57,31 +57,31 @@ public class PinsApi : IPinsApi private readonly ISlackApiClient _client; public PinsApi(ISlackApiClient client) => _client = client; - public Task AddMessage(string channelId, string ts = null, CancellationToken? cancellationToken = null) => + public Task AddMessage(string channelId, string ts = null, CancellationToken cancellationToken = default) => _client.Post("pins.add", new Args { { "channel", channelId }, { "timestamp", ts } }, cancellationToken); - public async Task> List(string channelId, CancellationToken? cancellationToken = null) => + public async Task> List(string channelId, CancellationToken cancellationToken = default) => (await _client.Get("pins.list", new Args { { "channel", channelId } }, cancellationToken).ConfigureAwait(false)).Items; - public Task RemoveFile(string channelId, string fileId, CancellationToken? cancellationToken = null) => + public Task RemoveFile(string channelId, string fileId, CancellationToken cancellationToken = default) => _client.Post("pins.remove", new Args { { "channel", channelId }, { "file", fileId } }, cancellationToken); - public Task RemoveFileComment(string channelId, string fileCommentId, CancellationToken? cancellationToken = null) => + public Task RemoveFileComment(string channelId, string fileCommentId, CancellationToken cancellationToken = default) => _client.Post("pins.remove", new Args { { "channel", channelId }, { "file_comment", fileCommentId } }, cancellationToken); - public Task RemoveMessage(string channelId, string ts, CancellationToken? cancellationToken = null) => + public Task RemoveMessage(string channelId, string ts, CancellationToken cancellationToken = default) => _client.Post("pins.remove", new Args { { "channel", channelId }, diff --git a/SlackNet/WebApi/ReactionsApi.cs b/SlackNet/WebApi/ReactionsApi.cs index 042ec159..41d82e6c 100644 --- a/SlackNet/WebApi/ReactionsApi.cs +++ b/SlackNet/WebApi/ReactionsApi.cs @@ -15,7 +15,7 @@ public interface IReactionsApi /// Channel where the message to add reaction to was posted. /// Timestamp of the message to add reaction to. /// - Task AddToMessage(string name, string channelId, string ts, CancellationToken? cancellationToken = null); + Task AddToMessage(string name, string channelId, string ts, CancellationToken cancellationToken = default); /// /// Returns a list of all reactions for a single file. @@ -24,7 +24,7 @@ public interface IReactionsApi /// File to get reactions for. /// If true always return the complete reaction list. /// - Task GetForFile(string fileId, bool full = false, CancellationToken? cancellationToken = null); + Task GetForFile(string fileId, bool full = false, CancellationToken cancellationToken = default); /// /// Returns a list of all reactions for a single file comment. @@ -33,7 +33,7 @@ public interface IReactionsApi /// File comment to get reactions for. /// If true always return the complete reaction list. /// - Task GetForFileComment(string fileCommentId, bool full = false, CancellationToken? cancellationToken = null); + Task GetForFileComment(string fileCommentId, bool full = false, CancellationToken cancellationToken = default); /// /// Returns a list of all reactions for a single message. @@ -43,7 +43,7 @@ public interface IReactionsApi /// Timestamp of the message to get reactions for. /// If true always return the complete reaction list. /// - Task GetForMessage(string channelId, string ts, bool full = false, CancellationToken? cancellationToken = null); + Task GetForMessage(string channelId, string ts, bool full = false, CancellationToken cancellationToken = default); /// /// Returns a list of all items (file, file comment, channel message, group message, or direct message) reacted to by a user. @@ -58,7 +58,7 @@ public interface IReactionsApi /// Set cursor equal to the returned by the previous request's . /// /// - Task List(string userId = null, bool full = false, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null); + Task List(string userId = null, bool full = false, int count = 100, int page = 1, string cursor = null, CancellationToken cancellationToken = default); /// /// Removes a reaction (emoji) from a file. @@ -67,7 +67,7 @@ public interface IReactionsApi /// Reaction (emoji) name. /// File to remove reaction from. /// - Task RemoveFromFile(string name, string fileId, CancellationToken? cancellationToken = null); + Task RemoveFromFile(string name, string fileId, CancellationToken cancellationToken = default); /// /// Removes a reaction (emoji) from a file comment. @@ -76,7 +76,7 @@ public interface IReactionsApi /// Reaction (emoji) name. /// File comment to remove reaction from. /// - Task RemoveFromFileComment(string name, string fileCommentId, CancellationToken? cancellationToken = null); + Task RemoveFromFileComment(string name, string fileCommentId, CancellationToken cancellationToken = default); /// /// Removes a reaction (emoji) from a message. @@ -86,12 +86,12 @@ public interface IReactionsApi /// Channel where the message to remove reaction from was posted. /// Timestamp of the message to remove reaction from. /// - Task RemoveFromMessage(string name, string channelId, string ts, CancellationToken? cancellationToken = null); + Task RemoveFromMessage(string name, string channelId, string ts, CancellationToken cancellationToken = default); } public class ReactionsApi(ISlackApiClient client) : IReactionsApi { - public Task AddToMessage(string name, string channelId, string ts, CancellationToken? cancellationToken = null) => + public Task AddToMessage(string name, string channelId, string ts, CancellationToken cancellationToken = default) => client.Post("reactions.add", new Args { { "name", name }, @@ -99,7 +99,7 @@ public Task AddToMessage(string name, string channelId, string ts, CancellationT { "timestamp", ts } }, cancellationToken); - public async Task GetForFile(string fileId, bool full = false, CancellationToken? cancellationToken = null) => + public async Task GetForFile(string fileId, bool full = false, CancellationToken cancellationToken = default) => (await client.Get("reactions.get", new Args { { "file", fileId }, @@ -107,7 +107,7 @@ public async Task GetForFile(string fileId, bool full = false, Cancellatio }, cancellationToken).ConfigureAwait(false)) .File; - public async Task GetForFileComment(string fileCommentId, bool full = false, CancellationToken? cancellationToken = null) => + public async Task GetForFileComment(string fileCommentId, bool full = false, CancellationToken cancellationToken = default) => (await client.Get("reactions.get", new Args { { "file_comment", fileCommentId }, @@ -115,7 +115,7 @@ public async Task GetForFileComment(string fileCommentId, bool full }, cancellationToken).ConfigureAwait(false)) .Comment; - public async Task GetForMessage(string channelId, string ts, bool full = false, CancellationToken? cancellationToken = null) => + public async Task GetForMessage(string channelId, string ts, bool full = false, CancellationToken cancellationToken = default) => (await client.Get("reactions.get", new Args { { "channel", channelId }, @@ -124,7 +124,7 @@ public async Task GetForMessage(string channelId, string ts, bool }, cancellationToken).ConfigureAwait(false)) .Message; - public Task List(string userId = null, bool full = false, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null) => + public Task List(string userId = null, bool full = false, int count = 100, int page = 1, string cursor = null, CancellationToken cancellationToken = default) => client.Get("reactions.list", new Args { { "user", userId }, @@ -134,21 +134,21 @@ public Task List(string userId = null, bool full = fal { "cursor", cursor } }, cancellationToken); - public Task RemoveFromFile(string name, string fileId, CancellationToken? cancellationToken = null) => + public Task RemoveFromFile(string name, string fileId, CancellationToken cancellationToken = default) => client.Post("reactions.remove", new Args { { "name", name }, { "file", fileId } }, cancellationToken); - public Task RemoveFromFileComment(string name, string fileCommentId, CancellationToken? cancellationToken = null) => + public Task RemoveFromFileComment(string name, string fileCommentId, CancellationToken cancellationToken = default) => client.Post("reactions.remove", new Args { { "name", name }, { "file_comment", fileCommentId } }, cancellationToken); - public Task RemoveFromMessage(string name, string channelId, string ts, CancellationToken? cancellationToken = null) => + public Task RemoveFromMessage(string name, string channelId, string ts, CancellationToken cancellationToken = default) => client.Post("reactions.remove", new Args { { "name", name }, diff --git a/SlackNet/WebApi/RemindersApi.cs b/SlackNet/WebApi/RemindersApi.cs index af4ceaaa..3badcfd7 100644 --- a/SlackNet/WebApi/RemindersApi.cs +++ b/SlackNet/WebApi/RemindersApi.cs @@ -16,7 +16,7 @@ public interface IRemindersApi /// When this reminder should happen (up to five years from now). /// The user who will receive the reminder. If no user is specified, the reminder will go to user who created it. /// - Task Add(string text, DateTime time, string userId = null, CancellationToken? cancellationToken = null); + Task Add(string text, DateTime time, string userId = null, CancellationToken cancellationToken = default); /// /// Creates a reminder. @@ -26,7 +26,7 @@ public interface IRemindersApi /// When this reminder should happen (up to 24 hours from now). /// The user who will receive the reminder. If no user is specified, the reminder will go to user who created it. /// - Task Add(string text, TimeSpan time, string userId = null, CancellationToken? cancellationToken = null); + Task Add(string text, TimeSpan time, string userId = null, CancellationToken cancellationToken = default); /// /// Creates a reminder. @@ -40,7 +40,7 @@ public interface IRemindersApi /// /// The user who will receive the reminder. If no user is specified, the reminder will go to user who created it. /// - Task Add(string text, string time, string userId = null, CancellationToken? cancellationToken = null); + Task Add(string text, string time, string userId = null, CancellationToken cancellationToken = default); /// /// Completes a reminder. @@ -48,7 +48,7 @@ public interface IRemindersApi /// See the Slack documentation for more information. /// The ID of the reminder to be marked as complete. /// - Task Complete(string reminderId, CancellationToken? cancellationToken = null); + Task Complete(string reminderId, CancellationToken cancellationToken = default); /// /// Deletes a reminder. @@ -56,7 +56,7 @@ public interface IRemindersApi /// See the Slack documentation for more information. /// The ID of the reminder. /// - Task Delete(string reminderId, CancellationToken? cancellationToken); + Task Delete(string reminderId, CancellationToken cancellationToken); /// /// Returns information about a reminder. @@ -64,14 +64,14 @@ public interface IRemindersApi /// See the Slack documentation for more information. /// The ID of the reminder. /// - Task Info(string reminderId, CancellationToken? cancellationToken = null); + Task Info(string reminderId, CancellationToken cancellationToken = default); /// /// Lists all reminders created by or for the user. /// /// See the Slack documentation for more information. /// - Task> List(CancellationToken? cancellationToken = null); + Task> List(CancellationToken cancellationToken = default); } public class RemindersApi : IRemindersApi @@ -79,7 +79,7 @@ public class RemindersApi : IRemindersApi private readonly ISlackApiClient _client; public RemindersApi(ISlackApiClient client) => _client = client; - public async Task Add(string text, DateTime time, string userId = null, CancellationToken? cancellationToken = null) => + public async Task Add(string text, DateTime time, string userId = null, CancellationToken cancellationToken = default) => (await _client.Post("reminders.add", new Args { { "text", text }, @@ -88,7 +88,7 @@ public async Task Add(string text, DateTime time, string userId = null }, cancellationToken).ConfigureAwait(false)) .Reminder; - public async Task Add(string text, TimeSpan time, string userId = null, CancellationToken? cancellationToken = null) => + public async Task Add(string text, TimeSpan time, string userId = null, CancellationToken cancellationToken = default) => (await _client.Post("reminders.add", new Args { { "text", text }, @@ -97,7 +97,7 @@ public async Task Add(string text, TimeSpan time, string userId = null }, cancellationToken).ConfigureAwait(false)) .Reminder; - public async Task Add(string text, string time, string userId = null, CancellationToken? cancellationToken = null) => + public async Task Add(string text, string time, string userId = null, CancellationToken cancellationToken = default) => (await _client.Post("reminders.add", new Args { { "text", text }, @@ -106,15 +106,15 @@ public async Task Add(string text, string time, string userId = null, }, cancellationToken).ConfigureAwait(false)) .Reminder; - public Task Complete(string reminderId, CancellationToken? cancellationToken = null) => + public Task Complete(string reminderId, CancellationToken cancellationToken = default) => _client.Post("reminders.complete", new Args { { "reminder", reminderId } }, cancellationToken); - public Task Delete(string reminderId, CancellationToken? cancellationToken = null) => + public Task Delete(string reminderId, CancellationToken cancellationToken = default) => _client.Post("reminders.delete", new Args { { "reminder", reminderId } }, cancellationToken); - public async Task Info(string reminderId, CancellationToken? cancellationToken = null) => + public async Task Info(string reminderId, CancellationToken cancellationToken = default) => (await _client.Get("reminders.info", new Args { { "reminder", reminderId } }, cancellationToken).ConfigureAwait(false)).Reminder; - public async Task> List(CancellationToken? cancellationToken = null) => + public async Task> List(CancellationToken cancellationToken = default) => (await _client.Get("reminders.list", new Args(), cancellationToken).ConfigureAwait(false)).Reminders; } \ No newline at end of file diff --git a/SlackNet/WebApi/RemoteFilesApi.cs b/SlackNet/WebApi/RemoteFilesApi.cs index 630050e9..b0647670 100644 --- a/SlackNet/WebApi/RemoteFilesApi.cs +++ b/SlackNet/WebApi/RemoteFilesApi.cs @@ -26,7 +26,7 @@ Task Add( string title, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -47,7 +47,7 @@ Task Add( byte[] previewImage, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -68,7 +68,7 @@ Task Add( Stream previewImage, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -77,7 +77,7 @@ Task Add( /// See the Slack documentation for more information. /// Creator defined unique ID for the file. /// - Task InfoByExternalId(string externalId, CancellationToken? cancellationToken = null); + Task InfoByExternalId(string externalId, CancellationToken cancellationToken = default); /// /// Retrieve information about a remote file added to Slack. @@ -85,7 +85,7 @@ Task Add( /// See the Slack documentation for more information. /// Specify a file by providing its ID. /// - Task InfoByFileId(string fileId, CancellationToken? cancellationToken = null); + Task InfoByFileId(string fileId, CancellationToken cancellationToken = default); /// /// Lists remote files visible to the token that calls it. @@ -107,7 +107,7 @@ Task List( string tsFrom = null, string tsTo = null, string cursor = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -116,7 +116,7 @@ Task List( /// See the Slack documentation for more information. /// Creator defined unique ID for the file. /// - Task RemoveByExternalId(string externalId, CancellationToken? cancellationToken = null); + Task RemoveByExternalId(string externalId, CancellationToken cancellationToken = default); /// /// Removes a remote file from Slack. It does not delete the file from its external host. @@ -124,7 +124,7 @@ Task List( /// See the Slack documentation for more information. /// Specify a file by providing its ID. /// - Task RemoveByFileId(string fileId, CancellationToken? cancellationToken = null); + Task RemoveByFileId(string fileId, CancellationToken cancellationToken = default); /// /// Share a remote file into a channel. @@ -133,7 +133,7 @@ Task List( /// Creator defined unique ID for the file. /// List of channel IDs where the file will be shared. /// - Task ShareByExternalId(string externalId, IEnumerable channelIds, CancellationToken? cancellationToken = null); + Task ShareByExternalId(string externalId, IEnumerable channelIds, CancellationToken cancellationToken = default); /// /// Share a remote file into a channel. @@ -142,7 +142,7 @@ Task List( /// Specify a file by providing its ID. /// List of channel IDs where the file will be shared. /// - Task ShareByFileId(string fileId, IEnumerable channelIds, CancellationToken? cancellationToken = null); + Task ShareByFileId(string fileId, IEnumerable channelIds, CancellationToken cancellationToken = default); /// /// Updates an existing remote file. @@ -160,7 +160,7 @@ Task UpdateByExternalId( string title = null, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -179,7 +179,7 @@ Task UpdateByFileId( string title = null, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -200,7 +200,7 @@ Task UpdateByExternalId( string title = null, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -221,7 +221,7 @@ Task UpdateByFileId( string title = null, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -242,7 +242,7 @@ Task UpdateByExternalId( string title = null, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -263,7 +263,7 @@ Task UpdateByFileId( string title = null, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); } @@ -278,7 +278,7 @@ public Task Add( string title, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => Add(externalId, externalUrl, title, filetype, indexableFileContents, null, cancellationToken); @@ -289,7 +289,7 @@ public Task Add( byte[] previewImage, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => Add(externalId, externalUrl, title, filetype, indexableFileContents, new ByteArrayContent(previewImage), cancellationToken); @@ -300,7 +300,7 @@ public Task Add( Stream previewImage, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => Add(externalId, externalUrl, title, filetype, indexableFileContents, new StreamContent(previewImage), cancellationToken); @@ -311,7 +311,7 @@ private Task Add( string filetype, string indexableFileContents, HttpContent previewContent, - CancellationToken? cancellationToken + CancellationToken cancellationToken ) => AddOrUpdate("files.remote.add", new Args { @@ -321,10 +321,10 @@ private Task Add( { "filetype", filetype } }, indexableFileContents, previewContent, cancellationToken); - public Task InfoByExternalId(string externalId, CancellationToken? cancellationToken = null) => + public Task InfoByExternalId(string externalId, CancellationToken cancellationToken = default) => _client.Get("files.remote.info", new Args { { "external_id", externalId } }, cancellationToken); - public Task InfoByFileId(string fileId, CancellationToken? cancellationToken = null) => + public Task InfoByFileId(string fileId, CancellationToken cancellationToken = default) => _client.Get("files.remote.info", new Args { { "file", fileId } }, cancellationToken); public Task List( @@ -333,7 +333,7 @@ public Task List( string tsFrom = null, string tsTo = null, string cursor = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => _client.Get("files.remote.list", new Args { @@ -344,16 +344,16 @@ public Task List( { "cursor", cursor } }, cancellationToken); - public Task RemoveByExternalId(string externalId, CancellationToken? cancellationToken = null) => + public Task RemoveByExternalId(string externalId, CancellationToken cancellationToken = default) => _client.Get("files.remote.remove", new Args { { "external_id", externalId } }, cancellationToken); - public Task RemoveByFileId(string fileId, CancellationToken? cancellationToken = null) => + public Task RemoveByFileId(string fileId, CancellationToken cancellationToken = default) => _client.Get("files.remote.remove", new Args { { "file", fileId } }, cancellationToken); - public Task ShareByExternalId(string externalId, IEnumerable channelIds, CancellationToken? cancellationToken = null) => + public Task ShareByExternalId(string externalId, IEnumerable channelIds, CancellationToken cancellationToken = default) => _client.Get("files.remote.share", new Args { { "external_id", externalId }, { "channels", channelIds } }, cancellationToken); - public Task ShareByFileId(string fileId, IEnumerable channelIds, CancellationToken? cancellationToken = null) => + public Task ShareByFileId(string fileId, IEnumerable channelIds, CancellationToken cancellationToken = default) => _client.Get("files.remote.share", new Args { { "file", fileId }, { "channels", channelIds } }, cancellationToken); public Task UpdateByExternalId( @@ -362,7 +362,7 @@ public Task UpdateByExternalId( string title = null, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => Update(externalId, null, externalUrl, title, filetype, indexableFileContents, null, cancellationToken); @@ -372,7 +372,7 @@ public Task UpdateByFileId( string title = null, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => Update(null, fileId, externalUrl, title, filetype, indexableFileContents, null, cancellationToken); @@ -383,7 +383,7 @@ public Task UpdateByExternalId( string title = null, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => Update(externalId, null, externalUrl, title, filetype, indexableFileContents, new ByteArrayContent(previewImage), cancellationToken); @@ -394,7 +394,7 @@ public Task UpdateByFileId( string title = null, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => Update(null, fileId, externalUrl, title, filetype, indexableFileContents, new ByteArrayContent(previewImage), cancellationToken); @@ -405,7 +405,7 @@ public Task UpdateByExternalId( string title = null, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => Update(externalId, null, externalUrl, title, filetype, indexableFileContents, new StreamContent(previewImage), cancellationToken); @@ -416,7 +416,7 @@ public Task UpdateByFileId( string title = null, string filetype = null, string indexableFileContents = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => Update(null, fileId, externalUrl, title, filetype, indexableFileContents, new StreamContent(previewImage), cancellationToken); @@ -428,7 +428,7 @@ private Task Update( string filetype, string indexableFileContents, HttpContent previewContent, - CancellationToken? cancellationToken + CancellationToken cancellationToken ) => AddOrUpdate("files.remote.update", new Args { @@ -439,7 +439,7 @@ private Task Update( { "filetype", filetype } }, indexableFileContents, previewContent, cancellationToken); - private Task AddOrUpdate(string slackMethod, Args args, string indexableFileContents, HttpContent previewContent, CancellationToken? cancellationToken) + private Task AddOrUpdate(string slackMethod, Args args, string indexableFileContents, HttpContent previewContent, CancellationToken cancellationToken) { var content = new MultipartFormDataContent(); diff --git a/SlackNet/WebApi/RtmApi.cs b/SlackNet/WebApi/RtmApi.cs index 1f75c0b1..72e465f0 100644 --- a/SlackNet/WebApi/RtmApi.cs +++ b/SlackNet/WebApi/RtmApi.cs @@ -15,7 +15,7 @@ public interface IRtmApi /// Only deliver presence events when requested by subscription. /// Group presence change notices in events when possible. /// - Task Connect(bool manualPresenceSubscription = false, bool batchPresenceAware = false, CancellationToken? cancellationToken = null); + Task Connect(bool manualPresenceSubscription = false, bool batchPresenceAware = false, CancellationToken cancellationToken = default); /// /// Begins a Real Time Messaging API session and reserves your application a specific URL with which to connect via websocket. @@ -39,7 +39,7 @@ Task Start( bool batchPresenceAware = false, bool includeLocale = false, bool noLatest = false, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); } @@ -48,7 +48,7 @@ public class RtmApi : IRtmApi private readonly ISlackApiClient _client; public RtmApi(ISlackApiClient client) => _client = client; - public Task Connect(bool manualPresenceSubscription = false, bool batchPresenceAware = false, CancellationToken? cancellationToken = null) => + public Task Connect(bool manualPresenceSubscription = false, bool batchPresenceAware = false, CancellationToken cancellationToken = default) => _client.Get("rtm.connect", new Args { { "presence_sub", manualPresenceSubscription }, { "batch_presence_aware", batchPresenceAware } }, cancellationToken); public Task Start( @@ -59,7 +59,7 @@ public Task Start( bool batchPresenceAware = false, bool includeLocale = false, bool noLatest = false, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => _client.Get("rtm.start", new Args { diff --git a/SlackNet/WebApi/ScheduledMessagesApi.cs b/SlackNet/WebApi/ScheduledMessagesApi.cs index 8a1a06bb..baaaf5e7 100644 --- a/SlackNet/WebApi/ScheduledMessagesApi.cs +++ b/SlackNet/WebApi/ScheduledMessagesApi.cs @@ -26,7 +26,7 @@ Task List( string oldestTs = null, int limit = 100, string cursor = null, - CancellationToken? cancellationToken = null); + CancellationToken cancellationToken = default); } public class ScheduledMessagesApi : IScheduledMessagesApi @@ -40,7 +40,7 @@ public Task List( string oldestTs = null, int limit = 100, string cursor = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => _client.Post("chat.scheduledMessages.list", new Args { diff --git a/SlackNet/WebApi/SearchApi.cs b/SlackNet/WebApi/SearchApi.cs index f135b217..bbd322f5 100644 --- a/SlackNet/WebApi/SearchApi.cs +++ b/SlackNet/WebApi/SearchApi.cs @@ -24,7 +24,7 @@ Task All( bool highlight = false, int count = 20, int page = 1, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -45,7 +45,7 @@ Task Files( bool highlight = false, int count = 20, int page = 1, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -66,7 +66,7 @@ Task Messages( bool highlight = false, int count = 20, int page = 1, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); } @@ -82,7 +82,7 @@ public Task All( bool highlight = false, int count = 20, int page = 1, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => _client.Get("search.all", new Args { @@ -102,7 +102,7 @@ public Task Files( bool highlight = false, int count = 20, int page = 1, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => _client.Get("search.files", new Args { @@ -122,7 +122,7 @@ public Task Messages( bool highlight = false, int count = 20, int page = 1, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => _client.Get("search.messages", new Args { diff --git a/SlackNet/WebApi/TeamApi.cs b/SlackNet/WebApi/TeamApi.cs index f2271c47..285fd162 100644 --- a/SlackNet/WebApi/TeamApi.cs +++ b/SlackNet/WebApi/TeamApi.cs @@ -20,7 +20,7 @@ public interface ITeamApi /// Set cursor equal to the returned by the previous request's . /// /// - Task AccessLogs(DateTime before, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null); + Task AccessLogs(DateTime before, int count = 100, int page = 1, string cursor = null, CancellationToken cancellationToken = default); /// /// Used to get the access logs for users on a team. @@ -34,7 +34,7 @@ public interface ITeamApi /// Set cursor equal to the returned by the previous request's . /// /// - Task AccessLogs(int? before = null, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null); + Task AccessLogs(int? before = null, int count = 100, int page = 1, string cursor = null, CancellationToken cancellationToken = default); /// /// Lists billable information for each user on the team. @@ -43,14 +43,14 @@ public interface ITeamApi /// See the Slack documentation for more information. /// A user to retrieve the billable information for. Defaults to all users. /// - Task> BillableInfo(string userId = null, CancellationToken? cancellationToken = null); + Task> BillableInfo(string userId = null, CancellationToken cancellationToken = default); /// /// Provides information about your team. /// /// See the Slack documentation for more information. /// - Task Info(CancellationToken? cancellationToken = null); + Task Info(CancellationToken cancellationToken = default); /// /// Lists the integration activity logs for a team, including when integrations are added, modified and removed. @@ -71,7 +71,7 @@ Task IntegrationLogs( int page = 1, string serviceId = null, string userId = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); } @@ -80,7 +80,7 @@ public class TeamApi : ITeamApi private readonly ISlackApiClient _client; public TeamApi(ISlackApiClient client) => _client = client; - public Task AccessLogs(DateTime before, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null) => + public Task AccessLogs(DateTime before, int count = 100, int page = 1, string cursor = null, CancellationToken cancellationToken = default) => _client.Get("team.accessLogs", new Args { { "before", before.ToTimestamp() }, @@ -89,7 +89,7 @@ public Task AccessLogs(DateTime before, int count = 100, int { "cursor", cursor } }, cancellationToken); - public Task AccessLogs(int? before = null, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null) => + public Task AccessLogs(int? before = null, int count = 100, int page = 1, string cursor = null, CancellationToken cancellationToken = default) => _client.Get("team.accessLogs", new Args { { "before", before }, @@ -98,10 +98,10 @@ public Task AccessLogs(int? before = null, int count = 100, { "cursor", cursor } }, cancellationToken); - public async Task> BillableInfo(string userId = null, CancellationToken? cancellationToken = null) => + public async Task> BillableInfo(string userId = null, CancellationToken cancellationToken = default) => (await _client.Get("team.billableInfo", new Args { { "user", userId } }, cancellationToken).ConfigureAwait(false)).BillableInfo; - public async Task Info(CancellationToken? cancellationToken = null) => + public async Task Info(CancellationToken cancellationToken = default) => (await _client.Get("team.info", new Args(), cancellationToken).ConfigureAwait(false)).Team; public Task IntegrationLogs( @@ -111,7 +111,7 @@ public Task IntegrationLogs( int page = 1, string serviceId = null, string userId = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => _client.Get("team.integrationLogs", new Args { diff --git a/SlackNet/WebApi/TeamBillingApi.cs b/SlackNet/WebApi/TeamBillingApi.cs index ee4b1877..92cfb727 100644 --- a/SlackNet/WebApi/TeamBillingApi.cs +++ b/SlackNet/WebApi/TeamBillingApi.cs @@ -11,7 +11,7 @@ public interface ITeamBillingApi /// /// See the Slack documentation for more information. /// - Task Info(CancellationToken? cancellationToken = null); + Task Info(CancellationToken cancellationToken = default); } public class TeamBillingApi : ITeamBillingApi @@ -19,6 +19,6 @@ public class TeamBillingApi : ITeamBillingApi private readonly ISlackApiClient _client; public TeamBillingApi(ISlackApiClient client) => _client = client; - public Task Info(CancellationToken? cancellationToken = null) => + public Task Info(CancellationToken cancellationToken = default) => _client.Get("team.billing.info", new Args(), cancellationToken); } \ No newline at end of file diff --git a/SlackNet/WebApi/TeamPreferencesApi.cs b/SlackNet/WebApi/TeamPreferencesApi.cs index bba4c041..8d9d31ca 100644 --- a/SlackNet/WebApi/TeamPreferencesApi.cs +++ b/SlackNet/WebApi/TeamPreferencesApi.cs @@ -11,7 +11,7 @@ public interface ITeamPreferencesApi /// /// See the Slack documentation for more information. /// - Task List(CancellationToken? cancellationToken = null); + Task List(CancellationToken cancellationToken = default); } public class TeamPreferencesApi : ITeamPreferencesApi @@ -19,6 +19,6 @@ public class TeamPreferencesApi : ITeamPreferencesApi private readonly ISlackApiClient _client; public TeamPreferencesApi(ISlackApiClient client) => _client = client; - public Task List(CancellationToken? cancellationToken = null) => + public Task List(CancellationToken cancellationToken = default) => _client.Get("team.preferences.list", new Args(), cancellationToken); } \ No newline at end of file diff --git a/SlackNet/WebApi/TeamProfileApi.cs b/SlackNet/WebApi/TeamProfileApi.cs index 82b98176..5fe21c64 100644 --- a/SlackNet/WebApi/TeamProfileApi.cs +++ b/SlackNet/WebApi/TeamProfileApi.cs @@ -12,7 +12,7 @@ public interface ITeamProfileApi /// See the Slack documentation for more information. /// Filter by visibility. /// - Task Get(ProfileFieldVisibility visibility = ProfileFieldVisibility.All, CancellationToken? cancellationToken = null); + Task Get(ProfileFieldVisibility visibility = ProfileFieldVisibility.All, CancellationToken cancellationToken = default); } public class TeamProfileApi : ITeamProfileApi @@ -20,6 +20,6 @@ public class TeamProfileApi : ITeamProfileApi private readonly ISlackApiClient _client; public TeamProfileApi(ISlackApiClient client) => _client = client; - public async Task Get(ProfileFieldVisibility visibility = ProfileFieldVisibility.All, CancellationToken? cancellationToken = null) => + public async Task Get(ProfileFieldVisibility visibility = ProfileFieldVisibility.All, CancellationToken cancellationToken = default) => (await _client.Get("team.profile.get", new Args { { "visibility", visibility } }, cancellationToken).ConfigureAwait(false)).Profile; } \ No newline at end of file diff --git a/SlackNet/WebApi/UserGroupUsersApi.cs b/SlackNet/WebApi/UserGroupUsersApi.cs index 92693bee..e8f5909d 100644 --- a/SlackNet/WebApi/UserGroupUsersApi.cs +++ b/SlackNet/WebApi/UserGroupUsersApi.cs @@ -14,7 +14,7 @@ public interface IUserGroupUsersApi /// ID of the User Group to update. /// Allow results that involve disabled User Groups. /// - Task> List(string userGroupId, bool includeDisabled = false, CancellationToken? cancellationToken = null); + Task> List(string userGroupId, bool includeDisabled = false, CancellationToken cancellationToken = default); /// /// Updates the list of users that belong to a User Group. @@ -25,7 +25,7 @@ public interface IUserGroupUsersApi /// User IDs that represent the entire list of users for the User Group. /// Include the number of users in the User Group. /// - Task Update(string userGroupId, IEnumerable userIds, bool includeCount = false, CancellationToken? cancellationToken = null); + Task Update(string userGroupId, IEnumerable userIds, bool includeCount = false, CancellationToken cancellationToken = default); } public class UserGroupUsersApi : IUserGroupUsersApi @@ -33,7 +33,7 @@ public class UserGroupUsersApi : IUserGroupUsersApi private readonly ISlackApiClient _client; public UserGroupUsersApi(ISlackApiClient client) => _client = client; - public async Task> List(string userGroupId, bool includeDisabled = false, CancellationToken? cancellationToken = null) => + public async Task> List(string userGroupId, bool includeDisabled = false, CancellationToken cancellationToken = default) => (await _client.Get("usergroups.users.list", new Args { { "usergroup", userGroupId }, @@ -41,7 +41,7 @@ public async Task> List(string userGroupId, bool includeDi }, cancellationToken).ConfigureAwait(false)) .Users; - public async Task Update(string userGroupId, IEnumerable userIds, bool includeCount = false, CancellationToken? cancellationToken = null) => + public async Task Update(string userGroupId, IEnumerable userIds, bool includeCount = false, CancellationToken cancellationToken = default) => (await _client.Post("usergroups.users.update", new Args { { "usergroup", userGroupId }, diff --git a/SlackNet/WebApi/UserGroupsApi.cs b/SlackNet/WebApi/UserGroupsApi.cs index 200afbcd..42cb69d8 100644 --- a/SlackNet/WebApi/UserGroupsApi.cs +++ b/SlackNet/WebApi/UserGroupsApi.cs @@ -23,7 +23,7 @@ Task Create( string description = null, string handle = null, bool includeCount = false, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); /// @@ -33,7 +33,7 @@ Task Create( /// ID of the User Group to disable. /// Include the number of users in the User Group. /// - Task Disable(string userGroupId, bool includeCount = false, CancellationToken? cancellationToken = null); + Task Disable(string userGroupId, bool includeCount = false, CancellationToken cancellationToken = default); /// /// Enables a User Group which was previously disabled. @@ -42,7 +42,7 @@ Task Create( /// ID of the User Group to enable. /// Include the number of users in the User Group. /// - Task Enable(string userGroupId, bool includeCount = false, CancellationToken? cancellationToken = null); + Task Enable(string userGroupId, bool includeCount = false, CancellationToken cancellationToken = default); /// /// Returns a list of all User Groups in the team. This can optionally include disabled User Groups. @@ -52,7 +52,7 @@ Task Create( /// Include disabled User Groups. /// Include the list of users for each User Group. /// - Task> List(bool includeCount = false, bool includeDisabled = false, bool includeUsers = false, CancellationToken? cancellationToken = null); + Task> List(bool includeCount = false, bool includeDisabled = false, bool includeUsers = false, CancellationToken cancellationToken = default); /// /// Updates the properties of an existing User Group. @@ -72,7 +72,7 @@ Task Update( string handle = null, bool includeCount = false, string name = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ); } @@ -87,7 +87,7 @@ public async Task Create( string description = null, string handle = null, bool includeCount = false, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => (await _client.Post("usergroups.create", new Args { @@ -99,7 +99,7 @@ public async Task Create( }, cancellationToken).ConfigureAwait(false)) .Usergroup; - public async Task Disable(string userGroupId, bool includeCount = false, CancellationToken? cancellationToken = null) => + public async Task Disable(string userGroupId, bool includeCount = false, CancellationToken cancellationToken = default) => (await _client.Post("usergroups.disable", new Args { { "usergroup", userGroupId }, @@ -107,7 +107,7 @@ public async Task Disable(string userGroupId, bool includeCount = fal }, cancellationToken).ConfigureAwait(false)) .Usergroup; - public async Task Enable(string userGroupId, bool includeCount = false, CancellationToken? cancellationToken = null) => + public async Task Enable(string userGroupId, bool includeCount = false, CancellationToken cancellationToken = default) => (await _client.Post("usergroups.enable", new Args { { "usergroup", userGroupId }, @@ -115,7 +115,7 @@ public async Task Enable(string userGroupId, bool includeCount = fals }, cancellationToken).ConfigureAwait(false)) .Usergroup; - public async Task> List(bool includeCount = false, bool includeDisabled = false, bool includeUsers = false, CancellationToken? cancellationToken = null) => + public async Task> List(bool includeCount = false, bool includeDisabled = false, bool includeUsers = false, CancellationToken cancellationToken = default) => (await _client.Get("usergroups.list", new Args { { "include_count", includeCount }, @@ -131,7 +131,7 @@ public async Task Update( string handle = null, bool includeCount = false, string name = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => (await _client.Post("usergroups.update", new Args { diff --git a/SlackNet/WebApi/UserProfileApi.cs b/SlackNet/WebApi/UserProfileApi.cs index 1ba7a01c..7edb8955 100644 --- a/SlackNet/WebApi/UserProfileApi.cs +++ b/SlackNet/WebApi/UserProfileApi.cs @@ -13,7 +13,7 @@ public interface IUserProfileApi /// Include labels for each ID in custom profile fields. /// User to retrieve profile info for (defaults to authed user). /// - Task Get(bool includeLabels = false, string userId = null, CancellationToken? cancellationToken = null); + Task Get(bool includeLabels = false, string userId = null, CancellationToken cancellationToken = default); /// /// Use this method to set a user's profile information, including name, email, current status, and other attributes. @@ -23,7 +23,7 @@ public interface IUserProfileApi /// Value to set a single key to. /// ID of user to change (defaults to authed user). This argument may only be specified by team admins on paid teams. /// - Task Set(string name, string value, string userId = null, CancellationToken? cancellationToken = null); + Task Set(string name, string value, string userId = null, CancellationToken cancellationToken = default); /// /// Use this method to set a user's profile information, including name, email, current status, and other attributes. @@ -32,7 +32,7 @@ public interface IUserProfileApi /// Changes to user's profile. Null properties will not be changed. /// ID of user to change (defaults to authed user). This argument may only be specified by team admins on paid teams. /// - Task Set(UserProfile profile, string userId = null, CancellationToken? cancellationToken = null); + Task Set(UserProfile profile, string userId = null, CancellationToken cancellationToken = default); } public class UserProfileApi : IUserProfileApi @@ -40,7 +40,7 @@ public class UserProfileApi : IUserProfileApi private readonly ISlackApiClient _client; public UserProfileApi(ISlackApiClient client) => _client = client; - public async Task Get(bool includeLabels = false, string userId = null, CancellationToken? cancellationToken = null) => + public async Task Get(bool includeLabels = false, string userId = null, CancellationToken cancellationToken = default) => (await _client.Get("users.profile.get", new Args { { "include_labels", includeLabels }, @@ -48,7 +48,7 @@ public async Task Get(bool includeLabels = false, string userId = n }, cancellationToken).ConfigureAwait(false)) .Profile; - public async Task Set(string name, string value, string userId = null, CancellationToken? cancellationToken = null) => + public async Task Set(string name, string value, string userId = null, CancellationToken cancellationToken = default) => (await _client.Post("users.profile.set", new Args { { "name", name }, @@ -57,7 +57,7 @@ public async Task Set(string name, string value, string userId = nu }, cancellationToken).ConfigureAwait(false)) .Profile; - public async Task Set(UserProfile profile, string userId = null, CancellationToken? cancellationToken = null) => + public async Task Set(UserProfile profile, string userId = null, CancellationToken cancellationToken = default) => (await _client.Post("users.profile.set", new Args { { "profile", profile }, diff --git a/SlackNet/WebApi/UsersApi.cs b/SlackNet/WebApi/UsersApi.cs index 75f00c70..9564cbc4 100644 --- a/SlackNet/WebApi/UsersApi.cs +++ b/SlackNet/WebApi/UsersApi.cs @@ -25,7 +25,7 @@ public interface IUsersApi /// Default value fetches the first "page" of the collection. /// /// - Task Conversations(bool excludeArchived = false, int limit = 100, IEnumerable types = null, string userId = null, string cursor = null, CancellationToken? cancellationToken = null); + Task Conversations(bool excludeArchived = false, int limit = 100, IEnumerable types = null, string userId = null, string cursor = null, CancellationToken cancellationToken = default); /// /// Allows the user to delete their profile image. It will clear whatever image is currently set. @@ -33,7 +33,7 @@ public interface IUsersApi /// /// See the Slack documentation for more information. /// - Task DeletePhoto(CancellationToken? cancellationToken = null); + Task DeletePhoto(CancellationToken cancellationToken = default); /// /// Lets you find out information about a user's presence. @@ -41,7 +41,7 @@ public interface IUsersApi /// See the Slack documentation for more information. /// User to get presence info on. Defaults to the authed user. /// - Task GetPresence(string userId = null, CancellationToken? cancellationToken = null); + Task GetPresence(string userId = null, CancellationToken cancellationToken = default); /// /// After your Slack app is awarded an identity token through Sign in with Slack, use this method to retrieve a user's identity. @@ -50,7 +50,7 @@ public interface IUsersApi /// /// See the Slack documentation for more information. /// - Task Identity(CancellationToken? cancellationToken = null); + Task Identity(CancellationToken cancellationToken = default); /// /// Returns information about a team member. @@ -59,7 +59,7 @@ public interface IUsersApi /// User to get info on. /// Set this to true to receive the locale for this user. /// - Task Info(string userId, bool includeLocale = false, CancellationToken? cancellationToken = null); + Task Info(string userId, bool includeLocale = false, CancellationToken cancellationToken = default); /// /// Returns a list of all users in the team. @@ -74,7 +74,7 @@ public interface IUsersApi /// Set this to true to receive the locale for users. /// The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached. /// - Task List(string cursor = null, bool includeLocale = false, int limit = 0, CancellationToken? cancellationToken = null); + Task List(string cursor = null, bool includeLocale = false, int limit = 0, CancellationToken cancellationToken = default); /// /// Find a user with an email address. @@ -82,7 +82,7 @@ public interface IUsersApi /// See the Slack documentation for more information. /// An email address belonging to a user in the workspace. /// - Task LookupByEmail(string email, CancellationToken? cancellationToken = null); + Task LookupByEmail(string email, CancellationToken cancellationToken = default); /// /// This method allows the user to set their profile image. @@ -99,7 +99,7 @@ public interface IUsersApi /// X coordinate of top-left corner of crop box. /// Y coordinate of top-left corner of crop box. /// - Task SetPhoto(byte[] imageContent, string contentType, string fileName = "photo", int? cropW = null, int? cropX = null, int? cropY = null, CancellationToken? cancellationToken = null); + Task SetPhoto(byte[] imageContent, string contentType, string fileName = "photo", int? cropW = null, int? cropX = null, int? cropY = null, CancellationToken cancellationToken = default); /// /// This method allows the user to set their profile image. @@ -116,7 +116,7 @@ public interface IUsersApi /// X coordinate of top-left corner of crop box. /// Y coordinate of top-left corner of crop box. /// - Task SetPhoto(Stream image, string contentType, string fileName = "photo", int? cropW = null, int? cropX = null, int? cropY = null, CancellationToken? cancellationToken = null); + Task SetPhoto(Stream image, string contentType, string fileName = "photo", int? cropW = null, int? cropX = null, int? cropY = null, CancellationToken cancellationToken = default); /// /// Lets you set the calling user's manual presence. @@ -125,7 +125,7 @@ public interface IUsersApi /// User's presence. /// [Obsolete("Use SetPresence with RequestPresence enum instead")] - Task SetPresence(Presence presence, CancellationToken? cancellationToken = null); + Task SetPresence(Presence presence, CancellationToken cancellationToken = default); /// /// Lets you set the calling user's manual presence. @@ -133,7 +133,7 @@ public interface IUsersApi /// See the Slack documentation for more information. /// User's presence. /// - Task SetPresence(RequestPresence presence, CancellationToken? cancellationToken = null); + Task SetPresence(RequestPresence presence, CancellationToken cancellationToken = default); } public class UsersApi : IUsersApi @@ -141,7 +141,7 @@ public class UsersApi : IUsersApi private readonly ISlackApiClient _client; public UsersApi(ISlackApiClient client) => _client = client; - public Task Conversations(bool excludeArchived = false, int limit = 100, IEnumerable types = null, string userId = null, string cursor = null, CancellationToken? cancellationToken = null) => + public Task Conversations(bool excludeArchived = false, int limit = 100, IEnumerable types = null, string userId = null, string cursor = null, CancellationToken cancellationToken = default) => _client.Get("users.conversations", new Args { { "cursor", cursor }, @@ -151,23 +151,23 @@ public Task Conversations(bool excludeArchived = false { "user", userId } }, cancellationToken); - public Task DeletePhoto(CancellationToken? cancellationToken = null) => + public Task DeletePhoto(CancellationToken cancellationToken = default) => _client.Get("users.deletePhoto", new Args(), cancellationToken); - public async Task GetPresence(string userId = null, CancellationToken? cancellationToken = null) => + public async Task GetPresence(string userId = null, CancellationToken cancellationToken = default) => (await _client.Get("users.getPresence", new Args { { "user", userId } }, cancellationToken).ConfigureAwait(false)).Presence; - public Task Identity(CancellationToken? cancellationToken = null) => + public Task Identity(CancellationToken cancellationToken = default) => _client.Get("users.identity", new Args(), cancellationToken); - public async Task Info(string userId, bool includeLocale = false, CancellationToken? cancellationToken = null) => + public async Task Info(string userId, bool includeLocale = false, CancellationToken cancellationToken = default) => (await _client.Get("users.info", new Args { { "user", userId }, { "include_locale", includeLocale }, }, cancellationToken).ConfigureAwait(false)).User; - public Task List(string cursor = null, bool includeLocale = false, int limit = 0, CancellationToken? cancellationToken = null) => + public Task List(string cursor = null, bool includeLocale = false, int limit = 0, CancellationToken cancellationToken = default) => _client.Get("users.list", new Args { { "cursor", cursor }, @@ -175,10 +175,10 @@ public Task List(string cursor = null, bool includeLocale = fa { "limit", limit } }, cancellationToken); - public async Task LookupByEmail(string email, CancellationToken? cancellationToken = null) => + public async Task LookupByEmail(string email, CancellationToken cancellationToken = default) => (await _client.Get("users.lookupByEmail", new Args { { "email", email } }, cancellationToken).ConfigureAwait(false)).User; - public Task SetPhoto(byte[] imageContent, string contentType, string fileName = "photo", int? cropW = null, int? cropX = null, int? cropY = null, CancellationToken? cancellationToken = null) => + public Task SetPhoto(byte[] imageContent, string contentType, string fileName = "photo", int? cropW = null, int? cropX = null, int? cropY = null, CancellationToken cancellationToken = default) => _client.Post("users.setPhoto", new Args { { "crop_w", cropW }, @@ -195,7 +195,7 @@ public Task SetPhoto(byte[] imageContent, string contentType, string fileName = }, cancellationToken); - public Task SetPhoto(Stream image, string contentType, string fileName = "photo", int? cropW = null, int? cropX = null, int? cropY = null, CancellationToken? cancellationToken = null) => + public Task SetPhoto(Stream image, string contentType, string fileName = "photo", int? cropW = null, int? cropX = null, int? cropY = null, CancellationToken cancellationToken = default) => _client.Post("users.setPhoto", new Args { { "crop_w", cropW }, @@ -212,9 +212,9 @@ public Task SetPhoto(Stream image, string contentType, string fileName = "photo" }, cancellationToken); - public Task SetPresence(Presence presence, CancellationToken? cancellationToken = null) => + public Task SetPresence(Presence presence, CancellationToken cancellationToken = default) => SetPresence(presence == Presence.Active ? RequestPresence.Auto : RequestPresence.Away, cancellationToken); - public Task SetPresence(RequestPresence presence, CancellationToken? cancellationToken = null) => + public Task SetPresence(RequestPresence presence, CancellationToken cancellationToken = default) => _client.Post("users.setPresence", new Args { { "presence", presence } }, cancellationToken); } \ No newline at end of file diff --git a/SlackNet/WebApi/ViewsApi.cs b/SlackNet/WebApi/ViewsApi.cs index 0490686f..61799c4b 100644 --- a/SlackNet/WebApi/ViewsApi.cs +++ b/SlackNet/WebApi/ViewsApi.cs @@ -13,7 +13,7 @@ public interface IViewsApi /// Exchange a trigger to post to the user. /// A view payload. /// - Task Open(string triggerId, ViewDefinition view, CancellationToken? cancellationToken = null); + Task Open(string triggerId, ViewDefinition view, CancellationToken cancellationToken = default); /// /// Create or update the view that comprises an app's Home tab for a specific user. @@ -23,7 +23,7 @@ public interface IViewsApi /// A string that represents view state to protect against possible race conditions. /// A view payload. /// - Task Publish(string userId, HomeViewDefinition viewDefinition, string hash = null, CancellationToken? cancellationToken = null); + Task Publish(string userId, HomeViewDefinition viewDefinition, string hash = null, CancellationToken cancellationToken = default); /// /// Push a new view onto the existing view stack by passing a view payload and a valid trigger ID @@ -34,7 +34,7 @@ public interface IViewsApi /// Exchange a trigger to post to the user. /// A view payload. /// - Task Push(string triggerId, ViewDefinition view, CancellationToken? cancellationToken = null); + Task Push(string triggerId, ViewDefinition view, CancellationToken cancellationToken = default); /// /// Update a view by passing a new view definition along with the returned by or the . @@ -44,7 +44,7 @@ public interface IViewsApi /// A unique identifier of the view set by the developer. Must be unique for all views on a team. /// A string that represents view state to protect against possible race conditions. /// - Task UpdateByExternalId(ViewDefinition view, string externalId, string hash = null, CancellationToken? cancellationToken = null); + Task UpdateByExternalId(ViewDefinition view, string externalId, string hash = null, CancellationToken cancellationToken = default); /// /// Update a view by passing a new view definition along with the returned by or the . @@ -54,19 +54,19 @@ public interface IViewsApi /// A string that represents view state to protect against possible race conditions. /// A unique identifier of the view to be updated. /// - Task UpdateByViewId(ViewDefinition view, string viewId, string hash = null, CancellationToken? cancellationToken = null); + Task UpdateByViewId(ViewDefinition view, string viewId, string hash = null, CancellationToken cancellationToken = default); } public class ViewsApi(ISlackApiClient client) : IViewsApi { - public Task Open(string triggerId, ViewDefinition view, CancellationToken? cancellationToken = null) => + public Task Open(string triggerId, ViewDefinition view, CancellationToken cancellationToken = default) => client.Post("views.open", new Args { { "trigger_id", triggerId }, { "view", view } }, cancellationToken); - public Task Publish(string userId, HomeViewDefinition viewDefinition, string hash = null, CancellationToken? cancellationToken = null) => + public Task Publish(string userId, HomeViewDefinition viewDefinition, string hash = null, CancellationToken cancellationToken = default) => client.Post("views.publish", new Args { { "user_id", userId }, @@ -74,14 +74,14 @@ public Task Publish(string userId, HomeViewDefinition viewDefiniti { "hash", hash } }, cancellationToken); - public Task Push(string triggerId, ViewDefinition view, CancellationToken? cancellationToken = null) => + public Task Push(string triggerId, ViewDefinition view, CancellationToken cancellationToken = default) => client.Post("views.push", new Args { { "trigger_id", triggerId }, { "view", view } }, cancellationToken); - public Task UpdateByExternalId(ViewDefinition view, string externalId, string hash = null, CancellationToken? cancellationToken = null) => + public Task UpdateByExternalId(ViewDefinition view, string externalId, string hash = null, CancellationToken cancellationToken = default) => client.Post("views.update", new Args { { "view", view }, @@ -89,7 +89,7 @@ public Task UpdateByExternalId(ViewDefinition view, string externa { "hash", hash } }, cancellationToken); - public Task UpdateByViewId(ViewDefinition view, string viewId, string hash = null, CancellationToken? cancellationToken = null) => + public Task UpdateByViewId(ViewDefinition view, string viewId, string hash = null, CancellationToken cancellationToken = default) => client.Post("views.update", new Args { { "view", view }, diff --git a/SlackNet/WebApi/WorkflowsApi.cs b/SlackNet/WebApi/WorkflowsApi.cs index ed2a11fe..e94022e4 100644 --- a/SlackNet/WebApi/WorkflowsApi.cs +++ b/SlackNet/WebApi/WorkflowsApi.cs @@ -25,7 +25,7 @@ public interface IWorkflowsApi /// An optional parameter that can be used to override app image that is shown in the Workflow Builder. /// An optional parameter that can be used to override the step name that is shown in the Workflow Builder. /// - Task UpdateStep(string workflowStepEditId, IDictionary inputs, IEnumerable outputs, string stepImageUrl = null, string stepName = null, CancellationToken? cancellationToken = null); + Task UpdateStep(string workflowStepEditId, IDictionary inputs, IEnumerable outputs, string stepImageUrl = null, string stepName = null, CancellationToken cancellationToken = default); /// /// Indicate that an app's step in a workflow completed execution. @@ -37,7 +37,7 @@ public interface IWorkflowsApi /// Keys of this object reflect the s of your outputs from your object. /// /// - Task StepCompleted(string workflowStepExecuteId, IDictionary outputs, CancellationToken? cancellationToken = null); + Task StepCompleted(string workflowStepExecuteId, IDictionary outputs, CancellationToken cancellationToken = default); /// /// Indicate that an app's step in a workflow failed to execute. @@ -46,7 +46,7 @@ public interface IWorkflowsApi /// The provided with a event. /// An object with a message property that should contain a human readable error message. /// - Task StepFailed(string workflowStepExecuteId, WorkflowError error, CancellationToken? cancellationToken = null); + Task StepFailed(string workflowStepExecuteId, WorkflowError error, CancellationToken cancellationToken = default); } public class WorkflowsApi : IWorkflowsApi @@ -59,7 +59,7 @@ public Task UpdateStep(string workflowStepEditId, IEnumerable outputs, string stepImageUrl = null, string stepName = null, - CancellationToken? cancellationToken = null + CancellationToken cancellationToken = default ) => _client.Post("workflows.updateStep", new Args { @@ -70,14 +70,14 @@ public Task UpdateStep(string workflowStepEditId, { "step_name", stepName } }, cancellationToken); - public Task StepCompleted(string workflowStepExecuteId, IDictionary outputs, CancellationToken? cancellationToken = null) => + public Task StepCompleted(string workflowStepExecuteId, IDictionary outputs, CancellationToken cancellationToken = default) => _client.Get("workflows.stepCompleted", new Args { { "workflow_step_execute_id", workflowStepExecuteId }, { "outputs", outputs } }, cancellationToken); - public Task StepFailed(string workflowStepExecuteId, WorkflowError error, CancellationToken? cancellationToken = null) => + public Task StepFailed(string workflowStepExecuteId, WorkflowError error, CancellationToken cancellationToken = default) => _client.Post("workflows.stepFailed", new Args { { "workflow_step_execute_id", workflowStepExecuteId },