|
|
|
@ -1,15 +1,30 @@
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
|
|
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
import SignalServiceKit
|
|
|
|
|
import SignalMessaging
|
|
|
|
|
|
|
|
|
|
@objc
|
|
|
|
|
public protocol LongTextViewDelegate {
|
|
|
|
|
@objc
|
|
|
|
|
func longTextViewMessageWasDeleted(_ longTextViewController: LongTextViewController)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc
|
|
|
|
|
public class LongTextViewController: OWSViewController {
|
|
|
|
|
|
|
|
|
|
// MARK: Properties
|
|
|
|
|
// MARK: - Dependencies
|
|
|
|
|
|
|
|
|
|
var uiDatabaseConnection: YapDatabaseConnection {
|
|
|
|
|
return OWSPrimaryStorage.shared().uiDatabaseConnection
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - Properties
|
|
|
|
|
|
|
|
|
|
@objc
|
|
|
|
|
weak var delegate: LongTextViewDelegate?
|
|
|
|
|
|
|
|
|
|
let viewItem: ConversationViewItem
|
|
|
|
|
|
|
|
|
@ -55,6 +70,54 @@ public class LongTextViewController: OWSViewController {
|
|
|
|
|
createViews()
|
|
|
|
|
|
|
|
|
|
self.messageTextView.contentOffset = CGPoint(x: 0, y: self.messageTextView.contentInset.top)
|
|
|
|
|
|
|
|
|
|
NotificationCenter.default.addObserver(self,
|
|
|
|
|
selector: #selector(uiDatabaseDidUpdate),
|
|
|
|
|
name: .OWSUIDatabaseConnectionDidUpdate,
|
|
|
|
|
object: OWSPrimaryStorage.shared().dbNotificationObject)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - DB
|
|
|
|
|
|
|
|
|
|
@objc internal func uiDatabaseDidUpdate(notification: NSNotification) {
|
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
|
|
|
|
|
|
guard let notifications = notification.userInfo?[OWSUIDatabaseConnectionNotificationsKey] as? [Notification] else {
|
|
|
|
|
owsFailDebug("notifications was unexpectedly nil")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guard let uniqueId = self.viewItem.interaction.uniqueId else {
|
|
|
|
|
Logger.error("Message is missing uniqueId.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guard self.uiDatabaseConnection.hasChange(forKey: uniqueId,
|
|
|
|
|
inCollection: TSInteraction.collection(),
|
|
|
|
|
in: notifications) else {
|
|
|
|
|
Logger.debug("No relevant changes.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
try uiDatabaseConnection.read { transaction in
|
|
|
|
|
guard TSInteraction.fetch(uniqueId: uniqueId, transaction: transaction) != nil else {
|
|
|
|
|
Logger.error("Message was deleted")
|
|
|
|
|
throw LongTextViewError.messageWasDeleted
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch LongTextViewError.messageWasDeleted {
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
self.delegate?.longTextViewMessageWasDeleted(self)
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
owsFailDebug("unexpected error: \(error)")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum LongTextViewError: Error {
|
|
|
|
|
case messageWasDeleted
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - Create Views
|
|
|
|
|