Merge branch 'mkirk/reply-marks-as-read' into release/2.36.0

pull/2/head
Michael Kirk 6 years ago
commit 1d409ef80e

@ -1 +1 @@
Subproject commit 30865575d8f4ef74dc51e5bde3eab1cf7d458784 Subproject commit 434610837e73668d186716fd2e5b8913c84ef46a

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