mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
ed9f4ea6c6
Fixed a few job migration issues Fixed an issue with the closed group key pair management (wasn't storing keys correctly) Refactored the OWSSound (now Preferences.Sound) Added the logic for the AttachmentDownloadJob and enabled jobs to be cascade deleted via interactions Optimised the HomeViewModel database observation query (fetch specific columns so changes outside those don't trigger updates) Updated to the latest GRDB (ran into a deadlock which should be fixed in a newer version)
59 lines
1.7 KiB
Swift
59 lines
1.7 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import Foundation
|
|
import GRDB
|
|
import SessionUtilitiesKit
|
|
|
|
public struct ClosedGroupKeyPair: Codable, Equatable, FetchableRecord, PersistableRecord, TableRecord, ColumnExpressible {
|
|
public static var databaseTableName: String { "closedGroupKeyPair" }
|
|
internal static let closedGroupForeignKey = ForeignKey(
|
|
[Columns.threadId],
|
|
to: [ClosedGroup.Columns.threadId]
|
|
)
|
|
private static let closedGroup = belongsTo(ClosedGroup.self, using: closedGroupForeignKey)
|
|
|
|
public typealias Columns = CodingKeys
|
|
public enum CodingKeys: String, CodingKey, ColumnExpression {
|
|
case threadId
|
|
case publicKey
|
|
case secretKey
|
|
case receivedTimestamp
|
|
}
|
|
|
|
public let threadId: String
|
|
public let publicKey: Data
|
|
public let secretKey: Data
|
|
public let receivedTimestamp: TimeInterval
|
|
|
|
// MARK: - Relationships
|
|
|
|
public var closedGroup: QueryInterfaceRequest<ClosedGroup> {
|
|
request(for: ClosedGroupKeyPair.closedGroup)
|
|
}
|
|
|
|
// MARK: - Initialization
|
|
|
|
public init(
|
|
threadId: String,
|
|
publicKey: Data,
|
|
secretKey: Data,
|
|
receivedTimestamp: TimeInterval
|
|
) {
|
|
self.threadId = threadId
|
|
self.publicKey = publicKey
|
|
self.secretKey = secretKey
|
|
self.receivedTimestamp = receivedTimestamp
|
|
}
|
|
}
|
|
|
|
// MARK: - GRDB Interactions
|
|
|
|
public extension ClosedGroupKeyPair {
|
|
static func fetchLatestKeyPair(_ db: Database, threadId: String) throws -> ClosedGroupKeyPair? {
|
|
return try ClosedGroupKeyPair
|
|
.filter(Columns.threadId == threadId)
|
|
.order(Columns.receivedTimestamp.desc)
|
|
.fetchOne(db)
|
|
}
|
|
}
|