cancel local notifications for unsend requests
This commit is contained in:
parent
68d14709e9
commit
e2a0578770
|
@ -95,6 +95,7 @@ protocol NotificationPresenterAdaptee: class {
|
|||
func notify(category: AppNotificationCategory, title: String?, body: String, userInfo: [AnyHashable: Any], sound: OWSSound?, replacingIdentifier: String?)
|
||||
|
||||
func cancelNotifications(threadId: String)
|
||||
func cancelNotification(identifier: String)
|
||||
func clearAllNotifications()
|
||||
}
|
||||
|
||||
|
@ -219,6 +220,10 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
|
|||
let userInfo = [
|
||||
AppNotificationUserInfoKey.threadId: threadId
|
||||
]
|
||||
|
||||
let transaction = transaction as! YapDatabaseReadWriteTransaction
|
||||
let identifier: String = UUID().uuidString
|
||||
incomingMessage.setNotificationIdentifier(identifier, transaction: transaction)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
notificationBody = MentionUtilities.highlightMentions(in: notificationBody!, threadID: thread.uniqueId!)
|
||||
|
@ -227,7 +232,8 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
|
|||
title: notificationTitle,
|
||||
body: notificationBody ?? "",
|
||||
userInfo: userInfo,
|
||||
sound: sound)
|
||||
sound: sound,
|
||||
replacingIdentifier: identifier)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -260,6 +266,11 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
|
|||
sound: sound)
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
public func cancelNotification(_ identifier: String) {
|
||||
self.adaptee.cancelNotification(identifier: identifier)
|
||||
}
|
||||
|
||||
@objc
|
||||
public func cancelNotifications(threadId: String) {
|
||||
|
|
|
@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@property (nonatomic, readonly) BOOL isUserMentioned;
|
||||
|
||||
@property (nonatomic, readonly, nullable) NSString *notificationIdentifier;
|
||||
|
||||
- (instancetype)initMessageWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(nullable TSThread *)thread
|
||||
messageBody:(nullable NSString *)body
|
||||
|
@ -88,6 +90,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
- (void)markAsReadNowWithSendReadReceipt:(BOOL)sendReadReceipt
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
- (void)setNotificationIdentifier:(NSString * _Nullable)notificationIdentifier
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -77,6 +77,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
_read = NO;
|
||||
_serverTimestamp = serverTimestamp;
|
||||
_wasReceivedByUD = wasReceivedByUD;
|
||||
_notificationIdentifier = nil;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -128,6 +129,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
return (self.body != nil && [self.body containsString:[NSString stringWithFormat:@"@%@", userPublicKey]]) || (self.quotedMessage != nil && [self.quotedMessage.authorId isEqualToString:userPublicKey]);
|
||||
}
|
||||
|
||||
- (void)setNotificationIdentifier:(NSString * _Nullable)notificationIdentifier transaction:(nonnull YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
_notificationIdentifier = notificationIdentifier;
|
||||
[self saveWithTransaction:transaction];
|
||||
}
|
||||
|
||||
#pragma mark - OWSReadTracking
|
||||
|
||||
- (BOOL)shouldAffectUnreadCounts
|
||||
|
|
|
@ -227,6 +227,9 @@ extension MessageReceiver {
|
|||
let transaction = transaction as! YapDatabaseReadWriteTransaction
|
||||
if let author = message.author, let timestamp = message.timestamp,
|
||||
let messageToDelete = userPublicKey == message.sender ? TSOutgoingMessage.find(withTimestamp: timestamp) : TSIncomingMessage.find(withAuthorId: author, timestamp: timestamp, transaction: transaction) {
|
||||
if let incomingMessage = messageToDelete as? TSIncomingMessage, let notificationIdentifier = incomingMessage.notificationIdentifier, !notificationIdentifier.isEmpty {
|
||||
SSKEnvironment.shared.notificationsManager!.cancelNotification(notificationIdentifier)
|
||||
}
|
||||
messageToDelete.remove(with: transaction)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
inThread:(TSThread *)thread
|
||||
transaction:(YapDatabaseReadTransaction *)transaction;
|
||||
|
||||
- (void)cancelNotification:(NSString *)identifier;
|
||||
- (void)clearAllNotifications;
|
||||
|
||||
@end
|
||||
|
|
|
@ -8,6 +8,10 @@ public class NoopNotificationsManager: NSObject, NotificationsProtocol {
|
|||
public func notifyUser(for incomingMessage: TSIncomingMessage, in thread: TSThread, transaction: YapDatabaseReadTransaction) {
|
||||
owsFailDebug("")
|
||||
}
|
||||
|
||||
public func cancelNotification(_ identifier: String) {
|
||||
owsFailDebug("")
|
||||
}
|
||||
|
||||
public func clearAllNotifications() {
|
||||
Logger.warn("clearAllNotifications")
|
||||
|
|
Loading…
Reference in New Issue