You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-ios/Session/Meta/SessionApp.swift

97 lines
3.1 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import SessionUtilitiesKit
import SessionMessagingKit
import SignalCoreKit
public struct SessionApp {
static let homeViewController: Atomic<HomeVC?> = Atomic(nil)
// MARK: - View Convenience Methods
public static func presentConversation(for threadId: String, action: ConversationViewModel.Action = .none, animated: Bool) {
let maybeThreadInfo: (thread: SessionThread, isMessageRequest: Bool)? = Storage.shared.write { db in
let thread: SessionThread = try SessionThread
.fetchOrCreate(db, id: threadId, variant: .contact, shouldBeVisible: nil)
return (thread, thread.isMessageRequest(db))
}
guard
let variant: SessionThread.Variant = maybeThreadInfo?.thread.variant,
let isMessageRequest: Bool = maybeThreadInfo?.isMessageRequest
else { return }
self.presentConversation(
for: threadId,
threadVariant: variant,
isMessageRequest: isMessageRequest,
action: action,
focusInteractionInfo: nil,
animated: animated
)
}
public static func presentConversation(
for threadId: String,
threadVariant: SessionThread.Variant,
isMessageRequest: Bool,
action: ConversationViewModel.Action,
focusInteractionInfo: Interaction.TimestampInfo?,
animated: Bool
) {
guard Thread.isMainThread else {
DispatchQueue.main.async {
self.presentConversation(
for: threadId,
threadVariant: threadVariant,
isMessageRequest: isMessageRequest,
action: action,
focusInteractionInfo: focusInteractionInfo,
animated: animated
)
}
return
}
homeViewController.wrappedValue?.show(
threadId,
variant: threadVariant,
isMessageRequest: isMessageRequest,
with: action,
focusedInteractionInfo: focusInteractionInfo,
animated: animated
)
}
// MARK: - Functions
public static func resetAppData(onReset: (() -> ())? = nil) {
// This _should_ be wiped out below.
Logger.error("")
DDLog.flushLog()
Storage.resetAllStorage()
ProfileManager.resetProfileStorage()
Attachment.resetAttachmentStorage()
AppEnvironment.shared.notificationPresenter.clearAllNotifications()
onReset?()
exit(0)
}
public static func showHomeView() {
guard Thread.isMainThread else {
DispatchQueue.main.async {
self.showHomeView()
}
return
}
let homeViewController: HomeVC = HomeVC()
let navController: UINavigationController = StyledNavigationController(rootViewController: homeViewController)
(UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController = navController
}
}