Merge remote-tracking branch 'zjs81/dev' into ez_disable_discoveredContact_eviction_PR
This commit is contained in:
commit
4480c0d356
56 files changed
+1500
-229
No files matched your search
@@ -3,7 +3,9 @@ import 'dart:ui';
|
||||
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
|
||||
import '../helpers/message_url_image_helper.dart';
|
||||
import '../helpers/reaction_helper.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
@@ -196,14 +198,40 @@ class NotificationService {
|
||||
return text;
|
||||
}
|
||||
|
||||
Future<String?> _resolveNotificationImagePath(
|
||||
String text, {
|
||||
required bool urlImagesEnabled,
|
||||
}) async {
|
||||
if (!urlImagesEnabled) return null;
|
||||
|
||||
final imageUrl = await MessageUrlImageHelper.parseVerified(text);
|
||||
if (imageUrl == null) return null;
|
||||
|
||||
try {
|
||||
// Cache the image so notification platforms can read it from disk.
|
||||
final imageFile = await DefaultCacheManager().getSingleFile(imageUrl);
|
||||
if (!imageFile.existsSync()) return null;
|
||||
return imageFile.path;
|
||||
} catch (e) {
|
||||
debugPrint('Failed to resolve notification image: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _showMessageNotificationImpl({
|
||||
required String contactName,
|
||||
required String message,
|
||||
required bool urlImagesEnabled,
|
||||
String? contactId,
|
||||
int? badgeCount,
|
||||
}) async {
|
||||
if (!await _ensureCanNotify()) return;
|
||||
|
||||
final imagePath = await _resolveNotificationImagePath(
|
||||
message,
|
||||
urlImagesEnabled: urlImagesEnabled,
|
||||
);
|
||||
|
||||
final androidDetails = AndroidNotificationDetails(
|
||||
'messages',
|
||||
'Messages',
|
||||
@@ -212,6 +240,12 @@ class NotificationService {
|
||||
priority: Priority.high,
|
||||
icon: '@mipmap/ic_launcher',
|
||||
number: badgeCount,
|
||||
styleInformation: imagePath != null
|
||||
? BigPictureStyleInformation(
|
||||
FilePathAndroidBitmap(imagePath),
|
||||
summaryText: formatNotificationText(message),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
|
||||
final iosDetails = DarwinNotificationDetails(
|
||||
@@ -219,6 +253,11 @@ class NotificationService {
|
||||
presentBadge: true,
|
||||
presentSound: true,
|
||||
badgeNumber: badgeCount,
|
||||
attachments: imagePath != null
|
||||
? <DarwinNotificationAttachment>[
|
||||
DarwinNotificationAttachment(imagePath),
|
||||
]
|
||||
: null,
|
||||
);
|
||||
|
||||
final macDetails = DarwinNotificationDetails(
|
||||
@@ -226,6 +265,11 @@ class NotificationService {
|
||||
presentBadge: true,
|
||||
presentSound: true,
|
||||
badgeNumber: badgeCount,
|
||||
attachments: imagePath != null
|
||||
? <DarwinNotificationAttachment>[
|
||||
DarwinNotificationAttachment(imagePath),
|
||||
]
|
||||
: null,
|
||||
);
|
||||
|
||||
final notificationDetails = NotificationDetails(
|
||||
@@ -299,11 +343,17 @@ class NotificationService {
|
||||
Future<void> _showChannelMessageNotificationImpl({
|
||||
required String channelName,
|
||||
required String message,
|
||||
required bool urlImagesEnabled,
|
||||
int? channelIndex,
|
||||
int? badgeCount,
|
||||
}) async {
|
||||
if (!await _ensureCanNotify()) return;
|
||||
|
||||
final imagePath = await _resolveNotificationImagePath(
|
||||
message,
|
||||
urlImagesEnabled: urlImagesEnabled,
|
||||
);
|
||||
|
||||
final androidDetails = AndroidNotificationDetails(
|
||||
'channel_messages',
|
||||
'Channel Messages',
|
||||
@@ -312,6 +362,12 @@ class NotificationService {
|
||||
priority: Priority.high,
|
||||
icon: '@mipmap/ic_launcher',
|
||||
number: badgeCount,
|
||||
styleInformation: imagePath != null
|
||||
? BigPictureStyleInformation(
|
||||
FilePathAndroidBitmap(imagePath),
|
||||
summaryText: formatNotificationText(message),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
|
||||
final iosDetails = DarwinNotificationDetails(
|
||||
@@ -319,6 +375,11 @@ class NotificationService {
|
||||
presentBadge: true,
|
||||
presentSound: true,
|
||||
badgeNumber: badgeCount,
|
||||
attachments: imagePath != null
|
||||
? <DarwinNotificationAttachment>[
|
||||
DarwinNotificationAttachment(imagePath),
|
||||
]
|
||||
: null,
|
||||
);
|
||||
|
||||
final macDetails = DarwinNotificationDetails(
|
||||
@@ -326,6 +387,11 @@ class NotificationService {
|
||||
presentBadge: true,
|
||||
presentSound: true,
|
||||
badgeNumber: badgeCount,
|
||||
attachments: imagePath != null
|
||||
? <DarwinNotificationAttachment>[
|
||||
DarwinNotificationAttachment(imagePath),
|
||||
]
|
||||
: null,
|
||||
);
|
||||
|
||||
final notificationDetails = NotificationDetails(
|
||||
@@ -448,6 +514,7 @@ class NotificationService {
|
||||
Future<void> showMessageNotification({
|
||||
required String contactName,
|
||||
required String message,
|
||||
required bool urlImagesEnabled,
|
||||
String? contactId,
|
||||
int? badgeCount,
|
||||
}) async {
|
||||
@@ -458,6 +525,7 @@ class NotificationService {
|
||||
type: _NotificationType.message,
|
||||
title: contactName,
|
||||
body: message,
|
||||
urlImagesEnabled: urlImagesEnabled,
|
||||
id: contactId,
|
||||
badgeCount: badgeCount,
|
||||
),
|
||||
@@ -485,6 +553,7 @@ class NotificationService {
|
||||
required String channelName,
|
||||
required String senderName,
|
||||
required String message,
|
||||
required bool urlImagesEnabled,
|
||||
int? channelIndex,
|
||||
int? badgeCount,
|
||||
}) async {
|
||||
@@ -495,6 +564,7 @@ class NotificationService {
|
||||
type: _NotificationType.channelMessage,
|
||||
title: channelName,
|
||||
body: '$senderName: $message',
|
||||
urlImagesEnabled: urlImagesEnabled,
|
||||
id: channelIndex?.toString(),
|
||||
badgeCount: badgeCount,
|
||||
),
|
||||
@@ -556,6 +626,7 @@ class NotificationService {
|
||||
await _showMessageNotificationImpl(
|
||||
contactName: notification.title,
|
||||
message: notification.body,
|
||||
urlImagesEnabled: notification.urlImagesEnabled,
|
||||
contactId: notification.id,
|
||||
badgeCount: notification.badgeCount,
|
||||
);
|
||||
@@ -571,6 +642,7 @@ class NotificationService {
|
||||
await _showChannelMessageNotificationImpl(
|
||||
channelName: notification.title,
|
||||
message: notification.body,
|
||||
urlImagesEnabled: notification.urlImagesEnabled,
|
||||
channelIndex: int.tryParse(notification.id ?? ''),
|
||||
badgeCount: notification.badgeCount,
|
||||
);
|
||||
@@ -647,6 +719,7 @@ class _PendingNotification {
|
||||
final _NotificationType type;
|
||||
final String title;
|
||||
final String body;
|
||||
final bool urlImagesEnabled;
|
||||
final String? id;
|
||||
final int? badgeCount;
|
||||
|
||||
@@ -654,6 +727,7 @@ class _PendingNotification {
|
||||
required this.type,
|
||||
required this.title,
|
||||
required this.body,
|
||||
this.urlImagesEnabled = false,
|
||||
this.id,
|
||||
this.badgeCount,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user