From 85b501e180ba0e51ef7a15e8721c3c3c51492e21 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Thu, 5 Sep 2024 10:11:09 -0400 Subject: [PATCH] re-enabled code related to recent updates to matrix SDK --- .../settings_emotes/settings_emotes.dart | 68 ++++++++++--------- .../client_download_content_extension.dart | 68 +++++++++---------- .../local_notifications_extension.dart | 17 +++-- 3 files changed, 76 insertions(+), 77 deletions(-) diff --git a/lib/pages/settings_emotes/settings_emotes.dart b/lib/pages/settings_emotes/settings_emotes.dart index 5f7ec4986..b90432f56 100644 --- a/lib/pages/settings_emotes/settings_emotes.dart +++ b/lib/pages/settings_emotes/settings_emotes.dart @@ -6,11 +6,14 @@ import 'package:archive/archive.dart' import 'package:collection/collection.dart'; import 'package:file_picker/file_picker.dart'; import 'package:fluffychat/utils/client_manager.dart'; +import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart'; import 'package:fluffychat/widgets/app_lock.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:go_router/go_router.dart'; +import 'package:http/http.dart' hide Client; import 'package:matrix/matrix.dart'; import '../../widgets/matrix.dart'; @@ -315,42 +318,41 @@ class EmotesSettingsController extends State { } Future exportAsZip() async { - // TODO update matrix SDK to support this - // final client = Matrix.of(context).client; + final client = Matrix.of(context).client; - // await showFutureLoadingDialog( - // context: context, - // future: () async { - // final pack = _getPack(); - // final archive = Archive(); - // for (final entry in pack.images.entries) { - // final emote = entry.value; - // final name = entry.key; - // final url = await emote.url.getDownloadUri(client); - // final response = await get( - // url, - // headers: {'authorization': 'Bearer ${client.accessToken}'}, - // ); + await showFutureLoadingDialog( + context: context, + future: () async { + final pack = _getPack(); + final archive = Archive(); + for (final entry in pack.images.entries) { + final emote = entry.value; + final name = entry.key; + final url = await emote.url.getDownloadUri(client); + final response = await get( + url, + headers: {'authorization': 'Bearer ${client.accessToken}'}, + ); - // archive.addFile( - // ArchiveFile( - // name, - // response.bodyBytes.length, - // response.bodyBytes, - // ), - // ); - // } - // final fileName = - // '${pack.pack.displayName ?? client.userID?.localpart ?? 'emotes'}.zip'; - // final output = ZipEncoder().encode(archive); + archive.addFile( + ArchiveFile( + name, + response.bodyBytes.length, + response.bodyBytes, + ), + ); + } + final fileName = + '${pack.pack.displayName ?? client.userID?.localpart ?? 'emotes'}.zip'; + final output = ZipEncoder().encode(archive); - // if (output == null) return; + if (output == null) return; - // MatrixFile( - // name: fileName, - // bytes: Uint8List.fromList(output), - // ).save(context); - // }, - // ); + MatrixFile( + name: fileName, + bytes: Uint8List.fromList(output), + ).save(context); + }, + ); } } diff --git a/lib/utils/client_download_content_extension.dart b/lib/utils/client_download_content_extension.dart index ba7741e60..9fff1eccd 100644 --- a/lib/utils/client_download_content_extension.dart +++ b/lib/utils/client_download_content_extension.dart @@ -11,45 +11,43 @@ extension ClientDownloadContentExtension on Client { bool? animated, ThumbnailMethod? thumbnailMethod, }) async { - // // To stay compatible with previous storeKeys: - // final cacheKey = isThumbnail - // // ignore: deprecated_member_use - // ? mxc.getThumbnail( - // this, - // width: width, - // height: height, - // animated: animated, - // method: thumbnailMethod!, - // ) - // : mxc; + // To stay compatible with previous storeKeys: + final cacheKey = isThumbnail + // ignore: deprecated_member_use + ? mxc.getThumbnail( + this, + width: width, + height: height, + animated: animated, + method: thumbnailMethod!, + ) + : mxc; - // final cachedData = await database?.getFile(cacheKey); - // if (cachedData != null) return cachedData; + final cachedData = await database?.getFile(cacheKey); + if (cachedData != null) return cachedData; - // final httpUri = isThumbnail - // ? await mxc.getThumbnailUri( - // this, - // width: width, - // height: height, - // animated: animated, - // method: thumbnailMethod, - // ) - // : await mxc.getDownloadUri(this); + final httpUri = isThumbnail + ? await mxc.getThumbnailUri( + this, + width: width, + height: height, + animated: animated, + method: thumbnailMethod, + ) + : await mxc.getDownloadUri(this); - // final response = await httpClient.get( - // httpUri, - // headers: - // accessToken == null ? null : {'authorization': 'Bearer $accessToken'}, - // ); - // if (response.statusCode != 200) { - // throw Exception(); - // } - // final remoteData = response.bodyBytes; + final response = await httpClient.get( + httpUri, + headers: + accessToken == null ? null : {'authorization': 'Bearer $accessToken'}, + ); + if (response.statusCode != 200) { + throw Exception(); + } + final remoteData = response.bodyBytes; - // await database?.storeFile(cacheKey, remoteData, 0); + await database?.storeFile(cacheKey, remoteData, 0); - // return remoteData; - // TODO update matrix SDK to support this - return Uint8List.fromList([]); + return remoteData; } } diff --git a/lib/widgets/local_notifications_extension.dart b/lib/widgets/local_notifications_extension.dart index eeca03bde..0953c1deb 100644 --- a/lib/widgets/local_notifications_extension.dart +++ b/lib/widgets/local_notifications_extension.dart @@ -62,14 +62,13 @@ extension LocalNotificationsExtension on MatrixState { isThumbnail: true, ); - // TODO replace after upgrading matrix SDK - // thumbnailUri = - // await event.senderFromMemoryOrFallback.avatarUrl?.getThumbnailUri( - // client, - // width: size, - // height: size, - // method: thumbnailMethod, - // ); + thumbnailUri = + await event.senderFromMemoryOrFallback.avatarUrl?.getThumbnailUri( + client, + width: size, + height: size, + method: thumbnailMethod, + ); } _audioPlayer.play(); @@ -77,7 +76,7 @@ extension LocalNotificationsExtension on MatrixState { html.Notification( title, body: body, - // icon: thumbnailUri?.toString(), + icon: thumbnailUri?.toString(), tag: event.room.id, ); } else if (Platform.isLinux) {