|
|
@ -283,10 +283,8 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
|
|
|
let linkPreviewDraft = snInputView.linkPreviewInfo?.draft
|
|
|
|
let linkPreviewDraft = snInputView.linkPreviewInfo?.draft
|
|
|
|
let tsMessage = TSOutgoingMessage.from(message, associatedWith: thread)
|
|
|
|
let tsMessage = TSOutgoingMessage.from(message, associatedWith: thread)
|
|
|
|
|
|
|
|
|
|
|
|
Storage.write(with: { transaction in
|
|
|
|
|
|
|
|
let promise: Promise<Void> = self.approveMessageRequestIfNeeded(
|
|
|
|
let promise: Promise<Void> = self.approveMessageRequestIfNeeded(
|
|
|
|
for: self.thread,
|
|
|
|
for: self.thread,
|
|
|
|
with: transaction,
|
|
|
|
|
|
|
|
isNewThread: !oldThreadShouldBeVisible,
|
|
|
|
isNewThread: !oldThreadShouldBeVisible,
|
|
|
|
timestamp: (sentTimestamp - 1) // Set 1ms earlier as this is used for sorting
|
|
|
|
timestamp: (sentTimestamp - 1) // Set 1ms earlier as this is used for sorting
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -325,7 +323,6 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
promise.retainUntilComplete()
|
|
|
|
promise.retainUntilComplete()
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func sendAttachments(_ attachments: [SignalAttachment], with text: String, onComplete: (() -> ())? = nil) {
|
|
|
|
func sendAttachments(_ attachments: [SignalAttachment], with text: String, onComplete: (() -> ())? = nil) {
|
|
|
@ -349,10 +346,8 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
|
|
|
let oldThreadShouldBeVisible: Bool = thread.shouldBeVisible
|
|
|
|
let oldThreadShouldBeVisible: Bool = thread.shouldBeVisible
|
|
|
|
let tsMessage = TSOutgoingMessage.from(message, associatedWith: thread)
|
|
|
|
let tsMessage = TSOutgoingMessage.from(message, associatedWith: thread)
|
|
|
|
|
|
|
|
|
|
|
|
Storage.write(with: { transaction in
|
|
|
|
|
|
|
|
let promise: Promise<Void> = self.approveMessageRequestIfNeeded(
|
|
|
|
let promise: Promise<Void> = self.approveMessageRequestIfNeeded(
|
|
|
|
for: self.thread,
|
|
|
|
for: self.thread,
|
|
|
|
with: transaction,
|
|
|
|
|
|
|
|
isNewThread: !oldThreadShouldBeVisible,
|
|
|
|
isNewThread: !oldThreadShouldBeVisible,
|
|
|
|
timestamp: (sentTimestamp - 1) // Set 1ms earlier as this is used for sorting
|
|
|
|
timestamp: (sentTimestamp - 1) // Set 1ms earlier as this is used for sorting
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -386,7 +381,6 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
promise.retainUntilComplete()
|
|
|
|
promise.retainUntilComplete()
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func handleMessageSent() {
|
|
|
|
func handleMessageSent() {
|
|
|
@ -1128,7 +1122,7 @@ extension ConversationVC: UIDocumentInteractionControllerDelegate {
|
|
|
|
|
|
|
|
|
|
|
|
extension ConversationVC {
|
|
|
|
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(()) }
|
|
|
|
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
|
|
|
|
// If the contact doesn't exist then we should create it so we can store the 'isApproved' state
|
|
|
@ -1159,7 +1153,17 @@ extension ConversationVC {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return promise
|
|
|
|
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
|
|
|
|
.map { _ in
|
|
|
|
if self?.presentedViewController is ModalActivityIndicatorViewController {
|
|
|
|
if self?.presentedViewController is ModalActivityIndicatorViewController {
|
|
|
|
self?.dismiss(animated: true, completion: nil) // Dismiss the loader
|
|
|
|
self?.dismiss(animated: true, completion: nil) // Dismiss the loader
|
|
|
@ -1168,9 +1172,11 @@ extension ConversationVC {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.map { _ in
|
|
|
|
.map { _ in
|
|
|
|
// Default 'didApproveMe' to true for the person approving the message request
|
|
|
|
// Default 'didApproveMe' to true for the person approving the message request
|
|
|
|
|
|
|
|
Storage.write { transaction in
|
|
|
|
contact.isApproved = true
|
|
|
|
contact.isApproved = true
|
|
|
|
contact.didApproveMe = (contact.didApproveMe || !isNewThread)
|
|
|
|
contact.didApproveMe = (contact.didApproveMe || !isNewThread)
|
|
|
|
Storage.shared.setContact(contact, using: transaction)
|
|
|
|
Storage.shared.setContact(contact, using: transaction)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Hide the 'messageRequestView' since the request has been approved and force a config
|
|
|
|
// 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)
|
|
|
|
// sync to propagate the contact approval state (both must run on the main thread)
|
|
|
@ -1208,17 +1214,15 @@ extension ConversationVC {
|
|
|
|
|
|
|
|
|
|
|
|
// Send a sync message with the details of the contact
|
|
|
|
// Send a sync message with the details of the contact
|
|
|
|
if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
|
|
|
|
if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
|
|
|
|
appDelegate.forceSyncConfigurationNowIfNeeded(with: transaction).retainUntilComplete()
|
|
|
|
appDelegate.forceSyncConfigurationNowIfNeeded().retainUntilComplete()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@objc func acceptMessageRequest() {
|
|
|
|
@objc func acceptMessageRequest() {
|
|
|
|
Storage.write { transaction in
|
|
|
|
|
|
|
|
let promise: Promise<Void> = self.approveMessageRequestIfNeeded(
|
|
|
|
let promise: Promise<Void> = self.approveMessageRequestIfNeeded(
|
|
|
|
for: self.thread,
|
|
|
|
for: self.thread,
|
|
|
|
with: transaction,
|
|
|
|
|
|
|
|
isNewThread: false,
|
|
|
|
isNewThread: false,
|
|
|
|
timestamp: NSDate.millisecondTimestamp()
|
|
|
|
timestamp: NSDate.millisecondTimestamp()
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -1232,7 +1236,6 @@ extension ConversationVC {
|
|
|
|
|
|
|
|
|
|
|
|
promise.retainUntilComplete()
|
|
|
|
promise.retainUntilComplete()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@objc func deleteMessageRequest() {
|
|
|
|
@objc func deleteMessageRequest() {
|
|
|
|
guard let uniqueId: String = thread.uniqueId else { return }
|
|
|
|
guard let uniqueId: String = thread.uniqueId else { return }
|
|
|
|