Use attachment description as alt text in html

Closes #805
This commit is contained in:
Oleksii Holub 2022-04-09 02:52:57 +03:00
parent 489c786c1e
commit 71876febf8
3 changed files with 7 additions and 5 deletions

View file

@ -42,7 +42,7 @@ public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixtur
Snowflake.Parse("885654862656843786")
);
var imageUrl = message.QuerySelector("img[alt*=\"attachment\" i]")?.GetAttribute("src");
var imageUrl = message.QuerySelector(".chatlog__attachment img")?.GetAttribute("src");
// Assert
message.Text().Should().Contain("Image attachment");

View file

@ -13,6 +13,7 @@ public partial record Attachment(
Snowflake Id,
string Url,
string FileName,
string? Description,
int? Width,
int? Height,
FileSize FileSize) : IHasId
@ -37,8 +38,9 @@ public partial record Attachment
var width = json.GetPropertyOrNull("width")?.GetInt32OrNull();
var height = json.GetPropertyOrNull("height")?.GetInt32OrNull();
var fileName = json.GetProperty("filename").GetNonNullString();
var description = json.GetPropertyOrNull("description")?.GetNonWhiteSpaceStringOrNull();
var fileSize = json.GetProperty("size").GetInt64().Pipe(FileSize.FromBytes);
return new Attachment(id, url, fileName, width, height, fileSize);
return new Attachment(id, url, fileName, description, width, height, fileSize);
}
}

View file

@ -158,19 +158,19 @@
@if (attachment.IsImage)
{
<a href="@await ResolveUrlAsync(attachment.Url)">
<img class="chatlog__attachment-media" src="@await ResolveUrlAsync(attachment.Url)" alt="Image attachment" title="Image: @attachment.FileName (@attachment.FileSize)" loading="lazy">
<img class="chatlog__attachment-media" src="@await ResolveUrlAsync(attachment.Url)" alt="@(attachment.Description ?? "Image attachment")" title="Image: @attachment.FileName (@attachment.FileSize)" loading="lazy">
</a>
}
else if (attachment.IsVideo)
{
<video class="chatlog__attachment-media" controls>
<source src="@await ResolveUrlAsync(attachment.Url)" alt="Video attachment" title="Video: @attachment.FileName (@attachment.FileSize)">
<source src="@await ResolveUrlAsync(attachment.Url)" alt="@(attachment.Description ?? "Video attachment")" title="Video: @attachment.FileName (@attachment.FileSize)">
</video>
}
else if (attachment.IsAudio)
{
<audio class="chatlog__attachment-media" controls>
<source src="@await ResolveUrlAsync(attachment.Url)" alt="Audio attachment" title="Audio: @attachment.FileName (@attachment.FileSize)">
<source src="@await ResolveUrlAsync(attachment.Url)" alt="@(attachment.Description ?? "Audio attachment")" title="Audio: @attachment.FileName (@attachment.FileSize)">
</audio>
}
else