Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Notification Buttons #24

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions noterly/lib/managers/notification_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class NotificationManager {
await NotificationManager.instance.updateRepeatingNotification(item);
await FirebaseAnalytics.instance.logEvent(name: 'mark_repeating_notification_done');
} else {
Log.logger.d('Archiving notification "${item.title}"');
await AppManager.instance.archiveItem(item.id, deferNotificationManagerCall: true);
Log.logger.d('Deleting notification "${item.title}"');
await AppManager.instance.deleteItem(item.id, deferNotificationManagerCall: true);
await FirebaseAnalytics.instance.logEvent(name: 'mark_notification_done');
}

Expand Down Expand Up @@ -151,6 +151,21 @@ class NotificationManager {
}
}

if (response.actionId === 'archive') {
Log.logger.d('Archiving notification "${item.title}"');
await AppManager.instance.archiveItem(item.id, deferNotificationManagerCall: true);

// just stole this code, hopefully nothing breaks 💀💀💀💀
// If we're in the background, we need to send a message to the main isolate to update the UI
if (isBackground) {
var sendPort = IsolateNameServer.lookupPortByName(IsolateManager.mainPortName);
sendPort?.send('update');
if (sendPort == null) {
Log.logger.w('Failed to send message to main isolate (port not found).');
}
}
}

static Future onResponse(NotificationResponse response) async => handleResponse(response, isBackground: false);

@pragma('vm:entry-point')
Expand Down Expand Up @@ -323,7 +338,8 @@ class NotificationManager {
item.isImmediate ? 'Immediate notifications' : 'Scheduled notifications',
channelDescription: item.isImmediate ? 'Notifications that are shown immediately' : 'Notifications that are scheduled for a future time',
actions: <AndroidNotificationAction>[
const AndroidNotificationAction('done', 'Mark as done'),
const AndroidNotificationAction('done', 'Done'),
const AndroidNotificationAction('archive', 'Archive'),
const AndroidNotificationAction('snooze', 'Snooze'),
],
category: AndroidNotificationCategory.reminder,
Expand Down