|
|
|
@ -263,10 +263,8 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
|
|
|
|
let linkPreviewDraft = snInputView.linkPreviewInfo?.draft
|
|
|
|
|
let tsMessage = TSOutgoingMessage.from(message, associatedWith: thread)
|
|
|
|
|
|
|
|
|
|
Storage.write(with: { transaction in
|
|
|
|
|
let promise: Promise<Void> = self.approveMessageRequestIfNeeded(
|
|
|
|
|
for: self.thread,
|
|
|
|
|
with: transaction,
|
|
|
|
|
isNewThread: !oldThreadShouldBeVisible,
|
|
|
|
|
timestamp: (sentTimestamp - 1) // Set 1ms earlier as this is used for sorting
|
|
|
|
|
)
|
|
|
|
@ -305,7 +303,6 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
promise.retainUntilComplete()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sendAttachments(_ attachments: [SignalAttachment], with text: String, onComplete: (() -> ())? = nil) {
|
|
|
|
@ -329,10 +326,8 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
|
|
|
|
let oldThreadShouldBeVisible: Bool = thread.shouldBeVisible
|
|
|
|
|
let tsMessage = TSOutgoingMessage.from(message, associatedWith: thread)
|
|
|
|
|
|
|
|
|
|
Storage.write(with: { transaction in
|
|
|
|
|
let promise: Promise<Void> = self.approveMessageRequestIfNeeded(
|
|
|
|
|
for: self.thread,
|
|
|
|
|
with: transaction,
|
|
|
|
|
isNewThread: !oldThreadShouldBeVisible,
|
|
|
|
|
timestamp: (sentTimestamp - 1) // Set 1ms earlier as this is used for sorting
|
|
|
|
|
)
|
|
|
|
@ -366,7 +361,6 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
promise.retainUntilComplete()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleMessageSent() {
|
|
|
|
@ -1103,7 +1097,7 @@ extension ConversationVC: UIDocumentInteractionControllerDelegate {
|
|
|
|
|
|
|
|
|
|
extension ConversationVC {
|
|
|
|
|
|
|
|
|
|
fileprivate func approveMessageRequestIfNeeded(for thread: TSThread?, with transaction: YapDatabaseReadWriteTransaction, isNewThread: Bool, timestamp: UInt64) -> Promise<Void> {
|
|
|
|
|
fileprivate func approveMessageRequestIfNeeded(for thread: TSThread?, isNewThread: Bool, timestamp: UInt64) -> Promise<Void> {
|
|
|
|
|
guard let contactThread: TSContactThread = thread as? TSContactThread else { return Promise.value(()) }
|
|
|
|
|
|
|
|
|
|
// If the contact doesn't exist then we should create it so we can store the 'isApproved' state
|
|
|
|
@ -1134,7 +1128,17 @@ extension ConversationVC {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return promise
|
|
|
|
|
.then { MessageSender.sendNonDurably(messageRequestResponse, in: contactThread, using: transaction) }
|
|
|
|
|
.then { _ -> Promise<Void> in
|
|
|
|
|
let (promise, seal) = Promise<Void>.pending()
|
|
|
|
|
Storage.writeSync { transaction in
|
|
|
|
|
MessageSender.sendNonDurably(messageRequestResponse, in: contactThread, using: transaction)
|
|
|
|
|
.done { seal.fulfill(()) }
|
|
|
|
|
.catch { _ in seal.fulfill(()) } // Fulfill even if this failed; the configuration in the swarm should be at most 2 days old
|
|
|
|
|
.retainUntilComplete()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return promise
|
|
|
|
|
}
|
|
|
|
|
.map { _ in
|
|
|
|
|
if self?.presentedViewController is ModalActivityIndicatorViewController {
|
|
|
|
|
self?.dismiss(animated: true, completion: nil) // Dismiss the loader
|
|
|
|
@ -1143,9 +1147,11 @@ extension ConversationVC {
|
|
|
|
|
}
|
|
|
|
|
.map { _ in
|
|
|
|
|
// Default 'didApproveMe' to true for the person approving the message request
|
|
|
|
|
Storage.write { transaction in
|
|
|
|
|
contact.isApproved = true
|
|
|
|
|
contact.didApproveMe = (contact.didApproveMe || !isNewThread)
|
|
|
|
|
Storage.shared.setContact(contact, using: transaction)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hide the 'messageRequestView' since the request has been approved and force a config
|
|
|
|
|
// sync to propagate the contact approval state (both must run on the main thread)
|
|
|
|
@ -1190,10 +1196,8 @@ extension ConversationVC {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc func acceptMessageRequest() {
|
|
|
|
|
Storage.write { transaction in
|
|
|
|
|
let promise: Promise<Void> = self.approveMessageRequestIfNeeded(
|
|
|
|
|
for: self.thread,
|
|
|
|
|
with: transaction,
|
|
|
|
|
isNewThread: false,
|
|
|
|
|
timestamp: NSDate.millisecondTimestamp()
|
|
|
|
|
)
|
|
|
|
@ -1207,7 +1211,6 @@ extension ConversationVC {
|
|
|
|
|
|
|
|
|
|
promise.retainUntilComplete()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc func deleteMessageRequest() {
|
|
|
|
|
guard let uniqueId: String = thread.uniqueId else { return }
|
|
|
|
|