using Massenger.Client.Services; using Massenger.Client.ViewModels; namespace Massenger.Client.Pages; [QueryProperty(nameof(ChatId), "chatId")] public partial class ChatPage : ContentPage { private readonly ChatViewModel _viewModel; private string? _chatId; public string? ChatId { get => _chatId; set { _chatId = value; _ = LoadChatAsync(value); } } public ChatPage() { InitializeComponent(); _viewModel = ServiceHelper.GetRequiredService(); _viewModel.AttachRealtime(); BindingContext = _viewModel; } protected override void OnDisappearing() { base.OnDisappearing(); _viewModel.DetachRealtime(); } private async Task LoadChatAsync(string? chatId) { if (Guid.TryParse(chatId, out var parsed)) { await _viewModel.LoadAsync(parsed); } } }