Fix disappearing messages
This commit is contained in:
parent
341782f255
commit
3eae001202
|
@ -34,7 +34,7 @@ final class OptionView : UIView {
|
|||
// Set up shadow
|
||||
layer.shadowColor = UIColor.black.cgColor
|
||||
layer.shadowOffset = CGSize(width: 0, height: 0.8)
|
||||
layer.shadowOpacity = isLightMode ? 0.4 : 1
|
||||
layer.shadowOpacity = isLightMode ? 0.16 : 1
|
||||
layer.shadowRadius = isLightMode ? 4 : 6
|
||||
// Set up title label
|
||||
let titleLabel = UILabel()
|
||||
|
|
|
@ -864,7 +864,7 @@ static CGRect oldframe;
|
|||
}
|
||||
|
||||
if (self.disappearingMessagesConfiguration.dictionaryValueDidChange) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.disappearingMessagesConfiguration saveWithTransaction:transaction];
|
||||
OWSDisappearingConfigurationUpdateInfoMessage *infoMessage = [[OWSDisappearingConfigurationUpdateInfoMessage alloc]
|
||||
initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
||||
|
|
|
@ -58,6 +58,6 @@ public final class ExpirationTimerUpdate : ControlMessage {
|
|||
|
||||
// MARK: Convenience
|
||||
@objc public func setDuration(_ duration: UInt32) {
|
||||
|
||||
self.duration = duration
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,44 +93,44 @@ extension MessageReceiver {
|
|||
|
||||
public static func setExpirationTimer(to duration: UInt32, for senderPublicKey: String, groupPublicKey: String?, using transaction: Any) {
|
||||
let transaction = transaction as! YapDatabaseReadWriteTransaction
|
||||
var isGroup = false
|
||||
var threadOrNil: TSThread?
|
||||
Storage.read { transaction in
|
||||
if let groupPublicKey = groupPublicKey {
|
||||
guard Storage.shared.isClosedGroup(groupPublicKey) else { return }
|
||||
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
|
||||
threadOrNil = TSGroupThread.fetch(uniqueId: TSGroupThread.threadId(fromGroupId: groupID), transaction: transaction)
|
||||
} else {
|
||||
threadOrNil = TSContactThread.getWithContactId(senderPublicKey, transaction: transaction)
|
||||
}
|
||||
if let groupPublicKey = groupPublicKey {
|
||||
guard Storage.shared.isClosedGroup(groupPublicKey) else { return }
|
||||
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
|
||||
threadOrNil = TSGroupThread.fetch(uniqueId: TSGroupThread.threadId(fromGroupId: groupID), transaction: transaction)
|
||||
isGroup = true
|
||||
} else {
|
||||
threadOrNil = TSContactThread.getWithContactId(senderPublicKey, transaction: transaction)
|
||||
}
|
||||
guard let thread = threadOrNil else { return }
|
||||
let configuration = OWSDisappearingMessagesConfiguration(threadId: thread.uniqueId!, enabled: true, durationSeconds: duration)
|
||||
configuration.save(with: transaction)
|
||||
let senderDisplayName = SSKEnvironment.shared.profileManager.profileNameForRecipient(withID: senderPublicKey, transaction: transaction)
|
||||
let senderDisplayName = SSKEnvironment.shared.profileManager.profileNameForRecipient(withID: senderPublicKey, transaction: transaction) ?? senderPublicKey
|
||||
let message = OWSDisappearingConfigurationUpdateInfoMessage(timestamp: NSDate.millisecondTimestamp(), thread: thread,
|
||||
configuration: configuration, createdByRemoteName: senderDisplayName, createdInExistingGroup: false)
|
||||
configuration: configuration, createdByRemoteName: senderDisplayName, createdInExistingGroup: isGroup)
|
||||
message.save(with: transaction)
|
||||
SSKEnvironment.shared.disappearingMessagesJob.startIfNecessary()
|
||||
}
|
||||
|
||||
public static func disableExpirationTimer(for senderPublicKey: String, groupPublicKey: String?, using transaction: Any) {
|
||||
let transaction = transaction as! YapDatabaseReadWriteTransaction
|
||||
var isGroup = false
|
||||
var threadOrNil: TSThread?
|
||||
Storage.read { transaction in
|
||||
if let groupPublicKey = groupPublicKey {
|
||||
guard Storage.shared.isClosedGroup(groupPublicKey) else { return }
|
||||
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
|
||||
threadOrNil = TSGroupThread.fetch(uniqueId: TSGroupThread.threadId(fromGroupId: groupID), transaction: transaction)
|
||||
} else {
|
||||
threadOrNil = TSContactThread.getWithContactId(senderPublicKey, transaction: transaction)
|
||||
}
|
||||
if let groupPublicKey = groupPublicKey {
|
||||
guard Storage.shared.isClosedGroup(groupPublicKey) else { return }
|
||||
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
|
||||
threadOrNil = TSGroupThread.fetch(uniqueId: TSGroupThread.threadId(fromGroupId: groupID), transaction: transaction)
|
||||
isGroup = true
|
||||
} else {
|
||||
threadOrNil = TSContactThread.getWithContactId(senderPublicKey, transaction: transaction)
|
||||
}
|
||||
guard let thread = threadOrNil else { return }
|
||||
let configuration = OWSDisappearingMessagesConfiguration(threadId: thread.uniqueId!, enabled: false, durationSeconds: 24 * 60 * 60)
|
||||
configuration.save(with: transaction)
|
||||
let senderDisplayName = SSKEnvironment.shared.profileManager.profileNameForRecipient(withID: senderPublicKey, transaction: transaction)
|
||||
let senderDisplayName = SSKEnvironment.shared.profileManager.profileNameForRecipient(withID: senderPublicKey, transaction: transaction) ?? senderPublicKey
|
||||
let message = OWSDisappearingConfigurationUpdateInfoMessage(timestamp: NSDate.millisecondTimestamp(), thread: thread,
|
||||
configuration: configuration, createdByRemoteName: senderDisplayName, createdInExistingGroup: false)
|
||||
configuration: configuration, createdByRemoteName: senderDisplayName, createdInExistingGroup: isGroup)
|
||||
message.save(with: transaction)
|
||||
SSKEnvironment.shared.disappearingMessagesJob.startIfNecessary()
|
||||
}
|
||||
|
|
|
@ -235,17 +235,4 @@ public final class MessageSender : NSObject {
|
|||
// Return
|
||||
return promise
|
||||
}
|
||||
|
||||
// MARK: Result Handling
|
||||
public static func handleSuccessfulMessageSend(_ message: Message, using transaction: Any) {
|
||||
guard let tsMessage = TSOutgoingMessage.find(withTimestamp: message.sentTimestamp!) else { return }
|
||||
tsMessage.openGroupServerMessageID = message.openGroupServerMessageID ?? 0
|
||||
tsMessage.isOpenGroupMessage = tsMessage.openGroupServerMessageID != 0
|
||||
tsMessage.update(withSentRecipient: message.recipient!, wasSentByUD: true, transaction: transaction as! YapDatabaseReadWriteTransaction)
|
||||
}
|
||||
|
||||
public static func handleFailedMessageSend(_ message: Message, with error: Swift.Error, using transaction: Any) {
|
||||
guard let tsMessage = TSOutgoingMessage.find(withTimestamp: message.sentTimestamp!) else { return }
|
||||
tsMessage.update(sendingError: error, transaction: transaction as! YapDatabaseReadWriteTransaction)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,23 @@ extension MessageSender : SharedSenderKeysDelegate {
|
|||
let destination = Message.Destination.from(thread)
|
||||
return MessageSender.send(message, to: destination, using: transaction)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: - Success & Failure Handling
|
||||
|
||||
public static func handleSuccessfulMessageSend(_ message: Message, using transaction: Any) {
|
||||
guard let tsMessage = TSOutgoingMessage.find(withTimestamp: message.sentTimestamp!) else { return }
|
||||
tsMessage.openGroupServerMessageID = message.openGroupServerMessageID ?? 0
|
||||
tsMessage.isOpenGroupMessage = tsMessage.openGroupServerMessageID != 0
|
||||
tsMessage.update(withSentRecipient: message.recipient!, wasSentByUD: true, transaction: transaction as! YapDatabaseReadWriteTransaction)
|
||||
OWSDisappearingMessagesJob.shared().startAnyExpiration(for: tsMessage, expirationStartedAt: NSDate.millisecondTimestamp(), transaction: transaction as! YapDatabaseReadWriteTransaction)
|
||||
}
|
||||
|
||||
public static func handleFailedMessageSend(_ message: Message, with error: Swift.Error, using transaction: Any) {
|
||||
guard let tsMessage = TSOutgoingMessage.find(withTimestamp: message.sentTimestamp!) else { return }
|
||||
tsMessage.update(sendingError: error, transaction: transaction as! YapDatabaseReadWriteTransaction)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue