spec compliance around filenames
This commit is contained in:
parent
a14a7dd5c5
commit
3cfe6a3681
4 changed files with 31 additions and 10 deletions
|
|
@ -43,11 +43,10 @@ class ComposerDraftController(final ComposerParams composer)
|
||||||
final (:commands, :text) = TextCommand.parse(
|
final (:commands, :text) = TextCommand.parse(
|
||||||
event?.localContent?.editSource ??
|
event?.localContent?.editSource ??
|
||||||
switch (content) {
|
switch (content) {
|
||||||
TextMessageContent(:final body) ||
|
TextMessageContent(:final body) => body,
|
||||||
ImageMessageContent(:final body) ||
|
// Media's body is its filename unless it has a caption
|
||||||
VideoMessageContent(:final body) ||
|
final MessageContent content when content.isMedia =>
|
||||||
AudioMessageContent(:final body) ||
|
content.caption ?? "",
|
||||||
FileMessageContent(:final body) => body,
|
|
||||||
_ => "",
|
_ => "",
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -75,7 +74,7 @@ class ComposerDraftController(final ComposerParams composer)
|
||||||
)
|
)
|
||||||
.set(
|
.set(
|
||||||
content is MessageContent && content.isMedia
|
content is MessageContent && content.isMedia
|
||||||
? (content.filename ?? content.body ?? "Attachment", content)
|
? (content.displayFilename ?? "Attachment", content)
|
||||||
: null,
|
: null,
|
||||||
);
|
);
|
||||||
_botCommand.clear();
|
_botCommand.clear();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import "package:nexus/models/content/message.dart";
|
import "package:nexus/models/content/message.dart";
|
||||||
|
import "package:nexus/helpers/extensions/is_media.dart";
|
||||||
|
|
||||||
extension GetFilename on MessageContent {
|
extension GetFilename on MessageContent {
|
||||||
String? get filename => switch (this) {
|
String? get filename => switch (this) {
|
||||||
|
|
@ -8,4 +9,16 @@ extension GetFilename on MessageContent {
|
||||||
FileMessageContent(:final filename) => filename,
|
FileMessageContent(:final filename) => filename,
|
||||||
_ => null,
|
_ => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// The file's name. Per the spec, the body is the filename if there's no
|
||||||
|
/// separate filename.
|
||||||
|
String? get displayFilename => isMedia ? filename ?? body : null;
|
||||||
|
|
||||||
|
/// The caption of media, or the body of other messages. Per the spec, the
|
||||||
|
/// body of media is only a caption if there's a different filename.
|
||||||
|
String? get caption => switch (filename) {
|
||||||
|
_ when !isMedia => body,
|
||||||
|
final filename? when filename != body => body,
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,9 @@ class const MessageRenderer(
|
||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
overflow: maxLines == null ? null : .ellipsis,
|
overflow: maxLines == null ? null : .ellipsis,
|
||||||
)
|
)
|
||||||
|
// Media without a caption has its filename as its body
|
||||||
|
: content.caption == null
|
||||||
|
? SizedBox.shrink()
|
||||||
: format == .html && formattedBody != null
|
: format == .html && formattedBody != null
|
||||||
? Html(
|
? Html(
|
||||||
roomId: event.roomId,
|
roomId: event.roomId,
|
||||||
|
|
@ -120,7 +123,7 @@ class const MessageRenderer(
|
||||||
formattedBody.linkifiedHtml,
|
formattedBody.linkifiedHtml,
|
||||||
)
|
)
|
||||||
: LinkifiedText(
|
: LinkifiedText(
|
||||||
body.isEmpty ? content.filename ?? "" : body,
|
body,
|
||||||
roomId: event.roomId,
|
roomId: event.roomId,
|
||||||
style: textStyle,
|
style: textStyle,
|
||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
|
|
@ -136,7 +139,7 @@ class const MessageRenderer(
|
||||||
if (event.lastEditRowId != 0)
|
if (event.lastEditRowId != 0)
|
||||||
Text("(edited)", style: theme.textTheme.labelSmall),
|
Text("(edited)", style: theme.textTheme.labelSmall),
|
||||||
|
|
||||||
if (linkify(body)
|
if (linkify(content.caption ?? "")
|
||||||
.firstWhereOrNull((element) => element is UrlElement)
|
.firstWhereOrNull((element) => element is UrlElement)
|
||||||
case final UrlElement link?)
|
case final UrlElement link?)
|
||||||
if (Uri.tryParse(link.url) case final Uri url?) UrlPreview(url),
|
if (Uri.tryParse(link.url) case final Uri url?) UrlPreview(url),
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,14 @@ final class const MessageMedia(final MessageContent content, {super.key})
|
||||||
encrypted: file != null,
|
encrypted: file != null,
|
||||||
filename: filename ?? body,
|
filename: filename ?? body,
|
||||||
),
|
),
|
||||||
FileMessageContent(:final url, :final info, :final filename, :final file) =>
|
FileMessageContent(
|
||||||
FileCard(url, info, filename: filename, encrypted: file != null),
|
:final url,
|
||||||
|
:final info,
|
||||||
|
:final file,
|
||||||
|
:final filename,
|
||||||
|
:final body,
|
||||||
|
) =>
|
||||||
|
FileCard(url, info, filename: filename ?? body, encrypted: file != null),
|
||||||
ImageMessageContent(
|
ImageMessageContent(
|
||||||
:final url,
|
:final url,
|
||||||
:final info,
|
:final info,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue