-
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update LatestInLibraryView to use getLatestMedia (#895)
- Loading branch information
Showing
6 changed files
with
98 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// Swiftfin is subject to the terms of the Mozilla Public | ||
// License, v2.0. If a copy of the MPL was not distributed with this | ||
// file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2023 Jellyfin & Jellyfin Contributors | ||
// | ||
|
||
import Combine | ||
import Foundation | ||
import JellyfinAPI | ||
|
||
final class LatestInLibraryViewModel: PagingLibraryViewModel { | ||
|
||
let parent: LibraryParent | ||
|
||
init(parent: LibraryParent) { | ||
self.parent = parent | ||
|
||
super.init() | ||
|
||
_requestNextPage() | ||
} | ||
|
||
override func _requestNextPage() { | ||
Task { | ||
|
||
await MainActor.run { | ||
self.isLoading = true | ||
} | ||
|
||
let parameters = Paths.GetLatestMediaParameters( | ||
parentID: self.parent.id, | ||
fields: ItemFields.minimumCases, | ||
enableUserData: true, | ||
limit: self.pageItemSize * 3 | ||
) | ||
let request = Paths.getLatestMedia(userID: userSession.user.id, parameters: parameters) | ||
let response = try await userSession.client.send(request) | ||
|
||
let items = response.value | ||
if items.isEmpty { | ||
hasNextPage = false | ||
return | ||
} | ||
|
||
await MainActor.run { | ||
self.isLoading = false | ||
self.items.append(contentsOf: items) | ||
} | ||
} | ||
} | ||
|
||
override public func getRandomItemFromLibrary() async throws -> BaseItemDtoQueryResult { | ||
BaseItemDtoQueryResult(items: items.elements) | ||
} | ||
|
||
func markPlayed(item: BaseItemDto) { | ||
Task { | ||
|
||
let request = Paths.markPlayedItem( | ||
userID: userSession.user.id, | ||
itemID: item.id! | ||
) | ||
let _ = try await userSession.client.send(request) | ||
|
||
await MainActor.run { | ||
refresh() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters