mirror of
https://github.com/Stone-Red-Code/Decho.git
synced 2026-09-04 00:46:11 +02:00
72 lines
1.8 KiB
C#
72 lines
1.8 KiB
C#
using Avalonia.Media;
|
|
|
|
using EchoHub.Core.DTOs;
|
|
using EchoHub.Core.Models;
|
|
|
|
namespace Decho.ViewModels;
|
|
|
|
public sealed class UserViewModel(UserPresenceDto dto) : ViewModelBase
|
|
{
|
|
public string Username { get; } = dto.Username;
|
|
public string DisplayName { get; } = dto.DisplayName ?? dto.Username;
|
|
public string? NicknameColor { get; } = dto.NicknameColor;
|
|
public string? StatusMessage { get; } = dto.StatusMessage;
|
|
public ServerRole Role { get; } = dto.Role;
|
|
|
|
public UserStatus Status
|
|
{
|
|
get;
|
|
set
|
|
{
|
|
if (field == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
field = value;
|
|
this.RaisePropertyChanged();
|
|
this.RaisePropertyChanged(nameof(StatusColor));
|
|
this.RaisePropertyChanged(nameof(StatusText));
|
|
}
|
|
} = dto.Status;
|
|
|
|
public string FullName => DisplayName ?? Username;
|
|
|
|
public IBrush? DisplayColor
|
|
{
|
|
get
|
|
{
|
|
if (string.IsNullOrEmpty(NicknameColor))
|
|
{
|
|
return Brushes.White;
|
|
}
|
|
|
|
try
|
|
{
|
|
return new SolidColorBrush(Color.Parse(NicknameColor));
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public string StatusColor => Status switch
|
|
{
|
|
UserStatus.Online => "#4CAF50",
|
|
UserStatus.Away => "#FF9800",
|
|
UserStatus.DoNotDisturb => "#E53935",
|
|
UserStatus.Invisible => "#9E9E9E",
|
|
_ => "#9E9E9E",
|
|
};
|
|
|
|
public string StatusText => Status switch
|
|
{
|
|
UserStatus.Online => "Online",
|
|
UserStatus.Away => "Away",
|
|
UserStatus.DoNotDisturb => "Do Not Disturb",
|
|
UserStatus.Invisible => "Invisible",
|
|
_ => "Offline",
|
|
};
|
|
} |