Enable swiftformat for the NSE and SAE

This commit is contained in:
Sasha Weiss 2025-12-19 17:30:15 -08:00 committed by GitHub
parent acde31f908
commit 4cf438d740
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 149 additions and 127 deletions

View File

@ -6,9 +6,7 @@
# Temporary excludes.
--exclude Signal
--exclude SignalNSE
--exclude SignalServiceKit
--exclude SignalShareExtension
--exclude SignalUI
--swift-version 6.2

View File

@ -37,7 +37,7 @@ class NSECallMessageHandler: CallMessageHandler {
sentAtTimestamp: UInt64,
serverReceivedTimestamp: UInt64,
serverDeliveryTimestamp: UInt64,
tx: DBWriteTransaction
tx: DBWriteTransaction,
) {
let bufferSecondsForMainAppToAnswerRing: UInt64 = 10
@ -54,7 +54,7 @@ class NSECallMessageHandler: CallMessageHandler {
identityManager: identityManager,
notificationPresenter: notificationPresenter,
profileManager: profileManager,
tsAccountManager: tsAccountManager
tsAccountManager: tsAccountManager,
)
let partialResult = callOfferHandler.startHandlingOffer(
caller: caller.aci,
@ -63,7 +63,7 @@ class NSECallMessageHandler: CallMessageHandler {
callId: offer.id,
callType: offer.type ?? .offerAudioCall,
sentAtTimestamp: sentAtTimestamp,
tx: tx
tx: tx,
)
guard let partialResult else {
return
@ -77,7 +77,7 @@ class NSECallMessageHandler: CallMessageHandler {
let isValid = isValidOfferMessage(
opaque: opaque,
messageAgeSec: messageAgeForRingRtc,
callMediaType: callType
callMediaType: callType,
)
guard isValid else {
NSELogger.uncorrelated.warn("missed a call because it's not valid (according to RingRTC)")
@ -87,7 +87,7 @@ class NSECallMessageHandler: CallMessageHandler {
outcome: .incomingMissed,
callType: partialResult.offerMediaType,
sentAtTimestamp: sentAtTimestamp,
tx: tx
tx: tx,
)
return
}
@ -110,11 +110,13 @@ class NSECallMessageHandler: CallMessageHandler {
return false
}
guard GroupMessageProcessorManager.discardMode(
forMessageFrom: caller.aci,
groupId: groupId,
tx: transaction
) == .doNotDiscard else {
guard
GroupMessageProcessorManager.discardMode(
forMessageFrom: caller.aci,
groupId: groupId,
tx: transaction,
) == .doNotDiscard
else {
NSELogger.uncorrelated.warn("discarding group ring \(ringId) from \(caller.aci)")
return false
}
@ -138,7 +140,7 @@ class NSECallMessageHandler: CallMessageHandler {
return isValidOpaqueRing(
opaqueCallMessage: opaqueData,
messageAgeSec: messageAgeForRingRtc,
validateGroupRing: validateGroupRing
validateGroupRing: validateGroupRing,
)
}()
guard shouldHandleExternally else {
@ -156,7 +158,7 @@ class NSECallMessageHandler: CallMessageHandler {
plaintextData: plaintextData,
wasReceivedByUD: wasReceivedByUD,
serverDeliveryTimestamp: serverDeliveryTimestamp,
tx: tx
tx: tx,
)
}
@ -165,7 +167,7 @@ class NSECallMessageHandler: CallMessageHandler {
plaintextData: Data,
wasReceivedByUD: Bool,
serverDeliveryTimestamp: UInt64,
tx: DBWriteTransaction
tx: DBWriteTransaction,
) {
do {
let payload = try CallMessageRelay.enqueueCallMessageForMainApp(
@ -173,7 +175,7 @@ class NSECallMessageHandler: CallMessageHandler {
plaintextData: plaintextData,
wasReceivedByUD: wasReceivedByUD,
serverDeliveryTimestamp: serverDeliveryTimestamp,
transaction: tx
transaction: tx,
)
// We don't want to risk consuming any call messages that the main app needs to perform the call
@ -185,7 +187,7 @@ class NSECallMessageHandler: CallMessageHandler {
NSELogger.uncorrelated.info("Notifying primary app of incoming call with push payload: \(payload)")
CXProvider.reportNewIncomingVoIPPushPayload(payload.payloadDict) { error in
if let error = error {
if let error {
owsFailDebug("Failed to notify main app of call message: \(error)")
} else {
NSELogger.uncorrelated.info("Successfully notified main app of call message.")
@ -199,14 +201,14 @@ class NSECallMessageHandler: CallMessageHandler {
func receivedGroupCallUpdateMessage(
_ updateMessage: SSKProtoDataMessageGroupCallUpdate,
forGroupId groupId: GroupIdentifier,
serverReceivedTimestamp: UInt64
serverReceivedTimestamp: UInt64,
) async {
await groupCallManager.peekGroupCallAndUpdateThread(
forGroupId: groupId,
peekTrigger: .receivedGroupUpdateMessage(
eraId: updateMessage.eraID,
messageTimestamp: serverReceivedTimestamp
)
messageTimestamp: serverReceivedTimestamp,
),
)
}
}

View File

@ -47,7 +47,7 @@ class NSEContext: NSObject, AppContext {
let memoryPressureSource = DispatchSource.makeMemoryPressureSource(
eventMask: .all,
queue: .global()
queue: .global(),
)
override init() {
@ -88,7 +88,7 @@ class NSEContext: NSObject, AppContext {
}
}
fileprivate extension DispatchSourceMemoryPressure {
private extension DispatchSourceMemoryPressure {
var memoryEvent: DispatchSource.MemoryPressureEvent {
DispatchSource.MemoryPressureEvent(rawValue: data)
}

View File

@ -50,7 +50,7 @@ class NSEEnvironment {
let databaseStorage = try SDSDatabaseStorage(
appReadiness: appReadiness,
databaseFileUrl: SDSDatabaseStorage.grdbDatabaseFileUrl,
keychainStorage: keychainStorage
keychainStorage: keychainStorage,
)
databaseStorage.grdbStorage.setUpDatabasePathKVO()

View File

@ -12,7 +12,7 @@ class NSELogger: PrefixedLogger {
convenience init() {
self.init(
prefix: "[NSE]",
suffix: "{{\(UUID().uuidString)}}"
suffix: "{{\(UUID().uuidString)}}",
)
}
}

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import UserNotifications
import SignalServiceKit
import UserNotifications
// The lifecycle of the NSE looks something like the following:
// 1) App receives notification
@ -83,7 +83,7 @@ class NotificationService: UNNotificationServiceExtension {
override func didReceive(
_ request: UNNotificationRequest,
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void,
) {
let logger = NSELogger()
_ = Self.nseDidStart()
@ -109,7 +109,7 @@ class NotificationService: UNNotificationServiceExtension {
let content = UNMutableNotificationContent()
let notificationFormat = OWSLocalizedString(
"NOTIFICATION_BODY_PHONE_LOCKED_FORMAT",
comment: "Lock screen notification text presented after user powers on their device without unlocking. Embeds {{device model}} (either 'iPad' or 'iPhone')"
comment: "Lock screen notification text presented after user powers on their device without unlocking. Embeds {{device model}} (either 'iPad' or 'iPhone')",
)
content.body = String(format: notificationFormat, UIDevice.current.localizedModel)
return content
@ -130,7 +130,7 @@ class NotificationService: UNNotificationServiceExtension {
// Re-set up the local identifiers to ensure they're propagated throughout the system.
switch finalContinuation.setUpLocalIdentifiers(
willResumeInProgressRegistration: false,
canInitiateRegistration: false
canInitiateRegistration: false,
) {
case .corruptRegistrationState:
Logger.warn("Ignoring request to process notifications when the user isn't registered.")
@ -170,8 +170,8 @@ class NotificationService: UNNotificationServiceExtension {
try await Preconditions([
NotificationPrecondition(
notificationName: .isSignalProxyReadyDidChange,
isSatisfied: { SignalProxy.isEnabledAndReady }
)
isSatisfied: { SignalProxy.isEnabledAndReady },
),
]).waitUntilSatisfied()
}
}

View File

@ -85,7 +85,7 @@ class SAEFailedViewController: UIViewController {
// MARK: - Event Handlers
private func cancelPressed() {
guard let delegate = delegate else {
guard let delegate else {
owsFailDebug("missing delegate")
return
}

View File

@ -3,10 +3,10 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import UIKit
import PureLayout
import SignalServiceKit
import SignalUI
import UIKit
class SAELoadViewController: UIViewController, OWSNavigationChildController {
@ -73,8 +73,8 @@ class SAELoadViewController: UIViewController, OWSNavigationChildController {
self.view.backgroundColor = (
self.shouldMimicRecipientPicker
? Theme.tableView2PresentedBackgroundColor
: Theme.backgroundColor
? Theme.tableView2PresentedBackgroundColor
: Theme.backgroundColor,
)
let activityIndicator = UIActivityIndicatorView(style: .large)
@ -96,8 +96,10 @@ class SAELoadViewController: UIViewController, OWSNavigationChildController {
let label = UILabel()
label.textColor = Theme.primaryTextColor
label.font = .systemFont(ofSize: 17)
label.text = OWSLocalizedString("SHARE_EXTENSION_LOADING",
comment: "Indicates that the share extension is still loading.")
label.text = OWSLocalizedString(
"SHARE_EXTENSION_LOADING",
comment: "Indicates that the share extension is still loading.",
)
self.view.addSubview(label)
label.autoHCenterInSuperview()
label.autoPinEdge(.top, to: .bottom, of: activityIndicator, withOffset: 12)

View File

@ -110,7 +110,7 @@ final class SAEScreenLockViewController: ScreenLockViewController {
self.isShowingAuthUI = false
self.ensureUI()
}
},
)
ensureUI()
@ -122,13 +122,13 @@ final class SAEScreenLockViewController: ScreenLockViewController {
OWSActionSheets.showActionSheet(
title: OWSLocalizedString(
"SCREEN_LOCK_UNLOCK_FAILED",
comment: "Title for alert indicating that screen lock could not be unlocked."
comment: "Title for alert indicating that screen lock could not be unlocked.",
),
buttonAction: { _ in
// After the alert, update the UI.
self.ensureUI()
},
fromViewController: self
fromViewController: self,
)
}

View File

@ -18,7 +18,7 @@ final class ShareAppExtensionContext: NSObject {
private var notificationCenterObservers = [NSObjectProtocol]()
static private let isRTL: Bool = {
private static let isRTL: Bool = {
// Borrowed from PureLayout's AppExtension compatible RTL support.
// App Extensions may not access UIApplication.sharedApplication.
// Fall back to checking the bundle's preferred localization character direction
@ -32,61 +32,73 @@ final class ShareAppExtensionContext: NSObject {
super.init()
let mainQueue = OperationQueue.main
notificationCenterObservers.append(NotificationCenter.default.addObserver(
forName: NSNotification.Name.NSExtensionHostDidBecomeActive,
object: nil,
queue: mainQueue) { [weak self] notification in
notificationCenterObservers.append(
NotificationCenter.default.addObserver(
forName: NSNotification.Name.NSExtensionHostDidBecomeActive,
object: nil,
queue: mainQueue,
) { [weak self] notification in
Logger.info("NSExtensionHostDidBecomeActive")
self?.internalReportedApplicationState = .active
BenchManager.bench(
title: "Slow post DidBecomeActive",
logIfLongerThan: 0.01,
logInProduction: true) {
NotificationCenter.default.post(name: NSNotification.Name.OWSApplicationDidBecomeActive, object: nil)
}
}
logInProduction: true,
) {
NotificationCenter.default.post(name: NSNotification.Name.OWSApplicationDidBecomeActive, object: nil)
}
},
)
notificationCenterObservers.append(NotificationCenter.default.addObserver(
forName: NSNotification.Name.NSExtensionHostWillResignActive,
object: nil,
queue: mainQueue) { [weak self] notification in
notificationCenterObservers.append(
NotificationCenter.default.addObserver(
forName: NSNotification.Name.NSExtensionHostWillResignActive,
object: nil,
queue: mainQueue,
) { [weak self] notification in
Logger.info("NSExtensionHostWillResignActive")
self?.internalReportedApplicationState = .inactive
BenchManager.bench(
title: "Slow post WillResignActive",
logIfLongerThan: 0.01,
logInProduction: true) {
NotificationCenter.default.post(name: NSNotification.Name.OWSApplicationWillResignActive, object: nil)
}
}
logInProduction: true,
) {
NotificationCenter.default.post(name: NSNotification.Name.OWSApplicationWillResignActive, object: nil)
}
},
)
notificationCenterObservers.append(NotificationCenter.default.addObserver(
forName: NSNotification.Name.NSExtensionHostDidEnterBackground,
object: nil,
queue: mainQueue) { [weak self] notification in
notificationCenterObservers.append(
NotificationCenter.default.addObserver(
forName: NSNotification.Name.NSExtensionHostDidEnterBackground,
object: nil,
queue: mainQueue,
) { [weak self] notification in
Logger.info("NSExtensionHostDidEnterBackground")
self?.internalReportedApplicationState = .background
BenchManager.bench(
title: "Slow post DidEnterBackground",
logIfLongerThan: 0.01,
logInProduction: true) {
NotificationCenter.default.post(name: NSNotification.Name.OWSApplicationDidEnterBackground, object: nil)
}
}
logInProduction: true,
) {
NotificationCenter.default.post(name: NSNotification.Name.OWSApplicationDidEnterBackground, object: nil)
}
},
)
notificationCenterObservers.append(NotificationCenter.default.addObserver(
forName: NSNotification.Name.NSExtensionHostWillEnterForeground,
object: nil,
queue: mainQueue) { [weak self] notification in
notificationCenterObservers.append(
NotificationCenter.default.addObserver(
forName: NSNotification.Name.NSExtensionHostWillEnterForeground,
object: nil,
queue: mainQueue,
) { [weak self] notification in
Logger.info("NSExtensionHostWillEnterForeground")
self?.internalReportedApplicationState = .inactive
BenchManager.bench(
title: "Slow post WillEnterForeground",
logIfLongerThan: 0.01,
logInProduction: true) {
NotificationCenter.default.post(name: NSNotification.Name.OWSApplicationWillEnterForeground, object: nil)
}
}
logInProduction: true,
) {
NotificationCenter.default.post(name: NSNotification.Name.OWSApplicationWillEnterForeground, object: nil)
}
},
)
}
@ -141,10 +153,11 @@ extension ShareAppExtensionContext: AppContext {
}
func appDocumentDirectoryPath() -> String {
guard let documentDirectoryURL = FileManager.default.urls(
for: .documentDirectory,
in: .userDomainMask
).last
guard
let documentDirectoryURL = FileManager.default.urls(
for: .documentDirectory,
in: .userDomainMask,
).last
else {
owsFail("Could not find documents directory.")
}
@ -152,9 +165,10 @@ extension ShareAppExtensionContext: AppContext {
}
func appSharedDataDirectoryPath() -> String {
guard let groupContainerDirectoryURL = FileManager.default.containerURL(
forSecurityApplicationGroupIdentifier: TSConstants.applicationGroup
)
guard
let groupContainerDirectoryURL = FileManager.default.containerURL(
forSecurityApplicationGroupIdentifier: TSConstants.applicationGroup,
)
else {
owsFail("Could not find application group directory.")
}

View File

@ -53,7 +53,7 @@ public class ShareViewController: OWSNavigationController, ShareViewDelegate, SA
self.initialLoadViewController = initialLoadViewController
}
public override func viewDidAppear(_ animated: Bool) {
override public func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let initialLoadViewController = self.initialLoadViewController.take() {
@ -74,7 +74,7 @@ public class ShareViewController: OWSNavigationController, ShareViewDelegate, SA
databaseStorage = try SDSDatabaseStorage(
appReadiness: appReadiness,
databaseFileUrl: SDSDatabaseStorage.grdbDatabaseFileUrl,
keychainStorage: keychainStorage
keychainStorage: keychainStorage,
)
} catch {
self.showNotRegisteredView()
@ -103,14 +103,14 @@ public class ShareViewController: OWSNavigationController, ShareViewDelegate, SA
// Configure the rest of the globals before preparing the database.
SUIEnvironment.shared.setUp(
appReadiness: appReadiness,
authCredentialManager: databaseContinuation.authCredentialManager
authCredentialManager: databaseContinuation.authCredentialManager,
)
let finalContinuation = await databaseContinuation.migrateDatabaseData()
finalContinuation.runLaunchTasksIfNeededAndReloadCaches()
switch finalContinuation.setUpLocalIdentifiers(
willResumeInProgressRegistration: false,
canInitiateRegistration: false
canInitiateRegistration: false,
) {
case .corruptRegistrationState:
self.showNotRegisteredView()
@ -154,7 +154,7 @@ public class ShareViewController: OWSNavigationController, ShareViewDelegate, SA
let conversationPicker: SharingThreadPickerViewController
conversationPicker = SharingThreadPickerViewController(
areAttachmentStoriesCompatPrecheck: typedItemProviders.allSatisfy { $0.isStoriesCompatible },
shareViewDelegate: self
shareViewDelegate: self,
)
let preSelectedThread = self.fetchPreSelectedThread()
@ -202,7 +202,7 @@ public class ShareViewController: OWSNavigationController, ShareViewDelegate, SA
}()
typedItems = try await buildAndValidateAttachments(
for: typedItemProviders,
setProgress: { loadViewControllerForProgress?.progress = $0 }
setProgress: { loadViewControllerForProgress?.progress = $0 },
)
} catch {
self.presentAttachmentError(error)
@ -227,7 +227,7 @@ public class ShareViewController: OWSNavigationController, ShareViewDelegate, SA
self,
selector: #selector(applicationDidEnterBackground),
name: .OWSApplicationDidEnterBackground,
object: nil
object: nil,
)
Logger.info("completed.")
@ -272,10 +272,14 @@ public class ShareViewController: OWSNavigationController, ShareViewDelegate, SA
private func showNotRegisteredView() {
AssertIsOnMainThread()
let failureTitle = OWSLocalizedString("SHARE_EXTENSION_NOT_REGISTERED_TITLE",
comment: "Title indicating that the share extension cannot be used until the user has registered in the main app.")
let failureMessage = OWSLocalizedString("SHARE_EXTENSION_NOT_REGISTERED_MESSAGE",
comment: "Message indicating that the share extension cannot be used until the user has registered in the main app.")
let failureTitle = OWSLocalizedString(
"SHARE_EXTENSION_NOT_REGISTERED_TITLE",
comment: "Title indicating that the share extension cannot be used until the user has registered in the main app.",
)
let failureMessage = OWSLocalizedString(
"SHARE_EXTENSION_NOT_REGISTERED_MESSAGE",
comment: "Message indicating that the share extension cannot be used until the user has registered in the main app.",
)
showErrorView(title: failureTitle, message: failureMessage)
}
@ -378,7 +382,7 @@ public class ShareViewController: OWSNavigationController, ShareViewDelegate, SA
private func buildAndValidateAttachments(
for typedItemProviders: [TypedItemProvider],
setProgress: @MainActor (Progress) -> Void
setProgress: @MainActor (Progress) -> Void,
) async throws -> [TypedItem] {
let progress = Progress(totalUnitCount: Int64(typedItemProviders.count))
@ -406,27 +410,27 @@ public class ShareViewController: OWSNavigationController, ShareViewDelegate, SA
case ShareViewControllerError.tooManyAttachments:
let format = OWSLocalizedString(
"IMAGE_PICKER_CAN_SELECT_NO_MORE_TOAST_FORMAT",
comment: "Momentarily shown to the user when attempting to select more images than is allowed. Embeds {{max number of items}} that can be shared."
comment: "Momentarily shown to the user when attempting to select more images than is allowed. Embeds {{max number of items}} that can be shared.",
)
let alertTitle = String(format: format, OWSFormat.formatInt(SignalAttachment.maxAttachmentsAllowed))
OWSActionSheets.showActionSheet(
title: alertTitle,
buttonTitle: CommonStrings.cancelButton
buttonTitle: CommonStrings.cancelButton,
) { _ in
self.shareViewWasCancelled()
}
default:
let alertTitle = OWSLocalizedString(
"SHARE_EXTENSION_UNABLE_TO_BUILD_ATTACHMENT_ALERT_TITLE",
comment: "Shown when trying to share content to a Signal user for the share extension. Followed by failure details."
comment: "Shown when trying to share content to a Signal user for the share extension. Followed by failure details.",
)
OWSActionSheets.showActionSheet(
title: alertTitle,
message: error.userErrorDescription,
buttonTitle: CommonStrings.cancelButton
buttonTitle: CommonStrings.cancelButton,
) { _ in
self.shareViewWasCancelled()
}
@ -445,9 +449,11 @@ public class ShareViewController: OWSNavigationController, ShareViewDelegate, SA
// Handle safari sharing images and PDFs as two separate items one with the object to share and the other as the URL of the data.
for extensionItem in extensionItems {
for attachment in extensionItem.attachments ?? [] {
if attachment.hasItemConformingToTypeIdentifier(UTType.data.identifier)
if
attachment.hasItemConformingToTypeIdentifier(UTType.data.identifier)
|| attachment.hasItemConformingToTypeIdentifier(UTType.fileURL.identifier)
|| attachment.hasItemConformingToTypeIdentifier("com.apple.pkpass") {
|| attachment.hasItemConformingToTypeIdentifier("com.apple.pkpass")
{
return extensionItem
}
}
@ -464,7 +470,7 @@ public class ShareViewController: OWSNavigationController, ShareViewDelegate, SA
return result
}
public override func viewDidDisappear(_ animated: Bool) {
override public func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
// If we're disappearing because we presented something else (e.g., image

View File

@ -15,7 +15,7 @@ public class SharingThreadPickerProgressSheet: ActionSheetController {
public init(
attachmentIds: [Attachment.IDType],
delegate: ShareViewDelegate?
delegate: ShareViewDelegate?,
) {
self.attachmentIds = attachmentIds
super.init()
@ -24,7 +24,7 @@ public class SharingThreadPickerProgressSheet: ActionSheetController {
let cancelAction = ActionSheetAction(
title: CommonStrings.cancelButton,
style: .cancel
style: .cancel,
) { [weak delegate] _ in
delegate?.shareViewWasCancelled()
}
@ -34,7 +34,7 @@ public class SharingThreadPickerProgressSheet: ActionSheetController {
self,
selector: #selector(handleAttachmentProgressNotification(_:)),
name: Upload.Constants.attachmentUploadProgressNotification,
object: nil
object: nil,
)
}
@ -90,7 +90,7 @@ public class SharingThreadPickerProgressSheet: ActionSheetController {
guard attachmentIds.isEmpty.negated else {
progressLabel.text = OWSLocalizedString(
"MESSAGE_STATUS_SENDING",
comment: "message status while message is sending."
comment: "message status while message is sending.",
)
return
}
@ -109,13 +109,13 @@ public class SharingThreadPickerProgressSheet: ActionSheetController {
progressLabel.text = String(
format: Self.progressFormat,
OWSFormat.formatInt(min(totalCompleted + 1, attachmentIds.count)),
OWSFormat.formatInt(attachmentIds.count)
OWSFormat.formatInt(attachmentIds.count),
)
}
private static let progressFormat = OWSLocalizedString(
"SHARE_EXTENSION_SENDING_IN_PROGRESS_FORMAT",
comment: "Send progress for share extension. Embeds {{ %1$@ number of attachments uploaded, %2$@ total number of attachments}}"
comment: "Send progress for share extension. Embeds {{ %1$@ number of attachments uploaded, %2$@ total number of attachments}}",
)
// MARK: Notifications

View File

@ -24,7 +24,7 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
/// the attachments end up being incompatible, because it would be weird to
/// have the stories destinations disappear. Instead, we show an error when
/// actually sending if stories are selected.
public let areAttachmentStoriesCompatPrecheck: Bool
let areAttachmentStoriesCompatPrecheck: Bool
var typedItems: [TypedItem] {
didSet {
@ -38,7 +38,7 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
private var selectedConversations: [ConversationItem] { selection.conversations }
public init(areAttachmentStoriesCompatPrecheck: Bool, shareViewDelegate: ShareViewDelegate) {
init(areAttachmentStoriesCompatPrecheck: Bool, shareViewDelegate: ShareViewDelegate) {
self.typedItems = []
self.areAttachmentStoriesCompatPrecheck = areAttachmentStoriesCompatPrecheck
self.shareViewDelegate = shareViewDelegate
@ -52,7 +52,7 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
self.updateApprovalMode()
}
public func presentActionSheetOnNavigationController(_ alert: ActionSheetController) {
func presentActionSheetOnNavigationController(_ alert: ActionSheetController) {
if let navigationController = shareViewDelegate?.shareViewNavigationController {
navigationController.presentActionSheet(alert)
} else {
@ -65,8 +65,8 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
guard
selectedConversations.count == 1,
case .group(let groupThreadId) = selectedConversations.first?.messageRecipient else
{
case .group(let groupThreadId) = selectedConversations.first?.messageRecipient
else {
mentionCandidates = []
return
}
@ -142,7 +142,7 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
profileManager: SSKEnvironment.shared.profileManagerRef,
recipientManager: DependenciesBridge.shared.recipientManager,
tsAccountManager: DependenciesBridge.shared.tsAccountManager,
tx: tx
tx: tx,
)
}
let approvalView = ContactShareViewController(contactShareDraft: contactShareDraft)
@ -161,7 +161,7 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
return AttachmentApprovalItem(attachment: attachment, canSave: false)
}
}
var approvalVCOptions: AttachmentApprovalViewControllerOptions = withCancelButton ? [ .hasCancel ] : []
var approvalVCOptions: AttachmentApprovalViewControllerOptions = withCancelButton ? [.hasCancel] : []
if self.selection.conversations.contains(where: \.isStory) {
approvalVCOptions.insert(.disallowViewOnce)
}
@ -234,7 +234,7 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
messageBody: destination.messageBody,
quotedReplyDraft: nil,
linkPreviewDataSource: linkPreviewDataSource,
transaction: tx
transaction: tx,
)
return try unpreparedMessage.prepare(tx: tx)
},
@ -244,9 +244,9 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
try await StorySharing.enqueueTextStory(
with: messageBody,
linkPreviewDraft: linkPreview,
to: conversations
to: conversations,
)
}
},
)
case .contact(let contactShare):
let contactShareForSending: ContactShareDraft.ForSending
@ -265,14 +265,14 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
thread: destination.thread,
expiresInSeconds: dmConfigurationStore.durationSeconds(
for: destination.thread,
tx: tx
)
tx: tx,
),
)
let message = builder.build(transaction: tx)
let unpreparedMessage = UnpreparedOutgoingMessage.forMessage(
message,
body: nil,
contactShareDraft: contactShareForSending
contactShareDraft: contactShareForSending,
)
return try unpreparedMessage.prepare(tx: tx)
},
@ -326,7 +326,7 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
} else {
let actionSheet = SharingThreadPickerProgressSheet(
attachmentIds: attachmentIds,
delegate: self.shareViewDelegate
delegate: self.shareViewDelegate,
)
presentActionSheetOnNavigationController(actionSheet)
self.sendProgressSheet = actionSheet
@ -370,14 +370,14 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
ThreadUtil.addThreadToProfileWhitelistIfEmptyOrPendingRequest(
destination.thread,
setDefaultTimerIfNecessary: true,
tx: tx
tx: tx,
)
}
let sendPromises = preparedMessages.map {
ThreadUtil.enqueueMessagePromise(
message: $0,
transaction: tx
transaction: tx,
)
}
return (preparedMessages, sendPromises)
@ -427,9 +427,9 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
let cancelAction = ActionSheetAction(
title: CommonStrings.cancelButton,
style: .cancel
style: .cancel,
) { [weak self] _ in
guard let self = self else { return }
guard let self else { return }
SSKEnvironment.shared.databaseStorageRef.write { transaction in
for message in failure.outgoingMessages {
// If we sent the message to anyone, mark it as failed
@ -445,7 +445,7 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
let untrustedServiceId = untrustedIdentityError.serviceId
let failureFormat = OWSLocalizedString(
"SHARE_EXTENSION_FAILED_SENDING_BECAUSE_UNTRUSTED_IDENTITY_FORMAT",
comment: "alert body when sharing file failed because of untrusted/changed identity keys"
comment: "alert body when sharing file failed because of untrusted/changed identity keys",
)
let displayName = SSKEnvironment.shared.databaseStorageRef.read { tx in
return SSKEnvironment.shared.contactManagerRef.displayName(for: SignalServiceAddress(untrustedServiceId), tx: tx).resolvedValue()
@ -463,16 +463,16 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
let confirmAction = ActionSheetAction(
title: SafetyNumberStrings.confirmSendButton,
style: .default
style: .default,
) { [weak self] _ in
guard let self = self else { return }
guard let self else { return }
// Confirm Identity
SSKEnvironment.shared.databaseStorageRef.write { transaction in
let identityManager = DependenciesBridge.shared.identityManager
let verificationState = identityManager.verificationState(
for: SignalServiceAddress(untrustedServiceId),
tx: transaction
tx: transaction,
)
switch verificationState {
case .verified:
@ -488,7 +488,7 @@ class SharingThreadPickerViewController: ConversationPickerViewController {
of: identityKey,
for: SignalServiceAddress(untrustedServiceId),
isUserInitiatedChange: true,
tx: transaction
tx: transaction,
)
}
}