Updated the feature flag so it will continue to use User Config if the migrations have already been run

This commit is contained in:
Morgan Pretty 2023-05-18 16:32:49 +10:00
parent c134acdc90
commit db67e36acb
7 changed files with 44 additions and 13 deletions

View File

@ -33,7 +33,7 @@ public enum SNMessagingKit { // Just to make the external API nice
// Wait until the feature is turned on before doing the migration that generates
// the config dump data
// FIXME: Remove this once `useSharedUtilForUserConfig` is permanent
(Features.useSharedUtilForUserConfig ?
(Features.useSharedUtilForUserConfig() ?
_014_GenerateInitialUserConfigDumps.self :
(nil as Migration.Type?)
)

View File

@ -9,7 +9,7 @@ import SessionUtilitiesKit
extension MessageReceiver {
internal static func handleLegacyConfigurationMessage(_ db: Database, message: ConfigurationMessage) throws {
// FIXME: Remove this once `useSharedUtilForUserConfig` is permanent
guard !SessionUtil.userConfigsEnabled else {
guard !SessionUtil.userConfigsEnabled(db) else {
TopBannerController.show(warning: .outdatedUserConfig)
return
}

View File

@ -189,7 +189,7 @@ public enum MessageReceiver {
// the config then the message will be dropped)
guard
!Message.requiresExistingConversation(message: message, threadVariant: threadVariant) ||
SessionUtil.conversationInConfig(threadId: threadId, threadVariant: threadVariant, visibleOnly: false)
SessionUtil.conversationInConfig(db, threadId: threadId, threadVariant: threadVariant, visibleOnly: false)
else { throw MessageReceiverError.requiredThreadNotInConfig }
switch message {

View File

@ -299,12 +299,13 @@ internal extension SessionUtil {
public extension SessionUtil {
static func conversationInConfig(
_ db: Database? = nil,
threadId: String,
threadVariant: SessionThread.Variant,
visibleOnly: Bool
) -> Bool {
// FIXME: Remove this once `useSharedUtilForUserConfig` is permanent
guard SessionUtil.userConfigsEnabled else { return true }
guard SessionUtil.userConfigsEnabled(db) else { return true }
let configVariant: ConfigDump.Variant = {
switch threadVariant {

View File

@ -6,6 +6,28 @@ import SessionSnodeKit
import SessionUtil
import SessionUtilitiesKit
// MARK: - Features
public extension Features {
static func useSharedUtilForUserConfig(_ db: Database? = nil) -> Bool {
// TODO: Need to set this timestamp to the correct date
guard Date().timeIntervalSince1970 < 1893456000 else { return true }
guard !SessionUtil.hasCheckedMigrationsCompleted.wrappedValue else {
return SessionUtil.userConfigsEnabledIgnoringFeatureFlag
}
if let db: Database = db {
return SessionUtil.refreshingUserConfigsEnabled(db)
}
return Storage.shared
.read { db in SessionUtil.refreshingUserConfigsEnabled(db) }
.defaulting(to: false)
}
}
// MARK: - SessionUtil
public enum SessionUtil {
public struct ConfResult {
let needsPush: Bool
@ -63,6 +85,7 @@ public enum SessionUtil {
public static var libSessionVersion: String { String(cString: LIBSESSION_UTIL_VERSION_STR) }
fileprivate static let hasCheckedMigrationsCompleted: Atomic<Bool> = Atomic(false)
private static let requiredMigrationsCompleted: Atomic<Bool> = Atomic(false)
private static let requiredMigrationIdentifiers: Set<String> = [
TargetMigrations.Identifier.messagingKit.key(with: _013_SessionUtilChanges.self),
@ -70,8 +93,16 @@ public enum SessionUtil {
]
public static var userConfigsEnabled: Bool {
Features.useSharedUtilForUserConfig &&
requiredMigrationsCompleted.wrappedValue
return userConfigsEnabled(nil)
}
public static func userConfigsEnabled(_ db: Database?) -> Bool {
Features.useSharedUtilForUserConfig(db) &&
SessionUtil.userConfigsEnabledIgnoringFeatureFlag
}
public static var userConfigsEnabledIgnoringFeatureFlag: Bool {
SessionUtil.requiredMigrationsCompleted.wrappedValue
}
internal static func userConfigsEnabled(
@ -80,9 +111,9 @@ public enum SessionUtil {
) -> Bool {
// First check if we are enabled regardless of what we want to ignore
guard
Features.useSharedUtilForUserConfig,
!requiredMigrationsCompleted.wrappedValue,
!refreshingUserConfigsEnabled(db),
Features.useSharedUtilForUserConfig(db),
!SessionUtil.requiredMigrationsCompleted.wrappedValue,
!SessionUtil.refreshingUserConfigsEnabled(db),
ignoreRequirementsForRunningMigrations,
let currentlyRunningMigration: (identifier: TargetMigrations.Identifier, migration: Migration.Type) = Storage.shared.currentlyRunningMigration
else { return true }
@ -99,6 +130,7 @@ public enum SessionUtil {
.isSuperset(of: SessionUtil.requiredMigrationIdentifiers)
requiredMigrationsCompleted.mutate { $0 = result }
hasCheckedMigrationsCompleted.mutate { $0 = true }
return result
}
@ -375,7 +407,7 @@ public enum SessionUtil {
publicKey: String
) throws {
// FIXME: Remove this once `useSharedUtilForUserConfig` is permanent
guard SessionUtil.userConfigsEnabled else { return }
guard SessionUtil.userConfigsEnabled(db) else { return }
guard !messages.isEmpty else { return }
guard !publicKey.isEmpty else { throw MessageReceiverError.noThread }

View File

@ -593,7 +593,7 @@ public struct ProfileManager {
)
}
// FIXME: Remove this once `useSharedUtilForUserConfig` is permanent
else if !SessionUtil.userConfigsEnabled {
else if !SessionUtil.userConfigsEnabled(db) {
// If we have a contact record for the profile (ie. it's a synced profile) then
// should should send an updated config message, otherwise we should just update
// the local state (the shared util has this logic build in to it's handling)

View File

@ -5,6 +5,4 @@ import Foundation
public final class Features {
public static let useOnionRequests: Bool = true
public static let useTestnet: Bool = false
public static let useSharedUtilForUserConfig: Bool = true // TODO: Base this off a timestamp
}