init
This commit is contained in:
commit
f25ba8adcd
64 changed files with 5959 additions and 0 deletions
126
src/GsDChat.Client/State/ClientState.cs
Normal file
126
src/GsDChat.Client/State/ClientState.cs
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GsDChat.Core.Models;
|
||||
using GsDChat.Core.Protocol;
|
||||
|
||||
namespace GsDChat.Client.State;
|
||||
|
||||
public class ClientState
|
||||
{
|
||||
private readonly object _lock = new();
|
||||
|
||||
public string ServerUrl { get; set; } = "http://localhost:5000";
|
||||
public string Token { get; set; } = string.Empty;
|
||||
public string CurrentUserId { get; set; } = string.Empty;
|
||||
public string CurrentUsername { get; set; } = string.Empty;
|
||||
public string CurrentUserRole { get; set; } = UserRoles.Member;
|
||||
|
||||
public string ServerName { get; set; } = "GsDChat Server";
|
||||
public string Motd { get; set; } = string.Empty;
|
||||
public ServerUiSync UiSync { get; set; } = ServerUiSync.CreateDefault();
|
||||
|
||||
public string ActiveScreenId { get; set; } = "F1_Chat";
|
||||
public string ActiveChannelId { get; set; } = string.Empty;
|
||||
|
||||
public List<Channel> Channels { get; } = new();
|
||||
public Dictionary<string, List<ChatMessage>> ChannelMessages { get; } = new();
|
||||
public List<UserSummary> Users { get; } = new();
|
||||
public List<FileSummary> Files { get; } = new();
|
||||
public List<string> SystemNotices { get; } = new();
|
||||
|
||||
public int ChatScrollOffset { get; set; } = 0;
|
||||
public string InputBuffer { get; set; } = string.Empty;
|
||||
public bool NeedsRedraw { get; set; } = true;
|
||||
public bool IsConnected { get; set; } = false;
|
||||
public string StatusMessage { get; set; } = string.Empty;
|
||||
public DateTime StatusMessageUntil { get; set; } = DateTime.MinValue;
|
||||
|
||||
public Channel? ActiveChannel
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return Channels.FirstOrDefault(c => c.Id == ActiveChannelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetStatus(string message, int durationSeconds = 5)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
StatusMessage = message;
|
||||
StatusMessageUntil = DateTime.UtcNow.AddSeconds(durationSeconds);
|
||||
NeedsRedraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddNotice(string text)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
SystemNotices.Add($"[{DateTime.Now:HH:mm:ss}] {text}");
|
||||
if (SystemNotices.Count > 100) SystemNotices.RemoveAt(0);
|
||||
NeedsRedraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddChatMessage(ChatMessage message)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (!ChannelMessages.TryGetValue(message.ChannelId, out var list))
|
||||
{
|
||||
list = new List<ChatMessage>();
|
||||
ChannelMessages[message.ChannelId] = list;
|
||||
}
|
||||
list.Add(message);
|
||||
NeedsRedraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetHistory(string channelId, List<ChatMessage> messages)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
ChannelMessages[channelId] = messages;
|
||||
NeedsRedraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateChannels(List<Channel> channels, string activeId)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
Channels.Clear();
|
||||
Channels.AddRange(channels);
|
||||
if (!string.IsNullOrEmpty(activeId))
|
||||
{
|
||||
ActiveChannelId = activeId;
|
||||
}
|
||||
NeedsRedraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateUsers(List<UserSummary> users)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
Users.Clear();
|
||||
Users.AddRange(users);
|
||||
NeedsRedraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateFiles(List<FileSummary> files)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
Files.Clear();
|
||||
Files.AddRange(files);
|
||||
NeedsRedraw = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue