Merge branch 'soru/animated-thumbnail' into 'main'
feat: Add animated property to thumbnails See merge request famedly/famedlysdk!590
This commit is contained in:
commit
03b9c6e2ee
|
|
@ -438,14 +438,16 @@ class Event extends MatrixEvent {
|
|||
/// Set [getThumbnail] to true to fetch the thumbnail, set [width], [height] and [method]
|
||||
/// for the respective thumbnailing properties.
|
||||
/// [minNoThumbSize] is the minimum size that an original image may be to not fetch its thumbnail, defaults to 80k
|
||||
/// [useThumbnailMxcUrl] says weather to use the mxc url of the thumbnail, rather than the original attachment
|
||||
/// [useThumbnailMxcUrl] says weather to use the mxc url of the thumbnail, rather than the original attachment.
|
||||
/// [animated] says weather the thumbnail is animated
|
||||
String getAttachmentUrl(
|
||||
{bool getThumbnail = false,
|
||||
bool useThumbnailMxcUrl = false,
|
||||
double width = 800.0,
|
||||
double height = 800.0,
|
||||
ThumbnailMethod method = ThumbnailMethod.scale,
|
||||
int minNoThumbSize = _minNoThumbSize}) {
|
||||
int minNoThumbSize = _minNoThumbSize,
|
||||
bool animated = false}) {
|
||||
if (![EventTypes.Message, EventTypes.Sticker].contains(type) ||
|
||||
!hasAttachment ||
|
||||
isAttachmentEncrypted) {
|
||||
|
|
@ -471,6 +473,7 @@ class Event extends MatrixEvent {
|
|||
width: width,
|
||||
height: height,
|
||||
method: method,
|
||||
animated: animated,
|
||||
);
|
||||
} else {
|
||||
return Uri.parse(thisMxcUrl).getDownloadLink(room.client);
|
||||
|
|
|
|||
|
|
@ -31,15 +31,28 @@ extension MxcUriExtension on Uri {
|
|||
/// Returns a scaled thumbnail link to this content with the given [width] and
|
||||
/// [height]. [method] can be [ThumbnailMethod.crop] or
|
||||
/// [ThumbnailMethod.scale] and defaults to [ThumbnailMethod.scale].
|
||||
/// If [animated] (default false) is set to true, an animated thumbnail is requested
|
||||
/// as per MSC2705. Thumbnails only animate if the media repository supports that.
|
||||
String getThumbnail(Client matrix,
|
||||
{num width, num height, ThumbnailMethod method = ThumbnailMethod.crop}) {
|
||||
{num width,
|
||||
num height,
|
||||
ThumbnailMethod method = ThumbnailMethod.crop,
|
||||
bool animated = false}) {
|
||||
if (!isScheme('mxc')) return toString();
|
||||
final methodStr = method.toString().split('.').last;
|
||||
width = width.round();
|
||||
height = height.round();
|
||||
return matrix.homeserver != null
|
||||
? '${matrix.homeserver.toString()}/_matrix/media/r0/thumbnail/$host$path?width=$width&height=$height&method=$methodStr'
|
||||
: '';
|
||||
if (matrix.homeserver == null) {
|
||||
return '';
|
||||
}
|
||||
return Uri(
|
||||
scheme: matrix.homeserver.scheme,
|
||||
host: matrix.homeserver.host,
|
||||
path: '/_matrix/media/r0/thumbnail/$host$path',
|
||||
queryParameters: {
|
||||
if (width != null) 'width': width.round().toString(),
|
||||
if (height != null) 'height': height.round().toString(),
|
||||
if (method != null) 'method': method.toString().split('.').last,
|
||||
if (animated != null) 'animated': animated.toString(),
|
||||
},
|
||||
).toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1104,12 +1104,12 @@ void main() {
|
|||
expect(event.getAttachmentUrl(),
|
||||
'https://fakeserver.notexisting/_matrix/media/r0/download/example.org/file');
|
||||
expect(event.getAttachmentUrl(getThumbnail: true),
|
||||
'https://fakeserver.notexisting/_matrix/media/r0/thumbnail/example.org/file?width=800&height=800&method=scale');
|
||||
'https://fakeserver.notexisting/_matrix/media/r0/thumbnail/example.org/file?width=800&height=800&method=scale&animated=false');
|
||||
expect(event.getAttachmentUrl(useThumbnailMxcUrl: true),
|
||||
'https://fakeserver.notexisting/_matrix/media/r0/download/example.org/thumb');
|
||||
expect(
|
||||
event.getAttachmentUrl(getThumbnail: true, useThumbnailMxcUrl: true),
|
||||
'https://fakeserver.notexisting/_matrix/media/r0/thumbnail/example.org/thumb?width=800&height=800&method=scale');
|
||||
'https://fakeserver.notexisting/_matrix/media/r0/thumbnail/example.org/thumb?width=800&height=800&method=scale&animated=false');
|
||||
expect(
|
||||
event.getAttachmentUrl(getThumbnail: true, minNoThumbSize: 9000000),
|
||||
'https://fakeserver.notexisting/_matrix/media/r0/download/example.org/file');
|
||||
|
|
|
|||
|
|
@ -38,11 +38,14 @@ void main() {
|
|||
expect(content.getDownloadLink(client),
|
||||
'${client.homeserver.toString()}/_matrix/media/r0/download/exampleserver.abc/abcdefghijklmn');
|
||||
expect(content.getThumbnail(client, width: 50, height: 50),
|
||||
'${client.homeserver.toString()}/_matrix/media/r0/thumbnail/exampleserver.abc/abcdefghijklmn?width=50&height=50&method=crop');
|
||||
'${client.homeserver.toString()}/_matrix/media/r0/thumbnail/exampleserver.abc/abcdefghijklmn?width=50&height=50&method=crop&animated=false');
|
||||
expect(
|
||||
content.getThumbnail(client,
|
||||
width: 50, height: 50, method: ThumbnailMethod.scale),
|
||||
'${client.homeserver.toString()}/_matrix/media/r0/thumbnail/exampleserver.abc/abcdefghijklmn?width=50&height=50&method=scale');
|
||||
width: 50,
|
||||
height: 50,
|
||||
method: ThumbnailMethod.scale,
|
||||
animated: true),
|
||||
'${client.homeserver.toString()}/_matrix/media/r0/thumbnail/exampleserver.abc/abcdefghijklmn?width=50&height=50&method=scale&animated=true');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue