mirror of https://github.com/oxen-io/session-ios
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.
55 lines
2.2 KiB
Swift
55 lines
2.2 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import Foundation
|
|
import GRDB
|
|
import SessionUtilitiesKit
|
|
|
|
enum _011_DisappearingMessagesConfiguration: Migration {
|
|
static let target: TargetMigrations.Identifier = .messagingKit
|
|
static let identifier: String = "DisappearingMessagesWithTypes"
|
|
static let needsConfigSync: Bool = false
|
|
static let minExpectedRunDuration: TimeInterval = 0.1
|
|
|
|
static func migrate(_ db: GRDB.Database) throws {
|
|
try db.alter(table: DisappearingMessagesConfiguration.self) { t in
|
|
t.add(.type, .integer)
|
|
t.add(.lastChangeTimestampMs, .integer)
|
|
.defaults(to: 0)
|
|
}
|
|
|
|
try db.alter(table: Contact.self) { t in
|
|
t.add(.lastKnownClientVersion, .integer)
|
|
}
|
|
|
|
func updateDisappearingMessageType(_ db: GRDB.Database, id: String, type: DisappearingMessagesConfiguration.DisappearingMessageType) throws {
|
|
_ = try DisappearingMessagesConfiguration
|
|
.filter(DisappearingMessagesConfiguration.Columns.threadId == id)
|
|
.updateAll(
|
|
db,
|
|
DisappearingMessagesConfiguration.Columns.type.set(to: type)
|
|
)
|
|
}
|
|
|
|
try DisappearingMessagesConfiguration
|
|
.filter(DisappearingMessagesConfiguration.Columns.isEnabled == true)
|
|
.fetchAll(db)
|
|
.forEach { config in
|
|
if let thread = try? SessionThread.fetchOne(db, id: config.threadId) {
|
|
guard !thread.isNoteToSelf(db) else {
|
|
try updateDisappearingMessageType(db, id: config.threadId, type: .disappearAfterSend)
|
|
return
|
|
}
|
|
|
|
switch thread.variant {
|
|
case .contact: try updateDisappearingMessageType(db, id: config.threadId, type: .disappearAfterRead)
|
|
case .closedGroup: try updateDisappearingMessageType(db, id: config.threadId, type: .disappearAfterSend)
|
|
case .openGroup: return
|
|
}
|
|
}
|
|
}
|
|
|
|
Storage.update(progress: 1, for: self, in: target) // In case this is the last migration
|
|
}
|
|
}
|
|
|