...
This commit is contained in:
@@ -221,11 +221,26 @@
|
||||
<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">
|
||||
@if (msg.FileContent != null && msg.FileContent.Length > 0 && !string.IsNullOrWhiteSpace(msg.FileType) && msg.FileType.StartsWith("image/"))
|
||||
@if (msg.FileContent != null && msg.FileContent.Length > 0 && !string.IsNullOrWhiteSpace(msg.FileType))
|
||||
{
|
||||
<a href="@GetImageDataUrl(msg.FileType, msg.FileContent)" download="@GetDownloadFileName(msg.FileName, msg.FileType)" title="دانلود تصویر" style="display:inline-block">
|
||||
<img src="@GetImageDataUrl(msg.FileType, msg.FileContent)" alt="image" style="max-width: 220px; border-radius: 8px; display: block; cursor: pointer;" />
|
||||
</a>
|
||||
@if (msg.FileType.StartsWith("image/"))
|
||||
{
|
||||
<a href="@GetImageDataUrl(msg.FileType, msg.FileContent)" download="@GetDownloadFileName(msg.FileName, msg.FileType)" title="دانلود تصویر" style="display:inline-block">
|
||||
<img src="@GetImageDataUrl(msg.FileType, msg.FileContent)" alt="image" style="max-width: 220px; border-radius: 8px; display: block; cursor: pointer;" />
|
||||
</a>
|
||||
}
|
||||
else if (msg.FileType.StartsWith("audio/"))
|
||||
{
|
||||
<div class="audio-message">
|
||||
<audio controls style="max-width: 250px;">
|
||||
<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))
|
||||
{
|
||||
<div style="margin-top:6px">@msg.text</div>
|
||||
@@ -374,7 +389,6 @@
|
||||
await JS.InvokeVoidAsync("scrollToTarget");
|
||||
}
|
||||
}
|
||||
|
||||
async Task OnclickInbox(int ID)
|
||||
{
|
||||
switch (ID)
|
||||
@@ -508,7 +522,6 @@
|
||||
=> (string.IsNullOrWhiteSpace(fileType) || content == null || content.Length == 0)
|
||||
? string.Empty
|
||||
: $"data:{fileType};base64,{Convert.ToBase64String(content)}";
|
||||
|
||||
private static string GetDownloadFileName(string? fileName, string? fileType)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(fileName)) return fileName;
|
||||
@@ -519,6 +532,22 @@
|
||||
}
|
||||
return $"image_{DateTimeOffset.Now.ToUnixTimeSeconds()}{ext}";
|
||||
}
|
||||
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;
|
||||
var minutes = durationSeconds / 60;
|
||||
var seconds = durationSeconds % 60;
|
||||
return $"{minutes:D2}:{seconds:D2}";
|
||||
}
|
||||
}
|
||||
|
||||
<style>
|
||||
|
Reference in New Issue
Block a user