Skip to content
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

Fix missing episodes with unfollowed podcasts #3546

Merged
merged 5 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
7.83
-----

* Bug Fixes
* Fix missing episodes with unfollowed podcasts
([#3546](https://github.com/Automattic/pocket-casts-android/pull/3546))

7.82
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import io.reactivex.Flowable
import io.reactivex.Maybe
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
import java.util.Calendar
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
import kotlin.time.Duration.Companion.days
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -224,25 +224,36 @@ class PodcastManagerImpl @Inject constructor(

// we don't delete podcasts added to the phone in the last week. This is to prevent stuff you just leave open in discover from being removed
val addedDate = podcast.addedDate
val calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_YEAR, -7)
val oneWeekAgo = calendar.time
if (addedDate != null && addedDate > oneWeekAgo) {
val oneWeekAgoMs = System.currentTimeMillis() - 7.days.inWholeMilliseconds
if (addedDate != null && addedDate.time > oneWeekAgoMs) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't change any logic it only simplifies the code.

return false
}

// podcasts can be deleted if all of the episodes are haven't been interacted with
val episodes = episodeManager.findEpisodesByPodcastOrderedBlocking(podcast)
var podcastHasChangedEpisodes = false
var latestPlaybackInteraction = 0L
val deleteEpisodes = mutableListOf<PodcastEpisode>()
for (episode in episodes) {
// find the latest playback interaction
episode.lastPlaybackInteraction?.let { interaction ->
if (interaction > latestPlaybackInteraction) {
latestPlaybackInteraction = interaction
}
}
// don't delete the podcast if any of the episodes have been interacted with
if (episodeManager.userHasInteractedWithEpisode(episode, playbackManager)) {
podcastHasChangedEpisodes = true
continue
}
// bulk delete or it takes 10 seconds on a large podcast
deleteEpisodes.add(episode)
}
// don't delete the episodes or podcast if the latest playback interaction happening in the last month
val oneMonthAgoMs = System.currentTimeMillis() - 30.days.inWholeMilliseconds
if (latestPlaybackInteraction > oneMonthAgoMs) {
return false
}
if (deleteEpisodes.isNotEmpty()) {
episodeManager.deleteEpisodesWithoutSyncBlocking(deleteEpisodes, playbackManager)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class PodcastRefresherImpl @Inject constructor(
override suspend fun refreshPodcast(existingPodcast: Podcast, playbackManager: PlaybackManager) {
try {
val podcastResponse = cacheServiceManager.getPodcastResponse(existingPodcast.uuid)
if (podcastResponse.wasCached() || podcastResponse.notModified()) {
// unsubscribed podcasts have episodes removed, so always refresh them
if (existingPodcast.isSubscribed && (podcastResponse.wasCached() || podcastResponse.notModified())) {
LogBuffer.i(LogBuffer.TAG_BACKGROUND_TASKS, "Refreshing podcast ${existingPodcast.uuid} not required as cached")
return
}
Expand Down