TF-2384 Handle NSE to get plain notification in iOS
Signed-off-by: dab246 <tdvu@linagora.com> (cherry picked from commit 364f32a14b9888f73a3a103b8b5e1bc9b31e148e)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import Foundation
|
||||
import KeychainAccess
|
||||
|
||||
enum KeychainControllerService: String {
|
||||
case sessions
|
||||
|
||||
var identifier: String {
|
||||
InfoPlistReader.main.baseBundleIdentifier + "." + rawValue
|
||||
}
|
||||
}
|
||||
|
||||
class KeychainController: KeychainControllerDelegate {
|
||||
private let keychain: Keychain
|
||||
|
||||
init(service: KeychainControllerService,
|
||||
accessGroup: String) {
|
||||
keychain = Keychain(service: service.identifier,
|
||||
accessGroup: accessGroup)
|
||||
}
|
||||
|
||||
func retrieveSharingSessionFromKeychain(accountId: String) -> KeychainSharingSession? {
|
||||
do {
|
||||
guard let sessionData = try keychain.getData(accountId) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return try JSONDecoder().decode(KeychainSharingSession.self, from: sessionData)
|
||||
} catch {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func retrieveSharingSessions() -> [KeychainCredentials] {
|
||||
keychain.allKeys().compactMap { accountId in
|
||||
guard let sharingSession = retrieveSharingSessionFromKeychain(accountId: accountId) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return KeychainCredentials(accountId: accountId, sharingSession: sharingSession)
|
||||
}
|
||||
}
|
||||
|
||||
func updateEmailStateToKeychain(accountId: String, newState: String) {
|
||||
do {
|
||||
if let sharingSession = retrieveSharingSessionFromKeychain(accountId: accountId) {
|
||||
let newSharingSession = sharingSession.updateEmailState(newState: newState)
|
||||
try keychain.set(newSharingSession.toJson() ?? "", key: accountId)
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user