mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-14 22:12:18 -06:00
fix: Improve receiving shares
This commit is contained in:
@@ -18,6 +18,8 @@ class LocalNotificationService {
|
||||
|
||||
LocalNotificationService();
|
||||
|
||||
final Map<String, List<int>> _pendingNotifications = {};
|
||||
|
||||
Future<void> initialize() async {
|
||||
const AndroidInitializationSettings initializationSettingsAndroid =
|
||||
AndroidInitializationSettings('paperless_logo_green');
|
||||
@@ -51,6 +53,7 @@ class LocalNotificationService {
|
||||
required String filePath,
|
||||
required bool finished,
|
||||
required String locale,
|
||||
required String userId,
|
||||
}) async {
|
||||
final tr = await S.delegate.load(Locale(locale));
|
||||
|
||||
@@ -88,6 +91,15 @@ class LocalNotificationService {
|
||||
).toJson(),
|
||||
),
|
||||
); //TODO: INTL
|
||||
_addNotification(userId, id);
|
||||
}
|
||||
|
||||
void _addNotification(String userId, int notificationId) {
|
||||
_pendingNotifications.update(
|
||||
userId,
|
||||
(notifications) => [...notifications, notificationId],
|
||||
ifAbsent: () => [notificationId],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> notifyFileSaved({
|
||||
@@ -119,24 +131,20 @@ class LocalNotificationService {
|
||||
),
|
||||
iOS: DarwinNotificationDetails(
|
||||
attachments: [
|
||||
DarwinNotificationAttachment(
|
||||
filePath,
|
||||
),
|
||||
DarwinNotificationAttachment(filePath),
|
||||
],
|
||||
),
|
||||
),
|
||||
payload: jsonEncode(
|
||||
OpenDownloadedDocumentPayload(
|
||||
filePath: filePath,
|
||||
).toJson(),
|
||||
OpenDownloadedDocumentPayload(filePath: filePath).toJson(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
//TODO: INTL
|
||||
Future<void> notifyTaskChanged(Task task) {
|
||||
Future<void> notifyTaskChanged(Task task, {required String userId}) async {
|
||||
log("[LocalNotificationService] notifyTaskChanged: ${task.toString()}");
|
||||
int id = task.id;
|
||||
int id = task.id + 1000;
|
||||
final status = task.status;
|
||||
late String title;
|
||||
late String? body;
|
||||
@@ -171,7 +179,7 @@ class LocalNotificationService {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return _plugin.show(
|
||||
await _plugin.show(
|
||||
id,
|
||||
title,
|
||||
body,
|
||||
@@ -204,6 +212,13 @@ class LocalNotificationService {
|
||||
),
|
||||
payload: jsonEncode(payload),
|
||||
);
|
||||
_addNotification(userId, id);
|
||||
}
|
||||
|
||||
Future<void> cancelUserNotifications(String userId) async {
|
||||
await Future.wait([
|
||||
for (var id in _pendingNotifications[userId] ?? []) _plugin.cancel(id),
|
||||
]);
|
||||
}
|
||||
|
||||
void onDidReceiveLocalNotification(
|
||||
@@ -272,6 +287,7 @@ class LocalNotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
@protected
|
||||
void onDidReceiveBackgroundNotificationResponse(NotificationResponse response) {
|
||||
//TODO: When periodic background inbox check is implemented, notification tap is handled here
|
||||
debugPrint(response.toString());
|
||||
|
||||
Reference in New Issue
Block a user