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.
39 lines
2.0 KiB
Swift
39 lines
2.0 KiB
Swift
5 years ago
|
|
||
|
public extension Storage {
|
||
|
|
||
|
// MARK: Open Group Public Keys
|
||
|
internal static let openGroupPublicKeyCollection = "LokiOpenGroupPublicKeyCollection"
|
||
|
internal static let lastMessageServerIDCollection = "LokiGroupChatLastMessageServerIDCollection"
|
||
|
internal static let lastDeletionServerIDCollection = "LokiGroupChatLastDeletionServerIDCollection"
|
||
|
|
||
|
internal static func getOpenGroupPublicKey(for server: String) -> String? {
|
||
|
var result: String? = nil
|
||
|
read { transaction in
|
||
|
result = transaction.object(forKey: server, inCollection: openGroupPublicKeyCollection) as? String
|
||
|
}
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
internal static func setOpenGroupPublicKey(for server: String, to publicKey: String, using transaction: YapDatabaseReadWriteTransaction) {
|
||
|
transaction.setObject(publicKey, forKey: server, inCollection: openGroupPublicKeyCollection)
|
||
|
}
|
||
|
|
||
|
internal static func removeOpenGroupPublicKey(for server: String, using transaction: YapDatabaseReadWriteTransaction) {
|
||
|
transaction.removeObject(forKey: server, inCollection: openGroupPublicKeyCollection)
|
||
|
}
|
||
|
|
||
|
private static func removeLastMessageServerID(for group: UInt64, on server: String, using transaction: YapDatabaseReadWriteTransaction) {
|
||
|
transaction.removeObject(forKey: "\(server).\(group)", inCollection: lastMessageServerIDCollection)
|
||
|
}
|
||
|
|
||
|
private static func removeLastDeletionServerID(for group: UInt64, on server: String, using transaction: YapDatabaseReadWriteTransaction) {
|
||
|
transaction.removeObject(forKey: "\(server).\(group)", inCollection: lastDeletionServerIDCollection)
|
||
|
}
|
||
|
|
||
|
internal static func clearAllData(for group: UInt64, on server: String, using transaction: YapDatabaseReadWriteTransaction) {
|
||
|
removeLastMessageServerID(for: group, on: server, using: transaction)
|
||
|
removeLastDeletionServerID(for: group, on: server, using: transaction)
|
||
|
Storage.removeOpenGroupPublicKey(for: server, using: transaction)
|
||
|
}
|
||
|
}
|