-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Playback 2024: Ratings #2376
Merged
+383
−9
Merged
Playback 2024: Ratings #2376
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eaed9b1
Add Ratings to EoY 2024
bjtitus 3982ab5
Add Analytics event to Learn Ratings
bjtitus 8685f2b
Add pause to Ratings Learn More
bjtitus aebebbf
Adjust spacing
bjtitus cac023b
Merge branch 'trunk' into bjtitus/playback-2024/ratings
bjtitus 0cbc28a
Fix dashed rectangle alignment
bjtitus 114af09
Clean up old code and warnings
bjtitus 0a5acf6
Change method name for model data loading
bjtitus ec8bb67
Handle empty ratings response
bjtitus c39428e
Switch shouldLoadData on 2023 story
bjtitus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
13 changes: 13 additions & 0 deletions
13
Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/UserPodcastRating.swift
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,13 @@ | ||
import Foundation | ||
|
||
public struct UserPodcastRating: Codable { | ||
public let podcastRating: UInt32 | ||
public let podcastUuid: String | ||
public let modifiedAt: Date | ||
|
||
public init(podcastRating: UInt32, podcastUuid: String, modifiedAt: Date) { | ||
self.podcastRating = podcastRating | ||
self.podcastUuid = podcastUuid | ||
self.modifiedAt = modifiedAt | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
Modules/DataModel/Sources/PocketCastsDataModel/Public/RatingsDataManager.swift
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,4 @@ | ||
/// This is currently in memory only since we don't store these locally in the database | ||
public class RatingsDataManager { | ||
public var ratings: [UserPodcastRating]? | ||
} |
51 changes: 51 additions & 0 deletions
51
Modules/Server/Sources/PocketCastsServer/Private/API Tasks/RetrieveRatingsTask.swift
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,51 @@ | ||
import Foundation | ||
import PocketCastsDataModel | ||
import PocketCastsUtils | ||
import SwiftProtobuf | ||
|
||
class RetrieveRatingsTask: ApiBaseTask, @unchecked Sendable { | ||
var completion: (([UserPodcastRating]?) -> Void)? | ||
|
||
var success: Bool = false | ||
|
||
private var convertedRatings = [UserPodcastRating]() | ||
|
||
private lazy var addRatingGroup: DispatchGroup = { | ||
let dispatchGroup = DispatchGroup() | ||
|
||
return dispatchGroup | ||
}() | ||
|
||
override func apiTokenAcquired(token: String) { | ||
let url = ServerConstants.Urls.api() + "user/podcast_rating/list" | ||
|
||
do { | ||
let (response, httpStatus) = getToServer(url: url, token: token) | ||
|
||
guard let responseData = response, httpStatus?.statusCode == ServerConstants.HttpConstants.ok else { | ||
completion?(nil) | ||
return | ||
} | ||
|
||
let serverRatings = try Api_PodcastRatingsResponse(serializedBytes: responseData).podcastRatings | ||
if serverRatings.count == 0 { | ||
completion?(convertedRatings) | ||
|
||
return | ||
} | ||
|
||
convertedRatings = serverRatings.map { rating in | ||
UserPodcastRating(podcastRating: rating.podcastRating, podcastUuid: rating.podcastUuid, modifiedAt: rating.modifiedAt.date) | ||
} | ||
|
||
DataManager.sharedManager.ratings.ratings = convertedRatings | ||
|
||
success = true | ||
|
||
completion?(convertedRatings) | ||
} catch { | ||
FileLog.shared.addMessage("Decoding ratings failed \(error.localizedDescription)") | ||
completion?(nil) | ||
} | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
Modules/Server/Sources/PocketCastsServer/Public/API/ApiServerHandler+UserPodcastRating.swift
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit confusing. If I call
hasLoadedData
I'm not expectingratings
to be nil. Can we find a better name? If it's only related to ratings I would specify that in the function name.