2019-06-09 11:57:33 +00:00
|
|
|
/*
|
2020-06-03 10:16:01 +00:00
|
|
|
* Famedly Matrix SDK
|
|
|
|
* Copyright (C) 2019, 2020 Famedly GmbH
|
2019-06-09 11:57:33 +00:00
|
|
|
*
|
2020-06-03 10:16:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2019-06-09 11:57:33 +00:00
|
|
|
*
|
2020-06-03 10:16:01 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2019-06-09 11:57:33 +00:00
|
|
|
*
|
2020-06-03 10:16:01 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-06-09 11:57:33 +00:00
|
|
|
*/
|
|
|
|
|
Update lib/src/client.dart, lib/src/user.dart, lib/src/timeline.dart, lib/src/room.dart, lib/src/presence.dart, lib/src/event.dart, lib/src/utils/profile.dart, lib/src/utils/receipt.dart, test/client_test.dart, test/event_test.dart, test/presence_test.dart, test/room_test.dart, test/timeline_test.dart, test/user_test.dart files
2020-01-04 17:56:17 +00:00
|
|
|
import 'package:famedlysdk/src/client.dart';
|
2019-06-09 10:16:48 +00:00
|
|
|
import 'dart:core';
|
|
|
|
|
2020-04-24 07:24:06 +00:00
|
|
|
extension MxcUriExtension on Uri {
|
2019-06-10 06:28:21 +00:00
|
|
|
/// Returns a download Link to this content.
|
2020-04-24 07:24:06 +00:00
|
|
|
String getDownloadLink(Client matrix) => isScheme('mxc')
|
2020-06-03 10:16:01 +00:00
|
|
|
? matrix.api.homeserver != null
|
|
|
|
? '${matrix.api.homeserver.toString()}/_matrix/media/r0/download/$host$path'
|
2020-04-24 07:24:06 +00:00
|
|
|
: ''
|
|
|
|
: toString();
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2019-06-10 06:28:21 +00:00
|
|
|
/// 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].
|
|
|
|
String getThumbnail(Client matrix,
|
2020-04-24 07:24:06 +00:00
|
|
|
{num width, num height, ThumbnailMethod method = ThumbnailMethod.crop}) {
|
|
|
|
if (!isScheme('mxc')) return toString();
|
|
|
|
final methodStr = method.toString().split('.').last;
|
2019-06-09 10:16:48 +00:00
|
|
|
width = width.round();
|
|
|
|
height = height.round();
|
2020-06-03 10:16:01 +00:00
|
|
|
return matrix.api.homeserver != null
|
|
|
|
? '${matrix.api.homeserver.toString()}/_matrix/media/r0/thumbnail/$host$path?width=$width&height=$height&method=$methodStr'
|
2020-03-30 09:08:38 +00:00
|
|
|
: '';
|
2019-06-09 10:16:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-10 06:28:21 +00:00
|
|
|
enum ThumbnailMethod { crop, scale }
|