Skip to content

Commit

Permalink
Adds INestedChannel.SyncPermissionsAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
gehongyan committed May 21, 2023
1 parent de7825c commit 7f03741
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 48 deletions.
9 changes: 9 additions & 0 deletions src/Kook.Net.Core/Entities/Channels/INestedChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public interface INestedChannel : IGuildChannel
/// </returns>
bool? IsPermissionSynced { get; }

/// <summary>
/// Syncs the permissions of this nested channel with its parent's.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous operation for syncing channel permissions with its parent's.
/// </returns>
Task SyncPermissionsAsync(RequestOptions options = null);

/// <summary>
/// Gets the parent (category) channel of this channel.
/// </summary>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,6 @@ namespace Kook.WebSocket;
/// </summary>
public static class SocketVoiceChannelExperimentalExtensions
{
/// <summary>
/// Syncs the permissions of this nested channel with its parent's.
/// </summary>
/// <param name="channel">The nested channel whose permissions will be synced.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous operation for syncing channel permissions with its parent's.
/// </returns>
/// <remarks>
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
public static Task SyncPermissionsAsync(this SocketVoiceChannel channel, RequestOptions options = null)
=> ExperimentalChannelHelper.SyncPermissionsAsync(channel, channel.Kook, options);

/// <summary>
/// Disconnects the specified user from the voice channel.
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions src/Kook.Net.Rest/Entities/Channels/ChannelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,18 @@ public static async Task<ICategoryChannel> GetCategoryAsync(INestedChannel chann
return RestChannel.Create(client, model) as ICategoryChannel;
}

/// <exception cref="InvalidOperationException">This channel does not have a parent channel.</exception>
public static async Task SyncPermissionsAsync(INestedChannel channel, BaseKookClient client,
RequestOptions options)
{
var category = await GetCategoryAsync(channel, client, options).ConfigureAwait(false);
if (category == null)
throw new InvalidOperationException("This channel does not have a parent channel.");

var args = new SyncChannelPermissionsParams(channel.Id);
await client.ApiClient.SyncChannelPermissionsAsync(args, options).ConfigureAwait(false);
}

#endregion

#region Users
Expand Down
3 changes: 3 additions & 0 deletions src/Kook.Net.Rest/Entities/Channels/RestTextChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public Task<Cacheable<IUserMessage, Guid>> SendCardAsync(ICard card, Quote quote
/// </returns>
public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null)
=> ChannelHelper.GetCategoryAsync(this, Kook, options);
/// <inheritdoc />
public Task SyncPermissionsAsync(RequestOptions options = null)
=> ChannelHelper.SyncPermissionsAsync(this, Kook, options);

#endregion

Expand Down
3 changes: 3 additions & 0 deletions src/Kook.Net.Rest/Entities/Channels/RestVoiceChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public async Task<IReadOnlyCollection<IUser>> GetConnectedUsersAsync(RequestOpti
/// </returns>
public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null)
=> ChannelHelper.GetCategoryAsync(this, Kook, options);
/// <inheritdoc />
public Task SyncPermissionsAsync(RequestOptions options = null)
=> ChannelHelper.SyncPermissionsAsync(this, Kook, options);

#endregion

Expand Down
10 changes: 5 additions & 5 deletions src/Kook.Net.Rest/Kook.Net.Rest.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../Kook.Net.targets"/>
<Import Project="../Kook.Net.targets" />

<PropertyGroup>
<RootNamespace>Kook.Rest</RootNamespace>
Expand All @@ -11,15 +11,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Linq.Async" Version="6.0.1"/>
<PackageReference Include="System.Text.Json" Version="7.0.2"/>
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Kook.Net.Core\Kook.Net.Core.csproj"/>
<ProjectReference Include="..\Kook.Net.Core\Kook.Net.Core.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<Reference Include="System.Net.Http"/>
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
10 changes: 10 additions & 0 deletions src/Kook.Net.Rest/KookRestApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,16 @@ public async Task RemoveChannelPermissionOverwriteAsync(CreateOrRemoveChannelPer
await SendJsonAsync(HttpMethod.Post, () => $"channel-role/delete", args, ids, ClientBucketType.SendEdit, options).ConfigureAwait(false);
}

public async Task SyncChannelPermissionsAsync(SyncChannelPermissionsParams args, RequestOptions options = null)
{
Preconditions.NotNull(args, nameof(args));
Preconditions.NotEqual(args.ChannelId, 0, nameof(args.ChannelId));
options = RequestOptions.CreateOrClone(options);

var ids = new BucketIds(channelId: args.ChannelId);
await SendJsonAsync(HttpMethod.Post, () => $"channel-role/sync", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false);
}

#endregion

#region Messages
Expand Down
4 changes: 4 additions & 0 deletions src/Kook.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ internal override void Update(ClientState state, Model model)
public virtual Task ModifyAsync(Action<ModifyTextChannelProperties> func, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Kook, func, options);

/// <inheritdoc />
public virtual Task SyncPermissionsAsync(RequestOptions options = null)
=> ChannelHelper.SyncPermissionsAsync(this, Kook, options);

private string DebuggerDisplay => $"{Name} ({Id}, Text)";
internal new SocketTextChannel Clone() => MemberwiseClone() as SocketTextChannel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public async Task<IReadOnlyCollection<SocketGuildUser>> GetConnectedUsersAsync(C
return ConnectedUsers;
}

/// <inheritdoc />
public virtual Task SyncPermissionsAsync(RequestOptions options = null)
=> ChannelHelper.SyncPermissionsAsync(this, Kook, options);

#endregion

#region Invites
Expand Down
3 changes: 3 additions & 0 deletions test/Kook.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> GetUsersAsync(CacheMode

public ulong CreatorId => throw new NotImplementedException();

/// <inheritdoc />
public Task SyncPermissionsAsync(RequestOptions options = null) => throw new NotImplementedException();

public Task<ICategoryChannel> GetCategoryAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null) =>
throw new NotImplementedException();

Expand Down
3 changes: 3 additions & 0 deletions test/Kook.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> GetUsersAsync(CacheMode

public ulong CreatorId => throw new NotImplementedException();

/// <inheritdoc />
public Task SyncPermissionsAsync(RequestOptions options = null) => throw new NotImplementedException();

public Task<ICategoryChannel> GetCategoryAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null) =>
throw new NotImplementedException();

Expand Down

0 comments on commit 7f03741

Please sign in to comment.