mirror of
https://github.com/cranci1/Sora.git
synced 2026-05-12 04:50:41 +00:00
bug fixes (#127)
This commit is contained in:
parent
dc6236f324
commit
600d338bce
1 changed files with 27 additions and 9 deletions
|
|
@ -26,22 +26,40 @@ class ContinueWatchingManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
var items = fetchItems()
|
var items = fetchItems()
|
||||||
if let index = items.firstIndex(where: { $0.streamUrl == item.streamUrl && $0.episodeNumber == item.episodeNumber }) {
|
|
||||||
items[index] = item
|
items.removeAll { existing in
|
||||||
} else {
|
existing.fullUrl == item.fullUrl &&
|
||||||
items.append(item)
|
existing.episodeNumber == item.episodeNumber &&
|
||||||
|
existing.module.metadata.sourceName == item.module.metadata.sourceName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
items.append(item)
|
||||||
|
|
||||||
if let data = try? JSONEncoder().encode(items) {
|
if let data = try? JSONEncoder().encode(items) {
|
||||||
UserDefaults.standard.set(data, forKey: storageKey)
|
UserDefaults.standard.set(data, forKey: storageKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchItems() -> [ContinueWatchingItem] {
|
func fetchItems() -> [ContinueWatchingItem] {
|
||||||
if let data = UserDefaults.standard.data(forKey: storageKey),
|
guard
|
||||||
let items = try? JSONDecoder().decode([ContinueWatchingItem].self, from: data) {
|
let data = UserDefaults.standard.data(forKey: storageKey),
|
||||||
return items
|
let raw = try? JSONDecoder().decode([ContinueWatchingItem].self, from: data)
|
||||||
|
else {
|
||||||
|
return []
|
||||||
}
|
}
|
||||||
return []
|
|
||||||
|
var seen = Set<String>()
|
||||||
|
let unique = raw.reversed().filter { item in
|
||||||
|
let key = "\(item.fullUrl)|\(item.module.metadata.sourceName)|\(item.episodeNumber)"
|
||||||
|
if seen.contains(key) {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
seen.insert(key)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}.reversed()
|
||||||
|
|
||||||
|
return Array(unique)
|
||||||
}
|
}
|
||||||
|
|
||||||
func remove(item: ContinueWatchingItem) {
|
func remove(item: ContinueWatchingItem) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue