From 3f137be7802921ae97d9c9e3788697db57da54f2 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sat, 16 Apr 2022 19:51:31 +0200 Subject: [PATCH] Restore last played item into queue only if it's not in there yet --- Model/Player/PlayerQueue.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Model/Player/PlayerQueue.swift b/Model/Player/PlayerQueue.swift index 6c4978ad..f3e89b14 100644 --- a/Model/Player/PlayerQueue.swift +++ b/Model/Player/PlayerQueue.swift @@ -198,8 +198,17 @@ extension PlayerModel { return } - queue = ([Defaults[.lastPlayed]] + Defaults[.queue]).compactMap { $0 } - Defaults[.lastPlayed] = nil + var restoredQueue = [PlayerQueueItem?]() + + if let lastPlayed = Defaults[.lastPlayed], + !Defaults[.queue].contains(where: { $0.videoID == lastPlayed.videoID }) + { + restoredQueue.append(lastPlayed) + Defaults[.lastPlayed] = nil + } + + restoredQueue.append(contentsOf: Defaults[.queue]) + queue = restoredQueue.compactMap { $0 } queue.forEach { item in accounts.api.loadDetails(item) { newItem in