feat: Use matrix authenticated media
This commit is contained in:
parent
f17b09f56c
commit
158a6855c3
7 changed files with 134 additions and 115 deletions
|
|
@ -6,12 +6,11 @@ import 'package:flutter/material.dart';
|
|||
import 'package:desktop_notifications/desktop_notifications.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/utils/client_download_content_extension.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
|
@ -48,50 +47,38 @@ extension LocalNotificationsExtension on MatrixState {
|
|||
hideEdit: true,
|
||||
removeMarkdown: true,
|
||||
);
|
||||
final icon = event.senderFromMemoryOrFallback.avatarUrl?.getThumbnail(
|
||||
client,
|
||||
width: 64,
|
||||
height: 64,
|
||||
method: ThumbnailMethod.crop,
|
||||
) ??
|
||||
room.avatar?.getThumbnail(
|
||||
client,
|
||||
width: 64,
|
||||
height: 64,
|
||||
method: ThumbnailMethod.crop,
|
||||
);
|
||||
|
||||
if (kIsWeb) {
|
||||
final avatarUrl = event.senderFromMemoryOrFallback.avatarUrl;
|
||||
|
||||
final iconBytes = avatarUrl == null
|
||||
? null
|
||||
: await client.downloadMxcCached(
|
||||
avatarUrl,
|
||||
width: 64,
|
||||
height: 64,
|
||||
thumbnailMethod: ThumbnailMethod.crop,
|
||||
isThumbnail: true,
|
||||
animated: false,
|
||||
);
|
||||
|
||||
_audioPlayer.play();
|
||||
|
||||
html.Notification(
|
||||
title,
|
||||
body: body,
|
||||
icon: icon.toString(),
|
||||
icon: iconBytes == null
|
||||
? null
|
||||
: html.Url.createObjectUrl(html.Blob(iconBytes)),
|
||||
tag: event.room.id,
|
||||
);
|
||||
} else if (Platform.isLinux) {
|
||||
final appIconUrl = room.avatar?.getThumbnail(
|
||||
room.client,
|
||||
width: 56,
|
||||
height: 56,
|
||||
);
|
||||
File? appIconFile;
|
||||
if (appIconUrl != null) {
|
||||
final tempDirectory = await getApplicationSupportDirectory();
|
||||
final avatarDirectory =
|
||||
await Directory('${tempDirectory.path}/notiavatars/').create();
|
||||
appIconFile = File(
|
||||
'${avatarDirectory.path}/${Uri.encodeComponent(appIconUrl.toString())}',
|
||||
);
|
||||
if (await appIconFile.exists() == false) {
|
||||
final response = await http.get(appIconUrl);
|
||||
await appIconFile.writeAsBytes(response.bodyBytes);
|
||||
}
|
||||
}
|
||||
final notification = await linuxNotifications!.notify(
|
||||
title,
|
||||
body: body,
|
||||
replacesId: linuxNotificationIds[roomId] ?? 0,
|
||||
appName: AppConfig.applicationName,
|
||||
appIcon: appIconFile?.path ?? '',
|
||||
appIcon: 'fluffychat',
|
||||
actions: [
|
||||
NotificationAction(
|
||||
DesktopNotificationActions.openChat.name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue