diff --git a/CHANGELOG.md b/CHANGELOG.md index 67d4fb8075baf56b5b403277e2faf9f1befc49ae..6d96352187f8a064b53a95fbba872827e0c9bfca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,12 @@ yet implemented. - Show newest podcasts and episodes in library view [#214](https://git.project-insanity.org/onny/nextcloud-app-podcast/-/issues/214) @onny +### Fixed +- Listening view: Only show episods with playtime + [#213](https://git.project-insanity.org/onny/nextcloud-app-podcast/-/issues/213) @onny +- Library view: Show list of newest episodes (which are present in the database) + [#213](https://git.project-insanity.org/onny/nextcloud-app-podcast/-/issues/213) @onny + ### Changed - Update npm modules [#181](https://git.project-insanity.org/onny/nextcloud-app-podcast/-/issues/181) @onny diff --git a/lib/Controller/EpisodeController.php b/lib/Controller/EpisodeController.php index a2227eecf930662a8109c501c76001676b04e712..b113657c6b506d197f3e03da3aec0f3bf18ca86d 100644 --- a/lib/Controller/EpisodeController.php +++ b/lib/Controller/EpisodeController.php @@ -29,10 +29,15 @@ use OCA\Podcast\Service\FyydApiService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; +use OCP\ILogger; use OCP\Http\Client\IClientService; class EpisodeController extends Controller { + + /** @var ILogger */ + private $logger; + /** @var EpisodesService */ private $service; @@ -47,10 +52,12 @@ class EpisodeController extends Controller { public function __construct(IRequest $request, EpisodeService $service, FyydApiService $fyydapi, + ILogger $logger, $userId) { parent::__construct(Application::APP_ID, $request); $this->service = $service; $this->fyydapi = $fyydapi; + $this->logger = $logger; $this->userId = $userId; } @@ -60,13 +67,34 @@ class EpisodeController extends Controller { public function index(int $episode_id = null, int $podcast_id = null, int $count = 20, int $page = 0, string $sortBy = null): DataResponse { + $data = $this->service->findAll($this->userId, $sortBy); + if ($episode_id) { - return new DataResponse($this->fyydapi->queryEpisode($episode_id)); + $list = $this->fyydapi->queryEpisode($episode_id); + + foreach($data as $localEpisode) { + if ($localEpisode->getId() == $list['data']['id']) { + $list['data']['lastplayed'] = $localEpisode->getLastplayed(); + $list['data']['playtime'] = $localEpisode->getPlaytime(); + } + } + + return new DataResponse($list); } else if ($podcast_id) { - return new DataResponse($this->fyydapi->queryEpisodes($podcast_id, $count, $page)); + $list = $this->fyydapi->queryEpisodes($podcast_id, $count, $page); + + foreach($list['data']['episodes'] as $key=>$fyydEpisode) { + foreach($data as $localEpisode) { + if ($localEpisode->getId() == $fyydEpisode['id']) { + $list['data']['episodes'][$key]['lastplayed'] = $localEpisode->getLastplayed(); + $list['data']['episodes'][$key]['playtime'] = $localEpisode->getPlaytime(); + } + } + } + + return new DataResponse($list); } - $data = $this->service->findAll($this->userId, $sortBy); $data = array_slice($data, $page * $count, $count); if (count($data) == $count) { diff --git a/lib/Controller/ShowController.php b/lib/Controller/ShowController.php index 40e67bafc9cae4b112e48360d4ef1898a288655f..2d47fca4e16b01655e16f518d0de85fa31a166b7 100644 --- a/lib/Controller/ShowController.php +++ b/lib/Controller/ShowController.php @@ -58,14 +58,23 @@ class ShowController extends Controller { public function index(int $podcast_id = null, string $category = null, int $count = 20, int $page = 0): DataResponse { + $data = $this->service->findAll($this->userId); + if ($category) { - return new DataResponse($this->fyydapi->queryCategory($category, $count, - $page)); + $list = $this->fyydapi->queryCategory($category, $count, $page); + return new DataResponse($list); } else if ($podcast_id) { - return new DataResponse($this->fyydapi->queryPodcast($podcast_id)); + $list = $this->fyydapi->queryPodcast($podcast_id); + + foreach($data as $localEpisode) { + if ($localEpisode->getId() == $list['data']['id']) { + $list['data']['dateadded'] = $localEpisode->getDateadded(); + } + } + + return new DataResponse($list); } - $data = $this->service->findAll($this->userId); $data = array_slice($data, $page * $count, $count); if (count($data) == $count) { diff --git a/lib/Service/FyydApiService.php b/lib/Service/FyydApiService.php index 251cbc5f274d852348f6b4f691ea91bdcfba68b1..f5c7a1b5ef547d1f8a63292a083e4a88c1914d2b 100644 --- a/lib/Service/FyydApiService.php +++ b/lib/Service/FyydApiService.php @@ -69,7 +69,6 @@ class FyydApiService { $parsed = json_decode($body, true); - return $parsed; } diff --git a/src/components/MediaHeader.vue b/src/components/MediaHeader.vue index 5ac3fa438827d3d7b18f9fa30dc6a6c651fc62c2..a92e41d0e3107169e71a5eee27776ae674b1c06f 100644 --- a/src/components/MediaHeader.vue +++ b/src/components/MediaHeader.vue @@ -34,7 +34,7 @@ v-show="isshow" class="podcastControls"> <button class="icon-add-white podcastButton button new-button" - :class="showExists(podcastid) ? 'icon-delete' : 'icon-add-white primary'" + :class="dateadded ? 'icon-delete' : 'icon-add-white primary'" @click="doSubscribe()"> {{ getSubscribeText }} </button> @@ -62,7 +62,6 @@ <script> import vueShowMoreText from 'vue-show-more-text' import { ShowApi } from './../services/ShowApi' -import { mapGetters } from 'vuex' const apiClient = new ShowApi() @@ -106,13 +105,14 @@ export default { type: Boolean, default: false, }, + dateadded: { + type: Boolean, + default: false, + }, }, computed: { - ...mapGetters([ - 'showExists', - ]), getSubscribeText() { - if (this.showExists(this.podcastid)) { + if (this.dateadded) { return t('podcast', 'Unsubscribe') } else { return t('podcast', 'Subscribe') diff --git a/src/store/episode.js b/src/store/episode.js index e6a812c12aef9c0571a31bf3dd6e03c0c7f47b31..8cba43b52aa6158a46fb91e4d08969a794548d69 100644 --- a/src/store/episode.js +++ b/src/store/episode.js @@ -55,8 +55,10 @@ export default { }, updateEpisode(state, { episode, playtime } = {}) { const existingIndex = state.episodes.findIndex(_episode => _episode.id === episode.id) - state.episodes[existingIndex].playtime = playtime - state.episodes[existingIndex].lastplayed = Date.now() + if (existingIndex >= 0) { + state.episodes[existingIndex].playtime = playtime + state.episodes[existingIndex].lastplayed = Date.now() + } }, }, actions: { @@ -74,22 +76,6 @@ export default { .then((episode) => { commit('addEpisode', episode) }) - const testEpisode = { - id: 6461881, - imgURL: 'https://thumborcdn.acast.com/lYYH8lBYyScJ5JcMCkVGdrY1EHg=/3000x3000/https://mediacdn.acast.com/assets/4f71cda1-166c-4604-88a7-bf1e6686c9e9/cover-image-kluot63n-thehistoryofbyzantium_new_.jpg', - title: 'Episode 225 - test episode', - pubdate: '2021-03-04T10:57:48+01:00', - duration: 3834, - playtime: 0, - lastplayed: 1616511062258, - enclosure: 'https://sphinx.acast.com/thehistoryofbyzantium/episode225-belisariusinmetal/media.mp3', - description: 'test test test', - podcast_id: 48700, - } - episodeApiClient.addEpisode(testEpisode) - .then((episode) => { - commit('addEpisode', episode) - }) }, removeEpisode({ commit }, episode) { episodeApiClient.removeEpisode(episode) diff --git a/src/store/player.js b/src/store/player.js index 6a9a6a44f11b6fe2156b7623381a5940128ef6e5..693c907f183a39aadb1d887ee6ade6a199f2521a 100644 --- a/src/store/player.js +++ b/src/store/player.js @@ -45,6 +45,7 @@ export default { playtime: null, duration: null, enclosure: null, + lastplayed: null, }, }, getters: { @@ -194,12 +195,11 @@ export default { }, storePlaybacktime(context, position) { - const episodeId = context.state.episode.id - const episode = context.getters.episodeById(episodeId) - const episodeLastPlayed = episode.lastplayed + const episode = context.state.episode const dateNow = Date.now() - if (dateNow - episodeLastPlayed >= 5000) { + if (dateNow - episode.lastplayed >= 5000) { context.dispatch('updateEpisode', { episode, playtime: position }) + context.state.episode.lastplayed = Date.now() } }, diff --git a/src/store/show.js b/src/store/show.js index 2c022f6d55304f46487e334e1ba40c6fffc88b13..7b29ce43accc189cc38a97f21db07a371f13ab49 100644 --- a/src/store/show.js +++ b/src/store/show.js @@ -32,12 +32,6 @@ export default { showById: state => (id) => { return state.shows.find((show) => show.id === id) }, - showExists: state => (id) => { - if (id !== undefined) { - id = Number(id) - return state.shows.some((show) => show.id === id) - } - }, }, mutations: { addShow(state, show) { diff --git a/src/views/Show.vue b/src/views/Show.vue index 98f92273581b1a5f3fb1a53063b9d6997526d67d..ed39a4adf51be1479f0f037032ad1316c2631fe1 100644 --- a/src/views/Show.vue +++ b/src/views/Show.vue @@ -32,6 +32,7 @@ :categories="podcast.categories" :description="podcast.description" :podcastid="podcast.id" + :dateadded="podcast.dateadded" :isshow="true" @doSubscribe="doSubscribe" /> <LoadMore :page="page" @@ -74,7 +75,6 @@ export default { }), computed: { ...mapGetters([ - 'showExists', 'episodePlaying', ]), }, @@ -103,7 +103,7 @@ export default { ]), doSubscribe() { - if (this.showExists(this.podcastId)) { + if (this.podcast.showadded) { this.removeShow(this.podcast) } else { this.addShow(this.podcast)