Initial commit
Some checks failed
Main Deploy Workflow / deploy_web (push) Has been cancelled
Main Deploy Workflow / deploy_playstore_internal (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled

This commit is contained in:
2026-09-11 15:59:56 -03:00
commit 0037b0b9cf
651 changed files with 199705 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
//
// SPDX-License-Identifier: AGPL-3.0-or-later
import 'dart:io';
import 'dart:typed_data';
import 'package:tatchat/utils/client_download_content_extension.dart';
import 'package:matrix/matrix.dart';
import 'package:path/path.dart' as path;
import 'matrix_sdk_extensions/flutter_matrix_dart_sdk_database/builder.dart';
const notificationAvatarDimension = 128;
extension NotificationAvatarExtension on Client {
Future<Uint8List?> tryDownloadNotificationAvatar(Uri? avatar) async {
if (avatar == null) return null;
try {
return await downloadMxcCached(
avatar,
thumbnailMethod: ThumbnailMethod.crop,
width: notificationAvatarDimension,
height: notificationAvatarDimension,
animated: false,
isThumbnail: true,
rounded: true,
).timeout(const Duration(seconds: 3));
} catch (e, s) {
Logs().e('Unable to get avatar picture', e, s);
return null;
}
}
/// Keep in sync with `createAttachment()` in iOS Notification Extension
/// This loads the avatar for a room and also stores it in a temporary
/// directory so the Notification Service Extension can access it later.
Future<String?> getIosNotificationAvatar(Uri? roomAvatar) async {
if (roomAvatar == null) return null;
final directory = await getFileStorageLocation();
if (directory == null) return null;
final host = roomAvatar.host.replaceAll('.', '_');
final rawPath = roomAvatar.pathSegments.join('_');
final fileName = 'notification_${host}_$rawPath.jpg';
final cachedFile = File(path.join(directory.path, fileName));
if (!await cachedFile.exists()) {
final bytes = await tryDownloadNotificationAvatar(roomAvatar);
if (bytes == null) return null;
await cachedFile.writeAsBytes(bytes);
}
return cachedFile.path;
}
}