rudimentary implementation and ui for syncshells

This commit is contained in:
Stanley Dimant
2022-09-30 01:18:57 +02:00
parent f6d1309d59
commit 2ca284546d
6 changed files with 386 additions and 57 deletions

View File

@@ -1,8 +1,10 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MareSynchronos.API;
using MareSynchronos.Utils;
using MareSynchronos.WebAPI.Utils;
using Microsoft.AspNetCore.SignalR.Client;
namespace MareSynchronos.WebAPI;
@@ -80,6 +82,7 @@ public partial class ApiController
if (dto.IsRemoved.GetValueOrDefault(false))
{
GroupPairedClients.RemoveAll(g => g.GroupGID == dto.GroupGID && g.UserUID == dto.UserUID);
return;
}
var existingUser = GroupPairedClients.FirstOrDefault(f => f.GroupGID == dto.GroupGID && f.UserUID == dto.UserUID);
@@ -93,7 +96,7 @@ public partial class ApiController
existingUser.UserAlias = dto.UserAlias ?? existingUser.UserAlias;
}
private void GroupChangedCallback(GroupDto dto)
private async Task GroupChangedCallback(GroupDto dto)
{
if (dto.IsDeleted.GetValueOrDefault(false))
{
@@ -106,6 +109,7 @@ public partial class ApiController
if (existingGroup == null)
{
Groups.Add(dto);
GroupPairedClients.AddRange(await _mareHub!.InvokeAsync<List<GroupPairDto>>(Api.InvokeGroupGetUsersInGroup, dto.GID));
return;
}

View File

@@ -1,4 +1,5 @@
using MareSynchronos.API;
using MareSynchronos.Utils;
using Microsoft.AspNetCore.SignalR.Client;
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -8,57 +9,67 @@ public partial class ApiController
{
public async Task<GroupCreatedDto> CreateGroup()
{
if (!IsConnected || SecretKey == "-") return new GroupCreatedDto();
return await _mareHub!.InvokeAsync<GroupCreatedDto>(Api.InvokeGroupCreate);
}
public async Task<bool> ChangeGroupPassword(string gid, string newpassword)
{
if (!IsConnected || SecretKey == "-") return false;
return await _mareHub!.InvokeAsync<bool>(Api.InvokeGroupChangePassword, gid, newpassword);
}
public async Task<List<GroupDto>> GetGroups()
{
if (!IsConnected || SecretKey == "-") return new List<GroupDto>();
return await _mareHub!.InvokeAsync<List<GroupDto>>(Api.InvokeGroupGetGroups);
}
public async Task<List<GroupPairDto>> GetUsersInGroup(string gid)
{
if (!IsConnected || SecretKey == "-") return new List<GroupPairDto>();
return await _mareHub!.InvokeAsync<List<GroupPairDto>>(Api.InvokeGroupGetUsersInGroup, gid);
}
public async Task SendGroupJoin(string gid, string password)
public async Task<bool> SendGroupJoin(string gid, string password)
{
if (!IsConnected || SecretKey == "-") return;
await _mareHub!.SendAsync(Api.SendGroupJoin, gid, password);
if (!IsConnected || SecretKey == "-") return false;
return await _mareHub!.InvokeAsync<bool>(Api.InvokeGroupJoin, gid, password);
}
public async Task SendGroupChangeInviteState(string gid, bool opened)
{
if (!IsConnected || SecretKey == "-") return;
await _mareHub!.SendAsync(Api.SendGroupChangeInviteState, gid, opened);
}
public async Task SendDeleteGroup(string gid)
{
if (!IsConnected || SecretKey == "-") return;
await _mareHub!.SendAsync(Api.SendGroupDelete, gid);
}
public async Task SendLeaveGroup(string gid)
{
if (!IsConnected || SecretKey == "-") return;
await _mareHub!.SendAsync(Api.SendGroupLeave, gid);
}
public async Task SendPauseGroup(string gid, bool isPaused)
{
if (!IsConnected || SecretKey == "-") return;
await _mareHub!.SendAsync(Api.SendGroupPause, gid, isPaused);
}
public async Task SendRemoveUserFromGroup(string gid, string uid)
{
if (!IsConnected || SecretKey == "-") return;
await _mareHub!.SendAsync(Api.SendGroupRemoveUser, gid, uid);
}
public async Task ChangeOwnerOfGroup(string gid, string uid)
{
if (!IsConnected || SecretKey == "-") return;
await _mareHub!.SendAsync(Api.SendGroupChangeOwner, gid, uid);
}
}

View File

@@ -118,6 +118,7 @@ public partial class ApiController : IDisposable
.ToDictionary(k => k.Key, k => k.Value);
public string UID => _connectionDto?.UID ?? string.Empty;
public string DisplayName => string.IsNullOrEmpty(_connectionDto?.Alias) ? (_connectionDto?.UID ?? string.Empty) : _connectionDto.Alias;
private string ApiUri => _pluginConfiguration.ApiUri;
public int OnlineUsers => SystemInfoDto.OnlineUsers;
@@ -268,6 +269,7 @@ public partial class ApiController : IDisposable
PairedClients =
await _mareHub!.InvokeAsync<List<ClientPairDto>>(Api.InvokeUserGetPairedClients, token);
Groups = await GetGroups();
GroupPairedClients.Clear();
foreach (var group in Groups)
{
GroupPairedClients.AddRange(await GetUsersInGroup(group.GID));