First commit

This commit is contained in:
2026-08-28 04:03:32 +03:00
commit 311bd61912
16 changed files with 557 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
using System.Collections.ObjectModel;
using AMessanger.Services;
using CommunityToolkit.Mvvm.ComponentModel;
using Avalonia.Threading;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
using System.Diagnostics;
namespace AMessanger.ViewModels;
public partial class MainViewModel : ViewModelBase
{
[ObservableProperty]
public partial ObservableCollection<string> Messages { get; private set; } = new();
[ObservableProperty]
public partial string Message { get; set; } = string.Empty;
[ObservableProperty]
public partial string UserName { get; set; } = "Test user";
public ICommand SendButtonCommand { get; private set; }
private readonly ChatService _chat;
public MainViewModel(ChatService chatService)
{
_chat = chatService;
_chat.OnMessageRecieved += OnMessageRecived;
SendButtonCommand = new RelayCommand(SendMessage);
}
private void OnMessageRecived(string user, string message)
{
Dispatcher.UIThread.Post(() => Messages.Add($"{user}: {message}"));
Debug.WriteLine($"{user}: {message}");
}
private void SendMessage()
{
if (string.IsNullOrWhiteSpace(Message))
return;
_chat.SendMessageAsync(UserName, Message.Trim());
Message = string.Empty;
}
}
+7
View File
@@ -0,0 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
namespace AMessanger.ViewModels;
public abstract class ViewModelBase : ObservableObject
{
}