-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/HeyBox.Net.WebSocket/Entitites/Users/SocketUserHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using HeyBox.API.Rest; | ||
|
||
namespace HeyBox.WebSocket; | ||
|
||
internal static class SocketUserHelper | ||
{ | ||
public static async Task AddRolesAsync(SocketRoomUser user, BaseSocketClient client, | ||
IEnumerable<ulong> roleIds, RequestOptions? options) | ||
{ | ||
IEnumerable<AddOrRemoveRoleParams> args = roleIds | ||
.Distinct() | ||
.Select(x => new AddOrRemoveRoleParams | ||
{ | ||
RoomId = user.Room.Id, | ||
RoleId = x, | ||
UserId = user.Id | ||
}); | ||
foreach (AddOrRemoveRoleParams arg in args) | ||
{ | ||
await client.ApiClient.AddRoleAsync(arg, options).ConfigureAwait(false); | ||
user.AddRole(arg.RoleId); | ||
} | ||
} | ||
|
||
public static async Task RemoveRolesAsync(SocketRoomUser user, BaseSocketClient client, | ||
IEnumerable<ulong> roleIds, RequestOptions? options) | ||
{ | ||
IEnumerable<AddOrRemoveRoleParams> args = roleIds | ||
.Distinct() | ||
.Select(x => new AddOrRemoveRoleParams | ||
{ | ||
RoomId = user.Room.Id, | ||
RoleId = x, | ||
UserId = user.Id | ||
}); | ||
foreach (AddOrRemoveRoleParams arg in args) | ||
{ | ||
await client.ApiClient.RemoveRoleAsync(arg, options).ConfigureAwait(false); | ||
user.RemoveRole(arg.RoleId); | ||
} | ||
} | ||
} |