Files
Hushian/Presentation/HushianWebApp/Components/Base/ChatBubble.razor

102 lines
2.7 KiB
Plaintext
Raw Normal View History

2025-07-12 21:33:44 +03:30
@using Common.Dtos.Conversation
2025-07-11 20:37:28 +03:30
@inject IJSRuntime JSRuntime
<div class="chat-container p-3">
@foreach (var msg in Messages)
{
2025-07-12 21:33:44 +03:30
@if (!target && ((!msg.IsRead && msg.Type == Common.Enums.ConversationType.UE) || Messages.Last() == msg))
2025-07-11 20:37:28 +03:30
{
target = true;
<div id="target" style="text-align: center;">
2025-07-12 21:33:44 +03:30
@if (!msg.IsRead && msg.Type == Common.Enums.ConversationType.UE)
2025-07-11 20:37:28 +03:30
{
<p>ـــــــــــــــــــــــــ</p>
}
</div>
}
2025-07-12 21:33:44 +03:30
<div class="d-flex mb-2 @(msg.Type==Common.Enums.ConversationType.UE ? "justify-content-end" : "justify-content-start")">
<div class="chat-bubble @(msg.Type==Common.Enums.ConversationType.UE ? "chat-mine"
: "chat-other")" data-id="@msg.ID">
2025-07-11 20:37:28 +03:30
@msg.text
</div>
2025-07-12 21:33:44 +03:30
@if (msg.Type == Common.Enums.ConversationType.EU)
2025-07-11 20:37:28 +03:30
{
if (msg.IsRead)
{
<Icon Style="align-self: self-end;" Name="IconName.CheckAll" Size="IconSize.x5" Color="IconColor.Success" />
}
else
{
<Icon Style="align-self: self-end;" Name="IconName.CheckLg" Size="IconSize.x5" />
}
}
</div>
}
</div>
<style>
.chat-bubble {
padding: 0.5rem 0.75rem;
border-radius: 1rem;
max-width: 75%;
word-wrap: break-word;
white-space: pre-wrap;
}
.chat-mine {
background: linear-gradient(to right, #005eff, #267fff);
color: white;
border-top-left-radius: 0;
}
.chat-other {
background-color: #f1f1f1;
color: #333;
border-top-right-radius: 0;
}
.chat-ai {
background-color: #f1f1f1;
color: #353;
border-top-right-radius: 0;
}
</style>
@code {
bool target = false;
[Parameter]
2025-07-12 21:33:44 +03:30
public List<Read_ConversationResponseDto> Messages { get; set; } = new();
2025-07-11 20:37:28 +03:30
[Parameter] public EventCallback<int> EventCallIsRead { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JSRuntime.InvokeVoidAsync("observeVisibility", DotNetObjectReference.Create(this));
await JSRuntime.InvokeVoidAsync("scrollToTarget");
}
}
[JSInvokable]
public async Task MarkAsRead(int id)
{
var msg = Messages.FirstOrDefault(m => m.ID == id);
2025-07-12 21:33:44 +03:30
if (msg != null && !msg.IsRead && msg.Type==Common.Enums.ConversationType.UE)
2025-07-11 20:37:28 +03:30
{
msg.IsRead = true;
await EventCallIsRead.InvokeAsync(id);
}
await Task.CompletedTask;
}
}