mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 13:08:42 +00:00
cancel al notifications on ios
This commit is contained in:
parent
1d84834a35
commit
b039f5e4c7
2 changed files with 15 additions and 7 deletions
|
|
@ -30,6 +30,7 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
if data != nil {
|
||||
bestAttemptContent.title = data!.title;
|
||||
bestAttemptContent.body = data!.body;
|
||||
bestAttemptContent.threadIdentifier = String(format: "%d", data!.notificationId)
|
||||
} else {
|
||||
bestAttemptContent.title = "\(bestAttemptContent.title) [failed to decrypt]"
|
||||
}
|
||||
|
|
@ -65,7 +66,7 @@ import CryptoKit
|
|||
import Foundation
|
||||
import Security
|
||||
|
||||
func getPushNotificationData(pushDataJson: String) -> (title: String, body: String)? {
|
||||
func getPushNotificationData(pushDataJson: String) -> (title: String, body: String, notificationId: Int)? {
|
||||
// Decode the pushDataJson
|
||||
guard let pushData = decodePushData(pushDataJson) else {
|
||||
NSLog("Failed to decode push data")
|
||||
|
|
@ -74,6 +75,7 @@ func getPushNotificationData(pushDataJson: String) -> (title: String, body: Stri
|
|||
|
||||
var pushKind: PushKind?
|
||||
var displayName: String?
|
||||
var fromUserId: Int?
|
||||
|
||||
// Check the keyId
|
||||
if pushData.keyId == 0 {
|
||||
|
|
@ -88,6 +90,7 @@ func getPushNotificationData(pushDataJson: String) -> (title: String, body: Stri
|
|||
pushKind = tryDecryptMessage(key: key.key, pushData: pushData)
|
||||
if pushKind != nil {
|
||||
displayName = userKeys.displayName
|
||||
fromUserId = userId
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -106,11 +109,11 @@ func getPushNotificationData(pushDataJson: String) -> (title: String, body: Stri
|
|||
let bestAttemptContent = UNMutableNotificationContent()
|
||||
|
||||
if pushKind == .testNotification {
|
||||
return ("Test Notification", "This is a test notification.")
|
||||
} else if displayName != nil {
|
||||
return (displayName!, getPushNotificationText(pushKind: pushKind))
|
||||
return ("Test Notification", "This is a test notification.", 0)
|
||||
} else if displayName != nil && fromUserId != nil {
|
||||
return (displayName!, getPushNotificationText(pushKind: pushKind), fromUserId!)
|
||||
} else {
|
||||
return ("", getPushNotificationTextWithoutUserId(pushKind: pushKind))
|
||||
return ("", getPushNotificationTextWithoutUserId(pushKind: pushKind), 1)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
@ -367,4 +370,4 @@ func getPushNotificationTextWithoutUserId(pushKind: PushKind) -> String {
|
|||
|
||||
// Return the corresponding message or an empty string if not found
|
||||
return pushNotificationText[pushKind] ?? ""
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:twonly/globals.dart';
|
||||
|
|
@ -254,7 +255,11 @@ class _ChatItemDetailsViewState extends State<ChatItemDetailsView> {
|
|||
twonlyDatabase.messagesDao.watchAllMessagesFrom(widget.userid);
|
||||
messageSub = msgStream.listen((msgs) {
|
||||
if (!context.mounted) return;
|
||||
flutterLocalNotificationsPlugin.cancel(widget.userid);
|
||||
if (Platform.isAndroid) {
|
||||
flutterLocalNotificationsPlugin.cancel(widget.userid);
|
||||
} else {
|
||||
flutterLocalNotificationsPlugin.cancelAll();
|
||||
}
|
||||
var updated = false;
|
||||
List<Message> displayedMessages = [];
|
||||
// should be cleared
|
||||
|
|
|
|||
Loading…
Reference in a new issue