diff --git a/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor b/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor index 65bc7bd..ed9bd99 100644 --- a/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor +++ b/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor @@ -175,15 +175,15 @@ - + - + - + @if (SelectedImagePreview != null) { @@ -207,7 +207,7 @@ } - + @if (RecordedAudioBytes != null) { @@ -223,7 +223,7 @@ } - + @if (IsRecording) { @@ -278,7 +278,7 @@ IBrowserFile? SelectedImageFile = null; byte[]? SelectedImageBytes = null; string? SelectedImagePreview = null; - + // Audio recording properties bool IsRecording = false; string RecordingTime = "00:00"; @@ -287,7 +287,7 @@ string RecordedAudioDuration = "00:00"; private System.Threading.Timer? recordingTimer; private DateTime recordingStartTime; - + bool chatloading = false; public bool IsLogin { get; set; } = false; public bool IsEndFirstProcess { get; set; } = false; @@ -317,7 +317,7 @@ return value; } } - + // Audio recording methods private async Task ToggleAudioRecording() { @@ -330,7 +330,7 @@ await StartAudioRecording(); } } - + private async Task StartAudioRecording() { try @@ -353,7 +353,7 @@ toastService.Notify(new ToastMessage(ToastType.Danger, $"خطا در ضبط صدا: {ex.Message}")); } } - + private async Task StopAudioRecording() { try @@ -366,10 +366,11 @@ RecordedAudioBytes = Convert.FromBase64String(base64Data); RecordedAudioUrl = audioData; RecordedAudioDuration = RecordingTime; - + IsRecording = false; recordingTimer?.Dispose(); recordingTimer = null; + await ClearSelectedImage(); StateHasChanged(); } } @@ -385,14 +386,14 @@ StateHasChanged(); } } - + private void UpdateRecordingTime(object? state) { var elapsed = DateTime.Now - recordingStartTime; RecordingTime = $"{elapsed.Minutes:D2}:{elapsed.Seconds:D2}"; InvokeAsync(StateHasChanged); } - + private Task ClearRecordedAudio() { RecordedAudioBytes = null; @@ -400,17 +401,17 @@ RecordedAudioDuration = "00:00"; return Task.CompletedTask; } - + private string GetAudioDataUrl(string? fileType, byte[]? content) => (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; @@ -428,7 +429,7 @@ { Common.Enums.ConversationType type = Common.Enums.ConversationType.UE; ChatItemResponseDto? model; - + if (SelectedImageFile != null) { var bytes = SelectedImageBytes ?? Array.Empty(); @@ -456,7 +457,7 @@ { model = await chatService.ADDChatResponse(LastOpenChat.ID, MsgInput, type); } - + LastOpenChat?.Responses.Add(model); LastOpenChat.LastText = MsgInput; @@ -486,7 +487,7 @@ SelectedImageFile = null; SelectedImageBytes = null; SelectedImagePreview = null; - + // Clear recorded audio after sending RecordedAudioBytes = null; RecordedAudioUrl = null; @@ -701,6 +702,7 @@ await file.OpenReadStream().CopyToAsync(memoryStream); SelectedImageBytes = memoryStream.ToArray(); SelectedImagePreview = $"data:{file.ContentType};base64,{Convert.ToBase64String(SelectedImageBytes)}"; + await ClearRecordedAudio(); } private Task ClearSelectedImage()