using Luski.net.Interfaces; using Luski.net.JsonTypes.BaseTypes; using System.Collections.Generic; using System.Linq; using System.Text.Json.Serialization; namespace Luski.net.JsonTypes; public class SocketAppUser : SocketUserBase { [JsonPropertyName("email")] [JsonInclude] public string Email { get; internal set; } = default!; [JsonIgnore] public IReadOnlyList Channels { get { if (_Channels is null || ChannelIdList is not null) { if (ChannelIdList.Length != 0) { _Channels = new List(); foreach (long channel in ChannelIdList) { SocketChannel s = SocketChannel.GetChannel(channel, SocketChannelContext.Default.SocketChannel).Result; Server.chans.Remove(s); switch (s.Type) { case Enums.ChannelType.GROUP: _Channels.Add(SocketChannel.GetChannel(channel, SocketGroupChannelContext.Default.SocketGroupChannel).Result); break; case Enums.ChannelType.DM: _Channels.Add(SocketChannel.GetChannel(channel, SocketDMChannelContext.Default.SocketDMChannel).Result); break; } } } else _Channels = new List(); } return _Channels.AsReadOnly(); } } [JsonIgnore] public IReadOnlyList FriendRequests { get { if (_FriendRequests is null || FriendRequestsRaw is not null) { _FriendRequests = new(); if (ChannelIdList.Length != 0 && FriendRequestsRaw is not null) { foreach (FR person in FriendRequestsRaw) { //_Friends.Add(SocketRemoteUser.GetUser(person)); long id = person.user_id == Id ? person.from : person.user_id; SocketRemoteUser frq = GetUser(id, SocketRemoteUserContext.Default.SocketRemoteUser).Result; _FriendRequests.Add(frq); } } else _FriendRequests = new(); } return _FriendRequests.AsReadOnly(); } } [JsonIgnore] public IReadOnlyList Friends { get { if (_Friends is null || FriendIdList is not null) { if (ChannelIdList.Length != 0) { _Friends = new List(); foreach (long person in FriendIdList) { _Friends.Add(GetUser(person, SocketRemoteUserContext.Default.SocketRemoteUser).Result); } } else _Friends = new List(); } return _Friends.AsReadOnly(); } } [JsonPropertyName("selected_channel")] [JsonInclude] public long SelectedChannel { get; internal set; } = default!; [JsonPropertyName("channels")] [JsonInclude] public long[] ChannelIdList { get; internal set; } = default!; [JsonPropertyName("friends")] [JsonInclude] public long[] FriendIdList { get; internal set; } = default!; [JsonPropertyName("friend_requests")] [JsonInclude] public FR[] FriendRequestsRaw { get; internal set; } = default!; [JsonIgnore] private List _Channels = default!; [JsonIgnore] private List _Friends = default!; [JsonIgnore] private List _FriendRequests = default!; public class FR { public long from { get; set; } = default!; public long user_id { get; set; } = default!; } internal void AddFriend(SocketRemoteUser User) { if (Server.poeople.Any(s => s.Id == User.Id)) { IEnumerable b = Server.poeople.Where(s => s.Id == User.Id); foreach (IUser item in b) { Server.poeople.Remove(item); } Server.poeople.Add(User); } else { Server.poeople.Add(User); } _Friends.Add(User); } internal void RemoveFriendRequest(SocketRemoteUser User) { if (Server.poeople.Any(s => s.Id == User.Id)) { IEnumerable b = Server.poeople.Where(s => s.Id == User.Id); foreach (IUser item in b) { Server.poeople.Remove(item); } } Server.poeople.Add(User); foreach (SocketRemoteUser user in _FriendRequests) { if (User.Id == user.Id) { _FriendRequests.Remove(User); } } } internal void AddFriendRequest(SocketRemoteUser User) { if (Server.poeople.Any(s => s.Id == User.Id)) { IEnumerable b = Server.poeople.Where(s => s.Id == User.Id); foreach (IUser item in b) { Server.poeople.Remove(item); } Server.poeople.Add(User); } else { Server.poeople.Add(User); } _FriendRequests.Add(User); } } [JsonSerializable(typeof(SocketAppUser))] [JsonSourceGenerationOptions( GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.Unspecified, WriteIndented = false, DefaultIgnoreCondition = JsonIgnoreCondition.Never)] internal partial class SocketAppUserContext : JsonSerializerContext { }