45 lines
956 B
C#
45 lines
956 B
C#
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<ChatViewModel>();
|
|
_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);
|
|
}
|
|
}
|
|
}
|