mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 14:48:41 +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 {
|
if data != nil {
|
||||||
bestAttemptContent.title = data!.title;
|
bestAttemptContent.title = data!.title;
|
||||||
bestAttemptContent.body = data!.body;
|
bestAttemptContent.body = data!.body;
|
||||||
|
bestAttemptContent.threadIdentifier = String(format: "%d", data!.notificationId)
|
||||||
} else {
|
} else {
|
||||||
bestAttemptContent.title = "\(bestAttemptContent.title) [failed to decrypt]"
|
bestAttemptContent.title = "\(bestAttemptContent.title) [failed to decrypt]"
|
||||||
}
|
}
|
||||||
|
|
@ -65,7 +66,7 @@ import CryptoKit
|
||||||
import Foundation
|
import Foundation
|
||||||
import Security
|
import Security
|
||||||
|
|
||||||
func getPushNotificationData(pushDataJson: String) -> (title: String, body: String)? {
|
func getPushNotificationData(pushDataJson: String) -> (title: String, body: String, notificationId: Int)? {
|
||||||
// Decode the pushDataJson
|
// Decode the pushDataJson
|
||||||
guard let pushData = decodePushData(pushDataJson) else {
|
guard let pushData = decodePushData(pushDataJson) else {
|
||||||
NSLog("Failed to decode push data")
|
NSLog("Failed to decode push data")
|
||||||
|
|
@ -74,6 +75,7 @@ func getPushNotificationData(pushDataJson: String) -> (title: String, body: Stri
|
||||||
|
|
||||||
var pushKind: PushKind?
|
var pushKind: PushKind?
|
||||||
var displayName: String?
|
var displayName: String?
|
||||||
|
var fromUserId: Int?
|
||||||
|
|
||||||
// Check the keyId
|
// Check the keyId
|
||||||
if pushData.keyId == 0 {
|
if pushData.keyId == 0 {
|
||||||
|
|
@ -88,6 +90,7 @@ func getPushNotificationData(pushDataJson: String) -> (title: String, body: Stri
|
||||||
pushKind = tryDecryptMessage(key: key.key, pushData: pushData)
|
pushKind = tryDecryptMessage(key: key.key, pushData: pushData)
|
||||||
if pushKind != nil {
|
if pushKind != nil {
|
||||||
displayName = userKeys.displayName
|
displayName = userKeys.displayName
|
||||||
|
fromUserId = userId
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -106,11 +109,11 @@ func getPushNotificationData(pushDataJson: String) -> (title: String, body: Stri
|
||||||
let bestAttemptContent = UNMutableNotificationContent()
|
let bestAttemptContent = UNMutableNotificationContent()
|
||||||
|
|
||||||
if pushKind == .testNotification {
|
if pushKind == .testNotification {
|
||||||
return ("Test Notification", "This is a test notification.")
|
return ("Test Notification", "This is a test notification.", 0)
|
||||||
} else if displayName != nil {
|
} else if displayName != nil && fromUserId != nil {
|
||||||
return (displayName!, getPushNotificationText(pushKind: pushKind))
|
return (displayName!, getPushNotificationText(pushKind: pushKind), fromUserId!)
|
||||||
} else {
|
} else {
|
||||||
return ("", getPushNotificationTextWithoutUserId(pushKind: pushKind))
|
return ("", getPushNotificationTextWithoutUserId(pushKind: pushKind), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:twonly/globals.dart';
|
import 'package:twonly/globals.dart';
|
||||||
|
|
@ -254,7 +255,11 @@ class _ChatItemDetailsViewState extends State<ChatItemDetailsView> {
|
||||||
twonlyDatabase.messagesDao.watchAllMessagesFrom(widget.userid);
|
twonlyDatabase.messagesDao.watchAllMessagesFrom(widget.userid);
|
||||||
messageSub = msgStream.listen((msgs) {
|
messageSub = msgStream.listen((msgs) {
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
|
if (Platform.isAndroid) {
|
||||||
flutterLocalNotificationsPlugin.cancel(widget.userid);
|
flutterLocalNotificationsPlugin.cancel(widget.userid);
|
||||||
|
} else {
|
||||||
|
flutterLocalNotificationsPlugin.cancelAll();
|
||||||
|
}
|
||||||
var updated = false;
|
var updated = false;
|
||||||
List<Message> displayedMessages = [];
|
List<Message> displayedMessages = [];
|
||||||
// should be cleared
|
// should be cleared
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue