...
This commit is contained in:
@@ -236,9 +236,7 @@
|
||||
<source src="@GetAudioDataUrl(msg.FileType, msg.FileContent)" type="@msg.FileType">
|
||||
مرورگر شما از پخش صدا پشتیبانی نمیکند.
|
||||
</audio>
|
||||
<div class="audio-info">
|
||||
<small class="text-muted">@GetAudioDuration(msg.FileContent)</small>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
}
|
||||
@if (!string.IsNullOrWhiteSpace(msg.text))
|
||||
@@ -488,16 +486,55 @@
|
||||
}
|
||||
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;
|
||||
var geter= await chatService.ADDChatResponse(ChatCurrent.ID, MsgInput, type);
|
||||
if(geter!=null)
|
||||
{ChatCurrent?.Responses.Add(geter);
|
||||
ChatItemResponseDto? model=null;
|
||||
if (SelectedImageFile != null)
|
||||
{
|
||||
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;
|
||||
await Task.Yield();
|
||||
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)
|
||||
@@ -605,18 +642,7 @@
|
||||
=> (string.IsNullOrWhiteSpace(fileType) || content == null || content.Length == 0)
|
||||
? string.Empty
|
||||
: $"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
|
||||
private async Task ToggleAudioRecording()
|
||||
|
Reference in New Issue
Block a user