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 notify(category: AppNotificationCategory, title: String?, body: String, userInfo: [AnyHashable: Any], sound: OWSSound?, replacingIdentifier: String?)
|
||||||
|
|
||||||
func cancelNotifications(threadId: String)
|
func cancelNotifications(threadId: String)
|
||||||
|
func cancelNotification(identifier: String)
|
||||||
func clearAllNotifications()
|
func clearAllNotifications()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,6 +220,10 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
|
||||||
let userInfo = [
|
let userInfo = [
|
||||||
AppNotificationUserInfoKey.threadId: threadId
|
AppNotificationUserInfoKey.threadId: threadId
|
||||||
]
|
]
|
||||||
|
|
||||||
|
let transaction = transaction as! YapDatabaseReadWriteTransaction
|
||||||
|
let identifier: String = UUID().uuidString
|
||||||
|
incomingMessage.setNotificationIdentifier(identifier, transaction: transaction)
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
notificationBody = MentionUtilities.highlightMentions(in: notificationBody!, threadID: thread.uniqueId!)
|
notificationBody = MentionUtilities.highlightMentions(in: notificationBody!, threadID: thread.uniqueId!)
|
||||||
|
@ -227,7 +232,8 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
|
||||||
title: notificationTitle,
|
title: notificationTitle,
|
||||||
body: notificationBody ?? "",
|
body: notificationBody ?? "",
|
||||||
userInfo: userInfo,
|
userInfo: userInfo,
|
||||||
sound: sound)
|
sound: sound,
|
||||||
|
replacingIdentifier: identifier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,6 +266,11 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
|
||||||
sound: sound)
|
sound: sound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc
|
||||||
|
public func cancelNotification(_ identifier: String) {
|
||||||
|
self.adaptee.cancelNotification(identifier: identifier)
|
||||||
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
public func cancelNotifications(threadId: String) {
|
public func cancelNotifications(threadId: String) {
|
||||||
|
|
|
@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@property (nonatomic, readonly) BOOL isUserMentioned;
|
@property (nonatomic, readonly) BOOL isUserMentioned;
|
||||||
|
|
||||||
|
@property (nonatomic, readonly, nullable) NSString *notificationIdentifier;
|
||||||
|
|
||||||
- (instancetype)initMessageWithTimestamp:(uint64_t)timestamp
|
- (instancetype)initMessageWithTimestamp:(uint64_t)timestamp
|
||||||
inThread:(nullable TSThread *)thread
|
inThread:(nullable TSThread *)thread
|
||||||
messageBody:(nullable NSString *)body
|
messageBody:(nullable NSString *)body
|
||||||
|
@ -88,6 +90,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
- (void)markAsReadNowWithSendReadReceipt:(BOOL)sendReadReceipt
|
- (void)markAsReadNowWithSendReadReceipt:(BOOL)sendReadReceipt
|
||||||
transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||||
|
|
||||||
|
- (void)setNotificationIdentifier:(NSString * _Nullable)notificationIdentifier
|
||||||
|
transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -77,6 +77,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
_read = NO;
|
_read = NO;
|
||||||
_serverTimestamp = serverTimestamp;
|
_serverTimestamp = serverTimestamp;
|
||||||
_wasReceivedByUD = wasReceivedByUD;
|
_wasReceivedByUD = wasReceivedByUD;
|
||||||
|
_notificationIdentifier = nil;
|
||||||
|
|
||||||
return self;
|
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]);
|
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
|
#pragma mark - OWSReadTracking
|
||||||
|
|
||||||
- (BOOL)shouldAffectUnreadCounts
|
- (BOOL)shouldAffectUnreadCounts
|
||||||
|
|
|
@ -227,6 +227,9 @@ extension MessageReceiver {
|
||||||
let transaction = transaction as! YapDatabaseReadWriteTransaction
|
let transaction = transaction as! YapDatabaseReadWriteTransaction
|
||||||
if let author = message.author, let timestamp = message.timestamp,
|
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) {
|
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)
|
messageToDelete.remove(with: transaction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
inThread:(TSThread *)thread
|
inThread:(TSThread *)thread
|
||||||
transaction:(YapDatabaseReadTransaction *)transaction;
|
transaction:(YapDatabaseReadTransaction *)transaction;
|
||||||
|
|
||||||
|
- (void)cancelNotification:(NSString *)identifier;
|
||||||
- (void)clearAllNotifications;
|
- (void)clearAllNotifications;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,6 +8,10 @@ public class NoopNotificationsManager: NSObject, NotificationsProtocol {
|
||||||
public func notifyUser(for incomingMessage: TSIncomingMessage, in thread: TSThread, transaction: YapDatabaseReadTransaction) {
|
public func notifyUser(for incomingMessage: TSIncomingMessage, in thread: TSThread, transaction: YapDatabaseReadTransaction) {
|
||||||
owsFailDebug("")
|
owsFailDebug("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func cancelNotification(_ identifier: String) {
|
||||||
|
owsFailDebug("")
|
||||||
|
}
|
||||||
|
|
||||||
public func clearAllNotifications() {
|
public func clearAllNotifications() {
|
||||||
Logger.warn("clearAllNotifications")
|
Logger.warn("clearAllNotifications")
|
||||||
|
|
Loading…
Reference in New Issue