Restore last played item into queue only if it's not in there yet

This commit is contained in:
Arkadiusz Fal 2022-04-16 19:51:31 +02:00
parent d202ff8b40
commit 3f137be780

View File

@ -198,8 +198,17 @@ extension PlayerModel {
return return
} }
queue = ([Defaults[.lastPlayed]] + Defaults[.queue]).compactMap { $0 } var restoredQueue = [PlayerQueueItem?]()
if let lastPlayed = Defaults[.lastPlayed],
!Defaults[.queue].contains(where: { $0.videoID == lastPlayed.videoID })
{
restoredQueue.append(lastPlayed)
Defaults[.lastPlayed] = nil Defaults[.lastPlayed] = nil
}
restoredQueue.append(contentsOf: Defaults[.queue])
queue = restoredQueue.compactMap { $0 }
queue.forEach { item in queue.forEach { item in
accounts.api.loadDetails(item) { newItem in accounts.api.loadDetails(item) { newItem in