-
Notifications
You must be signed in to change notification settings - Fork 3
feat(catalog): fill missing PI episodes from the publisher feed and notify from RSS #971
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5bb83df
feat(info): supplement stale PI episode lists from the show feed
ashwkun 8414b3f
feat(catalog): merge publisher-feed extras and notify from RSS when P…
ashwkun e517aa1
Merge remote-tracking branch 'origin/master' into feat/pi-episode-sup…
ashwkun 7597784
fix(catalog): address PR review, Sonar, and architecture-guard gaps
ashwkun 632e09e
fix(catalog): keep FCM Robolectric tests off the real Application
ashwkun 9bfd0f9
fix(catalog): cover CodeRabbit follow-ups on feed matching and tests
ashwkun 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
app/src/main/java/cx/aswin/boxlore/fcm/NewEpisodeFcmLogic.kt
This file contains hidden or 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,36 @@ | ||
| package cx.aswin.boxlore.fcm | ||
|
|
||
| import android.net.Uri | ||
|
|
||
| /** Deep-link and id helpers for `type=new_episode` FCM payloads. */ | ||
| internal object NewEpisodeFcmLogic { | ||
| fun usableEpisodeId(raw: String?): String? { | ||
| val id = raw?.trim().orEmpty() | ||
| if (id.isEmpty() || id == "0") return null | ||
| return id | ||
| } | ||
|
|
||
| fun route( | ||
| podcastId: String, | ||
| episodeId: String?, | ||
| podcastTitle: String, | ||
| ): String { | ||
| val ep = usableEpisodeId(episodeId) | ||
| return if (ep != null) { | ||
| "boxlore://episode/$ep?autoplay=false&podcastId=${Uri.encode(podcastId)}" + | ||
| "&podcastTitle=${Uri.encode(podcastTitle)}" | ||
| } else { | ||
| "boxlore://podcast/$podcastId" | ||
| } | ||
| } | ||
|
|
||
| fun durationMinutes( | ||
| localDurationSeconds: Int?, | ||
| payloadDurationMinutes: String?, | ||
| ): Int { | ||
| if (localDurationSeconds != null && localDurationSeconds > 0) { | ||
| return localDurationSeconds / 60 | ||
| } | ||
| return payloadDurationMinutes?.toIntOrNull()?.coerceAtLeast(0) ?: 0 | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
app/src/main/java/cx/aswin/boxlore/fcm/NewEpisodePushHydration.kt
This file contains hidden or 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,68 @@ | ||
| package cx.aswin.boxlore.fcm | ||
|
|
||
| import cx.aswin.boxlore.core.catalog.SubscriptionRepository | ||
| import cx.aswin.boxlore.core.domain.ports.EpisodeSupplementPort | ||
| import cx.aswin.boxlore.core.model.Episode | ||
| import kotlin.coroutines.cancellation.CancellationException | ||
|
|
||
| /** | ||
| * On a new-episode push, refresh the publisher feed for opted-in PI shows so the | ||
| * notification and auto-download use a local episode id (PI or negative supplement). | ||
| * Does not opt the show in from FCM. | ||
| */ | ||
| internal object NewEpisodePushHydration { | ||
| suspend fun resolveLocalEpisode( | ||
| podcastId: String, | ||
| payloadFeedUrl: String?, | ||
| payloadEnclosureUrl: String?, | ||
| subscriptionRepository: SubscriptionRepository, | ||
| episodeSupplementPort: EpisodeSupplementPort?, | ||
| payloadGuid: String? = null, | ||
| ): Episode? { | ||
| val port = episodeSupplementPort ?: return null | ||
| if (!port.hasDirectFeedOptIn(podcastId)) return null | ||
| val entity = subscriptionRepository.getPodcastEntity(podcastId) | ||
| val feedUrl = | ||
| payloadFeedUrl?.trim().orEmpty().ifEmpty { entity?.feedUrl.orEmpty() } | ||
| val guid = payloadGuid?.trim().orEmpty() | ||
| val enclosure = payloadEnclosureUrl?.trim().orEmpty() | ||
| val tip = | ||
| try { | ||
| port.resolveNewestTipFromFeed( | ||
| EpisodeSupplementPort.NewestTipRequest( | ||
| podcastIndexId = podcastId, | ||
| feedUrl = feedUrl, | ||
| knownEpisodes = listOfNotNull(entity?.latestEpisode), | ||
| podcastTitle = entity?.title, | ||
| podcastImageUrl = entity?.imageUrl, | ||
| podcastGenre = entity?.genre, | ||
| podcastArtist = entity?.author, | ||
| match = EpisodeSupplementPort.FeedItemMatch( | ||
| guid = guid.takeIf { it.isNotEmpty() }, | ||
| enclosureUrl = enclosure.takeIf { it.isNotEmpty() }, | ||
| ).takeIf { it.guid != null || it.enclosureUrl != null }, | ||
| ), | ||
| ) | ||
| } catch (e: CancellationException) { | ||
| throw e | ||
| } catch (_: Exception) { | ||
| null | ||
| } | ||
| if (tip != null) { | ||
| subscriptionRepository.updateLatestEpisode(podcastId, tip, markAsNew = true) | ||
| return tip | ||
| } | ||
| if (enclosure.isEmpty()) return null | ||
| val cached = | ||
| port | ||
| .getEpisodesForPodcast( | ||
| podcastIndexId = podcastId, | ||
| podcastTitle = entity?.title, | ||
| podcastImageUrl = entity?.imageUrl, | ||
| podcastGenre = entity?.genre, | ||
| podcastArtist = entity?.author, | ||
| ).find { it.audioUrl.trim() == enclosure } ?: return null | ||
| subscriptionRepository.updateLatestEpisode(podcastId, cached, markAsNew = true) | ||
| return cached | ||
| } | ||
| } | ||
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.