mirror of
https://github.com/lil-org/tokenary.git
synced 2024-12-12 12:33:42 +03:00
Remove old unused sessions
This commit is contained in:
parent
c7c60a5d1e
commit
758a38faeb
@ -17,11 +17,25 @@ class SessionStorage {
|
||||
private init() {}
|
||||
|
||||
func loadAll() -> [Item] {
|
||||
let items = Array(Defaults.storedSessions.values)
|
||||
var items = Array(Defaults.storedSessions.values)
|
||||
let wcItems = WCSessionStore.allSessions
|
||||
for item in items where wcItems[item.session.topic] == nil {
|
||||
WCSessionStore.store(item.session, peerId: item.sessionDetails.peerId, peerMeta: item.sessionDetails.peerMeta)
|
||||
let latestInteractionDates = Defaults.latestInteractionDates
|
||||
let now = Date()
|
||||
let oldnessThreshold: Double = 60 * 60 * 24 * 60 // 60 days
|
||||
|
||||
items = items.filter { item -> Bool in
|
||||
guard let date = latestInteractionDates[item.clientId], now.timeIntervalSince(date) < oldnessThreshold else {
|
||||
remove(clientId: item.clientId)
|
||||
return false
|
||||
}
|
||||
|
||||
if wcItems[item.session.topic] == nil {
|
||||
WCSessionStore.store(item.session, peerId: item.sessionDetails.peerId, peerMeta: item.sessionDetails.peerMeta)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
@ -30,6 +44,7 @@ class SessionStorage {
|
||||
}
|
||||
|
||||
func remove(clientId: String) {
|
||||
Defaults.latestInteractionDates.removeValue(forKey: clientId)
|
||||
if let item = Defaults.storedSessions.removeValue(forKey: clientId) {
|
||||
WCSessionStore.clear(item.session.topic)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user