...
This commit is contained in:
@@ -236,9 +236,7 @@
|
|||||||
<source src="@GetAudioDataUrl(msg.FileType, msg.FileContent)" type="@msg.FileType">
|
<source src="@GetAudioDataUrl(msg.FileType, msg.FileContent)" type="@msg.FileType">
|
||||||
مرورگر شما از پخش صدا پشتیبانی نمیکند.
|
مرورگر شما از پخش صدا پشتیبانی نمیکند.
|
||||||
</audio>
|
</audio>
|
||||||
<div class="audio-info">
|
|
||||||
<small class="text-muted">@GetAudioDuration(msg.FileContent)</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@if (!string.IsNullOrWhiteSpace(msg.text))
|
@if (!string.IsNullOrWhiteSpace(msg.text))
|
||||||
@@ -488,16 +486,55 @@
|
|||||||
}
|
}
|
||||||
async Task OnClickSendMsg()
|
async Task OnClickSendMsg()
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(MsgInput) && ChatCurrent != null)
|
if ((!string.IsNullOrEmpty(MsgInput) || SelectedImageFile != null || RecordedAudioBytes != null)
|
||||||
|
&& ChatCurrent != null)
|
||||||
{
|
{
|
||||||
Common.Enums.ConversationType type = CurrentUser.Role == "Company" ? Common.Enums.ConversationType.CU : Common.Enums.ConversationType.EU;
|
Common.Enums.ConversationType type = CurrentUser.Role == "Company" ? Common.Enums.ConversationType.CU : Common.Enums.ConversationType.EU;
|
||||||
var geter= await chatService.ADDChatResponse(ChatCurrent.ID, MsgInput, type);
|
ChatItemResponseDto? model=null;
|
||||||
if(geter!=null)
|
if (SelectedImageFile != null)
|
||||||
{ChatCurrent?.Responses.Add(geter);
|
{
|
||||||
|
var bytes = SelectedImageBytes ?? Array.Empty<byte>();
|
||||||
|
model = await chatService.ADDChatResponse(
|
||||||
|
ChatCurrent.ID,
|
||||||
|
MsgInput,
|
||||||
|
type,
|
||||||
|
SelectedImageFile.Name,
|
||||||
|
SelectedImageFile.ContentType,
|
||||||
|
bytes);
|
||||||
|
}
|
||||||
|
else if (RecordedAudioBytes != null)
|
||||||
|
{
|
||||||
|
// Send audio message
|
||||||
|
var fileName = $"audio_{DateTimeOffset.Now.ToUnixTimeSeconds()}.wav";
|
||||||
|
model = await chatService.ADDChatResponse(
|
||||||
|
ChatCurrent.ID,
|
||||||
|
MsgInput,
|
||||||
|
type,
|
||||||
|
fileName,
|
||||||
|
"audio/wav",
|
||||||
|
RecordedAudioBytes);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
model = await chatService.ADDChatResponse(ChatCurrent.ID, MsgInput, type);
|
||||||
|
}
|
||||||
|
if(model!=null)
|
||||||
|
{
|
||||||
|
ChatCurrent?.Responses.Add(model);
|
||||||
ChatCurrent.LastText = MsgInput;
|
ChatCurrent.LastText = MsgInput;
|
||||||
await Task.Yield();
|
await Task.Yield();
|
||||||
await JS.InvokeVoidAsync("scrollToBottom", "B1");
|
await JS.InvokeVoidAsync("scrollToBottom", "B1");
|
||||||
MsgInput = string.Empty;}
|
MsgInput = string.Empty;
|
||||||
|
SelectedImageFile = null;
|
||||||
|
SelectedImageBytes = null;
|
||||||
|
SelectedImagePreview = null;
|
||||||
|
|
||||||
|
// Clear recorded audio after sending
|
||||||
|
RecordedAudioBytes = null;
|
||||||
|
RecordedAudioUrl = null;
|
||||||
|
RecordedAudioDuration = "00:00";
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async Task onClickSelectedChat(int InboxID, ChatItemDto chatItem)
|
async Task onClickSelectedChat(int InboxID, ChatItemDto chatItem)
|
||||||
@@ -605,18 +642,7 @@
|
|||||||
=> (string.IsNullOrWhiteSpace(fileType) || content == null || content.Length == 0)
|
=> (string.IsNullOrWhiteSpace(fileType) || content == null || content.Length == 0)
|
||||||
? string.Empty
|
? string.Empty
|
||||||
: $"data:{fileType};base64,{Convert.ToBase64String(content)}";
|
: $"data:{fileType};base64,{Convert.ToBase64String(content)}";
|
||||||
private string GetAudioDuration(byte[]? content)
|
|
||||||
{
|
|
||||||
// Simple duration calculation based on file size (approximate)
|
|
||||||
if (content == null || content.Length == 0) return "00:00";
|
|
||||||
|
|
||||||
// Assuming 16-bit PCM at 44.1kHz, mono
|
|
||||||
var bytesPerSecond = 44100 * 2; // 44.1kHz * 2 bytes per sample
|
|
||||||
var durationSeconds = content.Length / bytesPerSecond;
|
|
||||||
var minutes = durationSeconds / 60;
|
|
||||||
var seconds = durationSeconds % 60;
|
|
||||||
return $"{minutes:D2}:{seconds:D2}";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Audio recording methods
|
// Audio recording methods
|
||||||
private async Task ToggleAudioRecording()
|
private async Task ToggleAudioRecording()
|
||||||
|
@@ -93,9 +93,6 @@
|
|||||||
<source src="@GetAudioDataUrl(msg.FileType, msg.FileContent)" type="@msg.FileType">
|
<source src="@GetAudioDataUrl(msg.FileType, msg.FileContent)" type="@msg.FileType">
|
||||||
مرورگر شما از پخش صدا پشتیبانی نمیکند.
|
مرورگر شما از پخش صدا پشتیبانی نمیکند.
|
||||||
</audio>
|
</audio>
|
||||||
<div class="audio-info">
|
|
||||||
<small class="text-muted">@GetAudioDuration(msg.FileContent)</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@if (!string.IsNullOrWhiteSpace(msg.text))
|
@if (!string.IsNullOrWhiteSpace(msg.text))
|
||||||
@@ -302,7 +299,7 @@
|
|||||||
value += "/" + CompanyGroups.FirstOrDefault(f => f.ID == GroupID.GetValueOrDefault()).Name;
|
value += "/" + CompanyGroups.FirstOrDefault(f => f.ID == GroupID.GetValueOrDefault()).Name;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (LastOpenChat != null)
|
if (LastOpenChat != null && LastOpenChat.Responses!=null)
|
||||||
{
|
{
|
||||||
var model = LastOpenChat.Responses.OrderBy(o => o.ID).LastOrDefault(l => l.Type != Common.Enums.ConversationType.UE);
|
var model = LastOpenChat.Responses.OrderBy(o => o.ID).LastOrDefault(l => l.Type != Common.Enums.ConversationType.UE);
|
||||||
|
|
||||||
@@ -407,18 +404,6 @@
|
|||||||
? string.Empty
|
? string.Empty
|
||||||
: $"data:{fileType};base64,{Convert.ToBase64String(content)}";
|
: $"data:{fileType};base64,{Convert.ToBase64String(content)}";
|
||||||
|
|
||||||
private string GetAudioDuration(byte[]? content)
|
|
||||||
{
|
|
||||||
// Simple duration calculation based on file size (approximate)
|
|
||||||
if (content == null || content.Length == 0) return "00:00";
|
|
||||||
|
|
||||||
// Assuming 16-bit PCM at 44.1kHz, mono
|
|
||||||
var bytesPerSecond = 44100 * 2; // 44.1kHz * 2 bytes per sample
|
|
||||||
var durationSeconds = content.Length / bytesPerSecond;
|
|
||||||
var minutes = durationSeconds / 60;
|
|
||||||
var seconds = durationSeconds % 60;
|
|
||||||
return $"{minutes:D2}:{seconds:D2}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@functions {
|
@functions {
|
||||||
async Task OnClickSendMsg()
|
async Task OnClickSendMsg()
|
||||||
|
@@ -67,6 +67,7 @@ namespace HushianWebApp.Service
|
|||||||
public async Task<ChatItemResponseDto?> ADDChatResponse(int conversationID, string text, ConversationType type,
|
public async Task<ChatItemResponseDto?> ADDChatResponse(int conversationID, string text, ConversationType type,
|
||||||
string? fileName, string? fileType, byte[]? fileContent)
|
string? fileName, string? fileType, byte[]? fileContent)
|
||||||
{
|
{
|
||||||
|
if (text == null) text = "";
|
||||||
var response = await _baseController.Post($"{BaseRoute}ADDChatResponse", new ADD_ConversationResponseDto()
|
var response = await _baseController.Post($"{BaseRoute}ADDChatResponse", new ADD_ConversationResponseDto()
|
||||||
{
|
{
|
||||||
ConversationID = conversationID,
|
ConversationID = conversationID,
|
||||||
|
Reference in New Issue
Block a user