Properly handle click actions on notifications

This commit is contained in:
2024-07-13 01:05:32 +02:00
parent 74a935f6f1
commit e93d125431
7 changed files with 103 additions and 19 deletions

View File

@@ -6,7 +6,7 @@ import 'package:simplecloudnotifier/state/application_log.dart';
import 'package:simplecloudnotifier/state/globals.dart';
class Notifier {
static void showLocalNotification(String channelID, String channelName, String channelDescr, String title, String body, DateTime? timestamp) async {
static void showLocalNotification(String messageID, String channelID, String channelName, String channelDescr, String title, String body, DateTime? timestamp) async {
final nid = Globals().sharedPrefs.getInt('notifier.nextid') ?? 1000;
Globals().sharedPrefs.setInt('notifier.nextid', nid + 7);
@@ -25,6 +25,12 @@ class Notifier {
final newSummaryNID = nid + 1;
ApplicationLog.debug('Create new summary notifications for channel ${channelID} with nid [${newSummaryNID}])');
Globals().sharedPrefs.setInt('notifier.summary.$channelID', newSummaryNID);
var payload = '';
if (messageID != '') {
payload = ['@SCN_MESSAGE_SUMMARY', channelID, newSummaryNID].join("\n");
}
await flutterLocalNotificationsPlugin.show(
newSummaryNID,
channelName,
@@ -40,6 +46,7 @@ class Notifier {
subText: (channelName == 'main') ? null : channelName,
),
),
payload: payload,
);
}
}
@@ -48,6 +55,11 @@ class Notifier {
ApplicationLog.debug('Create new local notifications for message in channel ${channelID} with nid [${newMessageNID}])');
var payload = '';
if (messageID != '') {
payload = ['@SCN_MESSAGE', messageID, channelID, newMessageNID].join("\n");
}
// ======== SHOW NOTIFICATION ========
await flutterLocalNotificationsPlugin.show(
newMessageNID,
@@ -65,6 +77,7 @@ class Notifier {
subText: (channelName == 'main') ? null : channelName,
),
),
payload: payload,
);
}
}