Minor refactoring

This commit is contained in:
Niels Andriesse 2021-01-28 13:33:50 +11:00
parent 4e590da262
commit 804377c5a4
4 changed files with 26 additions and 8 deletions

View file

@ -39,8 +39,18 @@ final class KeyPairMigrationSheet : Sheet {
upgradeNowButton.set(.width, to: 240)
upgradeNowButton.setTitle("Upgrade Now", for: UIControl.State.normal)
upgradeNowButton.addTarget(self, action: #selector(upgradeNow), for: UIControl.Event.touchUpInside)
// Upgrade now button
let upgradeLaterButton = Button(style: .prominentOutline, size: .large)
upgradeLaterButton.set(.width, to: 240)
upgradeLaterButton.setTitle("Upgrade Later", for: UIControl.State.normal)
upgradeLaterButton.addTarget(self, action: #selector(upgradeLater), for: UIControl.Event.touchUpInside)
// Button stack view
let buttonStackView = UIStackView(arrangedSubviews: [ upgradeNowButton, upgradeLaterButton ])
buttonStackView.axis = .vertical
buttonStackView.spacing = Values.mediumSpacing
buttonStackView.alignment = .center
// Main stack view
let stackView = UIStackView(arrangedSubviews: [ topStackView, explanationLabel, upgradeNowButton ])
let stackView = UIStackView(arrangedSubviews: [ topStackView, explanationLabel, buttonStackView ])
stackView.axis = .vertical
stackView.spacing = Values.veryLargeSpacing
stackView.alignment = .center
@ -55,4 +65,11 @@ final class KeyPairMigrationSheet : Sheet {
@objc private func upgradeNow() {
Storage.prepareForV2KeyPairMigration()
}
@objc private func upgradeLater() {
let alert = UIAlertController(title: "Warning", message: "You won't be able to send or receive messages until you upgrade.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", accessibilityIdentifier: nil, style: .default, handler: nil))
presentingViewController?.dismiss(animated: true, completion: nil) // Dismiss self
presentingViewController?.present(alert, animated: true, completion: nil)
}
}

View file

@ -98,9 +98,9 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
return handleFailure(error)
}
OWSFileSystem.deleteFile(temporaryFilePath.absoluteString)
storage.write(with: { transaction in
storage.write { transaction in
storage.persist(stream, associatedWith: self.tsIncomingMessageID, using: transaction)
}, completion: { })
}
}.catch(on: DispatchQueue.global()) { error in
handleFailure(error)
}

View file

@ -164,8 +164,6 @@ void AssertIsOnDisappearingMessagesQueue()
return;
}
NSTimeInterval startedSecondsAgo = ([NSDate ows_millisecondTimeStamp] - expirationStartedAt) / 1000.0;
// Don't clobber if multiple actions simultaneously triggered expiration.
if (message.expireStartedAt == 0 || message.expireStartedAt > expirationStartedAt) {
[message updateWithExpireStartedAt:expirationStartedAt transaction:transaction];
@ -191,7 +189,7 @@ void AssertIsOnDisappearingMessagesQueue()
NSString *_Nullable remoteContactName = nil;
if (remoteRecipientId) {
remoteContactName = [SSKEnvironment.shared.profileManager profileNameForRecipientWithID:remoteRecipientId avoidingWriteTransaction:YES];
remoteContactName = [SSKEnvironment.shared.profileManager profileNameForRecipientWithID:remoteRecipientId avoidingWriteTransaction:YES] ?: remoteRecipientId;
}
// Become eventually consistent in the case that the remote changed their settings at the same time.

View file

@ -340,14 +340,16 @@ public final class MessageSender : NSObject {
// MARK: Success & Failure Handling
public static func handleSuccessfulMessageSend(_ message: Message, to destination: Message.Destination, using transaction: Any) {
guard let tsMessage = TSOutgoingMessage.find(withTimestamp: message.sentTimestamp!) else { return }
tsMessage.openGroupServerMessageID = message.openGroupServerMessageID ?? 0
let storage = SNMessagingKitConfiguration.shared.storage
let transaction = transaction as! YapDatabaseReadWriteTransaction
guard let tsMessage = TSOutgoingMessage.find(withTimestamp: message.sentTimestamp!) else { return }
// Track the open group server message ID
tsMessage.openGroupServerMessageID = message.openGroupServerMessageID ?? 0
tsMessage.save(with: transaction)
if let serverID = message.openGroupServerMessageID {
storage.setIDForMessage(withServerID: serverID, to: tsMessage.uniqueId!, using: transaction)
}
// Mark the message as sent
var recipients = [ message.recipient! ]
if case .closedGroup(_) = destination, let threadID = message.threadID, // threadID should always be set at this point
let thread = TSGroupThread.fetch(uniqueId: threadID, transaction: transaction), thread.isClosedGroup {
@ -356,6 +358,7 @@ public final class MessageSender : NSObject {
recipients.forEach { recipient in
tsMessage.update(withSentRecipient: recipient, wasSentByUD: true, transaction: transaction)
}
// Start the disappearing messages timer if needed
OWSDisappearingMessagesJob.shared().startAnyExpiration(for: tsMessage, expirationStartedAt: NSDate.millisecondTimestamp(), transaction: transaction)
}