replying to notification marks thread as read

pull/2/head
Michael Kirk 6 years ago
parent 1e0504e8ff
commit 6c08f98fbb

@ -613,15 +613,7 @@ class NotificationActionHandler {
throw NotificationError.failDebug("unable to find thread with id: \(threadId)")
}
return Promise { resolver in
self.dbConnection.asyncReadWrite({ transaction in
thread.markAllAsRead(with: transaction)
},
completionBlock: {
self.notificationPresenter.cancelNotifications(threadId: threadId)
resolver.fulfill(())
})
}
return markAsRead(thread: thread)
}
func reply(userInfo: [AnyHashable: Any], replyText: String) throws -> Promise<Void> {
@ -633,12 +625,16 @@ class NotificationActionHandler {
throw NotificationError.failDebug("unable to find thread with id: \(threadId)")
}
return ThreadUtil.sendMessageNonDurably(text: replyText,
thread: thread,
quotedReplyModel: nil,
messageSender: messageSender).recover { error in
Logger.warn("Failed to send reply message from notification with error: \(error)")
self.notificationPresenter.notifyForFailedSend(inThread: thread)
return markAsRead(thread: thread).then { () -> Promise<Void> in
let sendPromise = ThreadUtil.sendMessageNonDurably(text: replyText,
thread: thread,
quotedReplyModel: nil,
messageSender: self.messageSender)
return sendPromise.recover { error in
Logger.warn("Failed to send reply message from notification with error: \(error)")
self.notificationPresenter.notifyForFailedSend(inThread: thread)
}
}
}
@ -654,6 +650,12 @@ class NotificationActionHandler {
signalApp.presentConversation(forThreadId: threadId, animated: shouldAnimate)
return Promise.value(())
}
private func markAsRead(thread: TSThread) -> Promise<Void> {
return dbConnection.readWritePromise { transaction in
thread.markAllAsRead(with: transaction)
}
}
}
extension ThreadUtil {

@ -0,0 +1,20 @@
//
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
import Foundation
import PromiseKit
public extension YapDatabaseConnection {
@objc
func readWritePromise(_ block: @escaping (YapDatabaseReadWriteTransaction) -> Void) -> AnyPromise {
return AnyPromise(readWritePromise(block) as Promise<Void>)
}
func readWritePromise(_ block: @escaping (YapDatabaseReadWriteTransaction) -> Void) -> Promise<Void> {
return Promise { resolver in
self.asyncReadWrite(block, completionBlock: resolver.fulfill)
}
}
}
Loading…
Cancel
Save