mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Remove NSEMemoryStore
This commit is contained in:
parent
c5c173e0a0
commit
b36b66190a
2 changed files with 0 additions and 135 deletions
|
@ -884,7 +884,6 @@
|
|||
EC85D752247C0F52002C44C9 /* UNUserNotificationCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC85D750247C0E8F002C44C9 /* UNUserNotificationCenter.swift */; };
|
||||
EC85D754247C0F5B002C44C9 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC85D753247C0F5B002C44C9 /* Constants.swift */; };
|
||||
EC85D755247C0F84002C44C9 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC85D753247C0F5B002C44C9 /* Constants.swift */; };
|
||||
EC85D757247E700F002C44C9 /* NSEMemoryStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC85D756247E700F002C44C9 /* NSEMemoryStore.swift */; };
|
||||
EC9A3EC524E1616900A8CFAE /* PushNotificationStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC9A3EC424E1616900A8CFAE /* PushNotificationStore.swift */; };
|
||||
EC9A3EC624E1632C00A8CFAE /* PushNotificationStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC9A3EC424E1616900A8CFAE /* PushNotificationStore.swift */; };
|
||||
EC9A3EC724E1634100A8CFAE /* KeyValueStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC1CA87124C823E700DE9EBF /* KeyValueStore.swift */; };
|
||||
|
@ -2113,7 +2112,6 @@
|
|||
EC85D74E2477E614002C44C9 /* RiotNSE.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = RiotNSE.entitlements; sourceTree = "<group>"; };
|
||||
EC85D750247C0E8F002C44C9 /* UNUserNotificationCenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UNUserNotificationCenter.swift; sourceTree = "<group>"; };
|
||||
EC85D753247C0F5B002C44C9 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
|
||||
EC85D756247E700F002C44C9 /* NSEMemoryStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSEMemoryStore.swift; sourceTree = "<group>"; };
|
||||
EC9A3EC424E1616900A8CFAE /* PushNotificationStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushNotificationStore.swift; sourceTree = "<group>"; };
|
||||
ECAE7AE424EC0E01002FA813 /* TableViewSections.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewSections.swift; sourceTree = "<group>"; };
|
||||
ECAE7AE624EC15F7002FA813 /* Section.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Section.swift; sourceTree = "<group>"; };
|
||||
|
@ -5144,7 +5142,6 @@
|
|||
children = (
|
||||
EC85D74E2477E614002C44C9 /* RiotNSE.entitlements */,
|
||||
EC85D7452477E5F7002C44C9 /* NotificationService.swift */,
|
||||
EC85D756247E700F002C44C9 /* NSEMemoryStore.swift */,
|
||||
EC85D7472477E5F7002C44C9 /* Info.plist */,
|
||||
EC1CA8D924D811B400DE9EBF /* NSE-Common.xcconfig */,
|
||||
EC1CA8BC24D1B4CF00DE9EBF /* NSE-Debug.xcconfig */,
|
||||
|
@ -6159,7 +6156,6 @@
|
|||
files = (
|
||||
EC85D74F2477E8EB002C44C9 /* RiotSettings.swift in Sources */,
|
||||
32FD756824D2AD5100BA7B37 /* BuildSettings.swift in Sources */,
|
||||
EC85D757247E700F002C44C9 /* NSEMemoryStore.swift in Sources */,
|
||||
EC2B4EF224A1EF34005EB739 /* DataProtectionHelper.swift in Sources */,
|
||||
EC85D7462477E5F7002C44C9 /* NotificationService.swift in Sources */,
|
||||
32FD755424D074C700BA7B37 /* CommonConfiguration.swift in Sources */,
|
||||
|
|
|
@ -1,131 +0,0 @@
|
|||
/*
|
||||
Copyright 2020 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import MatrixSDK
|
||||
|
||||
// error domain
|
||||
let NSEMemoryStoreErrorDomain: String = "NSEMemoryStoreErrorDomain"
|
||||
|
||||
// error codes
|
||||
enum NSEMemoryStoreErrorCode: Int {
|
||||
case userIDMissing = 1001 // User ID is missing in credentials
|
||||
}
|
||||
|
||||
/// Fake memory store implementation. Uses some real values from an MXFileStore instance.
|
||||
class NSEMemoryStore: MXMemoryStore {
|
||||
|
||||
// In-memory value for eventStreamToken. Will be used as eventStreamToken if provided.
|
||||
private var lastStoredEventStreamToken: String?
|
||||
private var credentials: MXCredentials
|
||||
// real store
|
||||
private var fileStore: MXFileStore!
|
||||
private var myUser: MXUser?
|
||||
|
||||
init(withCredentials credentials: MXCredentials) {
|
||||
self.credentials = credentials
|
||||
if fileStore == nil {
|
||||
fileStore = MXFileStore(credentials: credentials)
|
||||
// load real eventStreamToken
|
||||
fileStore.loadMetaData()
|
||||
}
|
||||
}
|
||||
|
||||
override func open(with credentials: MXCredentials, onComplete: (() -> Void)?, failure: ((Error?) -> Void)? = nil) {
|
||||
super.open(with: credentials, onComplete: {
|
||||
guard let userId = credentials.userId else {
|
||||
failure?(NSError(domain: NSEMemoryStoreErrorDomain,
|
||||
code: NSEMemoryStoreErrorCode.userIDMissing.rawValue,
|
||||
userInfo: nil))
|
||||
return
|
||||
}
|
||||
// load session user before calling onComplete
|
||||
self.fileStore.asyncUsers(withUserIds: [userId], success: { (users) in
|
||||
if let user = users.first {
|
||||
self.myUser = user
|
||||
}
|
||||
onComplete?()
|
||||
}, failure: failure)
|
||||
}, failure: failure)
|
||||
}
|
||||
|
||||
// Return real eventStreamToken, to be able to launch a meaningful background sync
|
||||
override var eventStreamToken: String? {
|
||||
get {
|
||||
// if more up-to-date token exists, use it
|
||||
if let token = lastStoredEventStreamToken {
|
||||
return token
|
||||
}
|
||||
return fileStore.eventStreamToken
|
||||
} set {
|
||||
// store new token values in memory, and return these values in future reads
|
||||
lastStoredEventStreamToken = newValue
|
||||
}
|
||||
}
|
||||
|
||||
// Return real userAccountData, to be able to use push rules
|
||||
override var userAccountData: [AnyHashable : Any]? {
|
||||
get {
|
||||
return fileStore.userAccountData
|
||||
} set {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
|
||||
// This store should act like as a permanent one
|
||||
override var isPermanent: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Some mandatory methods to implement to be permanent
|
||||
override func storeState(forRoom roomId: String, stateEvents: [MXEvent]) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
// Fetch real room state
|
||||
override func state(ofRoom roomId: String, success: @escaping ([MXEvent]) -> Void, failure: ((Error) -> Void)? = nil) {
|
||||
fileStore.state(ofRoom: roomId, success: success, failure: failure)
|
||||
}
|
||||
|
||||
// Fetch real soom summary
|
||||
override func summary(ofRoom roomId: String) -> MXRoomSummary? {
|
||||
return fileStore.summary(ofRoom: roomId)
|
||||
}
|
||||
|
||||
// Fetch real room account data
|
||||
override func accountData(ofRoom roomId: String) -> MXRoomAccountData? {
|
||||
return fileStore.accountData(ofRoom: roomId)
|
||||
}
|
||||
|
||||
// Override and return a user to be stored on session.myUser
|
||||
override func user(withUserId userId: String) -> MXUser? {
|
||||
if userId == credentials.userId, let myUser = myUser {
|
||||
// if asking for session user and myUser is set, return that
|
||||
return myUser
|
||||
}
|
||||
return MXUser(userId: userId)
|
||||
}
|
||||
|
||||
override var syncFilterId: String? {
|
||||
get {
|
||||
// Return real sync filter
|
||||
return fileStore.syncFilterId
|
||||
} set {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue