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.
51 lines
2.1 KiB
Swift
51 lines
2.1 KiB
Swift
3 years ago
|
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||
|
|
||
|
import Foundation
|
||
|
import GRDB
|
||
|
import SessionUtilitiesKit
|
||
|
|
||
2 years ago
|
enum _011_DisappearingMessage: Migration {
|
||
3 years ago
|
static let target: TargetMigrations.Identifier = .messagingKit
|
||
|
static let identifier: String = "DisappearingMessageType"
|
||
|
static let needsConfigSync: Bool = false
|
||
|
static let minExpectedRunDuration: TimeInterval = 0.1
|
||
|
|
||
|
static func migrate(_ db: GRDB.Database) throws {
|
||
3 years ago
|
try db.alter(table: DisappearingMessagesConfiguration.self) { t in
|
||
|
t.add(.type, .integer)
|
||
2 years ago
|
t.add(.lastChangeTimestampMs, .integer)
|
||
|
.defaults(to: 0)
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
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)
|
||
3 years ago
|
)
|
||
3 years ago
|
}
|
||
|
|
||
|
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
|
||
|
}
|
||
|
}
|
||
|
}
|
||
3 years ago
|
|
||
|
Storage.update(progress: 1, for: self, in: target) // In case this is the last migration
|
||
|
}
|
||
|
}
|
||
|
|