@page "/Conversation" @page "/" @inject IJSRuntime JS @using Common.Dtos.Conversation @using HushianWebApp.Models @using HushianWebApp.Service @using HushianWebApp.Services @inject ILocalStorageService localStorageService; @inject NavigationManager navigationManager; @inject ConversationService conversationService; @Content
گفتگو های اخیر
@if (isSelectedInbox1) { @foreach (var item in Inbox1Items) {
@item.UserFullName @item.LastMsgdate @item.LastMsgtime
@item.LastText
@if (item.NoReadCount > 0) { @item.NoReadCount }
} } @if (isSelectedInbox2) { @foreach (var item in Inbox2Items) {
@item.UserFullName @item.LastMsgdate @item.LastMsgtime
@item.LastText
@if (item.NoReadCount>0) { @item.NoReadCount }
} } @if (isSelectedInbox3) { @foreach (var item in Inbox3Items) {
@item.UserFullName @item.LastMsgdate @item.LastMsgtime
@item.LastText
} }
@if (maximomeallowsize < width) { @Content }
@code { private Modal modal = default!; int maximomeallowsize = 700; private int width; private int height; public RenderFragment Content { get; set; } private DotNetObjectReference? objRef; int colmdB = 9; bool chatloading = false; bool convloading = false; public string MsgInput { get; set; } bool isSelectedInbox1 = false; bool isSelectedInbox2 = true; bool isSelectedInbox3 = false; public int countInbox1 { get { return Inbox1Items.Count(); } } public int countInbox2 { get { return Inbox2Items.Count(); } } public List Inbox1Items { get; set; } = new() ; public List Inbox2Items { get; set; } = new(); public List Inbox3Items { get; set; } = new(); public Read_ConversationDto? SelectedConversation { get; set; } = null; public List? SelectedConversationItems { get; set; } = null; public string SelectedChatUserName { get; set; } = "مهدی ربیع نژاد"; public string Role { get; set; } public int UserID = 0; async Task OnclickInbox(int ID) { switch (ID) { case 1: isSelectedInbox1 = true; isSelectedInbox2 = false; isSelectedInbox3 = false; break; case 2: isSelectedInbox2 = true; isSelectedInbox1 = false; isSelectedInbox3 = false; break; case 3: isSelectedInbox3 = true; isSelectedInbox2 = false; isSelectedInbox1 = false; break; } SelectedConversation = null; SelectedConversationItems = null; } async Task SendMsg() { if (!string.IsNullOrEmpty(MsgInput) && SelectedConversationItems!=null) { await conversationService.ADDConversationItem(SelectedConversationItems[0].ConversationID, MsgInput, Role=="Company" ? Common.Enums.ConversationType.CU : Common.Enums.ConversationType.EU); SelectedConversationItems?.Add(new() { text = MsgInput, Type = Common.Enums.ConversationType.EU }); SelectedConversation.LastText = MsgInput; await Task.Yield(); await JS.InvokeVoidAsync("scrollToBottom", "B1"); MsgInput = string.Empty; } } private async Task HandleKeyDown(KeyboardEventArgs e) { if (e.Key == "Enter") { await SendMsg(); } } async Task onClickSelectedCon(int InboxID,Read_ConversationDto conversationDto) { // پر کردن SelectedCon // مقدار دادن به SelectedChatUserName chatloading = true; SelectedChatUserName = "در حال گفتگو با "+ conversationDto.UserFullName; SelectedConversation = conversationDto; SelectedConversationItems = await conversationService.GetConversationItems(conversationDto.ID); chatloading = false; if (maximomeallowsize > width) { //await LoadSessionB(12); await modal.ShowAsync(); } } } @functions{ protected override async Task OnInitializedAsync() { Role = await localStorageService.GetItem("C/Role"); UserID= await localStorageService.GetItem("C/UserID"); convloading = true; await LoadSessionB(); Inbox1Items =await conversationService.ConversationAwaitingOurResponse(); Inbox2Items =await conversationService.MyConversationIsInProgress(); Inbox3Items =await conversationService.MyConversationIsFinished(); convloading = false; await base.OnInitializedAsync(); } async Task IsrEADaCTION(int id) { if( await conversationService.MarkAsReadConversationItemAsync(id)) { if (isSelectedInbox1) Inbox1Items = await conversationService.ConversationAwaitingOurResponse(); else if (isSelectedInbox2) Inbox2Items = await conversationService.MyConversationIsInProgress(); else { Inbox1Items = await conversationService.ConversationAwaitingOurResponse(); Inbox2Items = await conversationService.MyConversationIsInProgress(); } } } protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { objRef = DotNetObjectReference.Create(this); await JS.InvokeVoidAsync("registerResizeCallback", objRef); await GetWindowSize(); } } [JSInvokable] public async Task OnResize() { await GetWindowSize(); if (maximomeallowsize < width) { await modal.HideAsync(); await LoadSessionB(9); } else await LoadSessionB(12); StateHasChanged(); } private async Task GetWindowSize() { var size = await JS.InvokeAsync("getWindowSize"); width = size.Width; height = size.Height; } async Task LoadSessionB(int md=9) { Content = @
@if (SelectedConversation!=null) {

@SelectedChatUserName

@if ( SelectedConversation.status==Common.Enums.ConversationStatus.InProgress) { } else if (SelectedConversation.status == Common.Enums.ConversationStatus.Finished && (Role=="Company" || SelectedConversation.ExperID == UserID)) { } }
@if (SelectedConversationItems != null) { } else {

هوشیان

}
@if (SelectedConversation != null && SelectedConversation.status!=Common.Enums.ConversationStatus.Finished && SelectedConversationItems != null) {
}
; } }