48 lines
No EOL
1.7 KiB
Text
48 lines
No EOL
1.7 KiB
Text
@using System.Collections.Specialized
|
|
@using LANCommander.SDK.Services
|
|
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
|
@inject IChatClient ChatClient
|
|
@namespace LANCommander.UI.Components
|
|
|
|
<Flex Direction="FlexDirection.Vertical" Class="chat-thread">
|
|
<Flex Direction="FlexDirection.Vertical" Class="chat-thread-messages">
|
|
@if (_thread != null)
|
|
{
|
|
<Virtualize Items="_thread.MessageGroups" Context="messageGroup">
|
|
<ChatMessageGroup
|
|
@key="messageGroup.Id"
|
|
UserId="@messageGroup.UserId"
|
|
UserName="@messageGroup.UserName"
|
|
StartedOn="@messageGroup.StartedOn.LocalDateTime">
|
|
@foreach (var message in messageGroup.Messages)
|
|
{
|
|
<ChatMessage Id="@message.Id" Content="@message.Content" SentOn="@message.SentOn"/>
|
|
}
|
|
</ChatMessageGroup>
|
|
</Virtualize>
|
|
}
|
|
</Flex>
|
|
|
|
<ChatMessageInput ThreadId="@Id" Placeholder="@($"Message {_thread?.Title}")" />
|
|
</Flex>
|
|
|
|
@code {
|
|
[Parameter] public Guid? Id { get; set; }
|
|
|
|
SDK.Models.ChatThread? _thread;
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if ((_thread == null || _thread.Id != Id) && Id.HasValue)
|
|
{
|
|
_thread = await ChatClient.GetThreadAsync(Id.Value);
|
|
|
|
_thread.MessageGroups.CollectionChanged += MessageGroupsOnCollectionChanged;
|
|
|
|
await ChatClient.GetMessagesAsync(Id.Value);
|
|
}
|
|
}
|
|
|
|
void MessageGroupsOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
|
=> InvokeAsync(StateHasChanged);
|
|
} |