using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using Luski.Shared.PublicServers.V1.Enums; using Luski.Shared.PublicServers.V1.Shared; namespace Luski.net.Structures.Public; public class SocketAppUser : SocketUser { public long SelectedChannel { get; init; } = default!; private List? _serverProfiles; public async Task GetSelectedChannel(CancellationToken Token) { return await Server.GetChannel(SelectedChannel, Token); } public async Task GetProfiles(CancellationToken Token) { if (_serverProfiles is null) { _serverProfiles = (await Server.GetMyProfiles(Token)).ToList(); } return _serverProfiles.ToArray(); } public async Task HasAccessToCategory(SocketCategory Category, ServerPermission RequiredPerms = ServerPermission.ViewThis) { if (Category.Server != Server) return false; if (Server.OwnerID == Id) return true; Role[] UserRoleIDList = await GetRoles(); RequiredPerms |= ServerPermission.ViewThis; ServerPermission GoodPerms = ServerPermission.None; UserOverride[] CatUserOverides = await Category.GetUserOverrides(); foreach (UserOverride CatUserOveride in CatUserOverides) { if (CatUserOveride.UserID != Id) continue; if ((CatUserOveride.BadPermissions & RequiredPerms) > ServerPermission.None) return false; if ((CatUserOveride.GoodPermissions & RequiredPerms) == RequiredPerms) return true; GoodPerms |= CatUserOveride.GoodPermissions; break; } RoleOverride[] CatRoleOverides = await Category.GetRoleOverrides(); int bad_index = -1; int good_index = -1; foreach (RoleOverride CatRoleOveride in CatRoleOverides) { if (!RoleIds.Contains(CatRoleOveride.ParentRoleID)) continue; var index = (await CatRoleOveride.GetRole()).Index; if ((CatRoleOveride.BadPermissions & RequiredPerms) > ServerPermission.None) { if (bad_index < index) bad_index = index; } else good_index = index; GoodPerms |= CatRoleOveride.GoodPermissions; } if (bad_index > good_index) return false; foreach (Role RoleID in UserRoleIDList) { GoodPerms |= RoleID.ServerPermissions; } return GoodPerms.HasPermission(RequiredPerms); } public string Username { get; internal set; } = default!; }