From f2037c23caadf7b6488eaf0ba26049ef75cf19a9 Mon Sep 17 00:00:00 2001 From: Guilherme Dellagustin Date: Sat, 11 Feb 2023 16:13:17 +0100 Subject: [PATCH] Issue #213: socialInteract from the API As https://github.com/Podcastindex-org/docs-api/issues/91 is now implemented, this commit replaces the hard coded comment uri by the content of the socialInteract property from the podcast index API. Note: even though the spec does not forbid two socialInteracts with the same protocol, this implementation only takes the first one. If we see use cases for supporting both, then we will need to update later. --- server/index.js | 18 ++++++++++-------- ui/src/pages/Podcast/PodcastInfo/index.tsx | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/server/index.js b/server/index.js index 5f3386d1..bc6f5f1f 100644 --- a/server/index.js +++ b/server/index.js @@ -122,20 +122,22 @@ app.use('/api/add/byfeedurl', async (req, res) => { // ------------ API to get comments for episode --- // ------------------------------------------------ app.use('/api/comments/byepisodeid', async (req, res) => { - let episodeId = req.query.id - const response = await api.episodesById(episodeId, false) + let episodeId = req.query.id; + const response = await api.episodesById(episodeId, false); - // The API request above will be used once socialInteract is returned by the API - // the log statement below just shows the API call is working, it should be removed - // later when the response is actually used - console.log(response) + const socialInteract = response.episode.socialInteract && response.episode.socialInteract.filter((si) => si.protocol === 'activitypub'); + + if(!socialInteract && socialInteract.lenght >= 0) { + // Bad requests sounds appropriate, as the client is only expected to call this API + // when it validated upfront that the episode has a property socialInteract with activitypub protocol + res.status(400).send('The episode does not contain a socialInteract property') + } const userAgent = USER_AGENT; const cache = new InMemoryCache(); const fetcher = makeRateLimitedFetcher(fetch); - // TODO: Once socialInteract is returned by the API, we should replace the URL here - const threadcap = await makeThreadcap('https://podcastindex.social/users/dave/statuses/109683341113064081', { userAgent, cache, fetcher }); + const threadcap = await makeThreadcap(socialInteract[0].uri, { userAgent, cache, fetcher }); await updateThreadcap(threadcap, { updateTime: new Date().toISOString(), userAgent, cache, fetcher }); diff --git a/ui/src/pages/Podcast/PodcastInfo/index.tsx b/ui/src/pages/Podcast/PodcastInfo/index.tsx index 02a34a36..27872f2e 100644 --- a/ui/src/pages/Podcast/PodcastInfo/index.tsx +++ b/ui/src/pages/Podcast/PodcastInfo/index.tsx @@ -232,7 +232,7 @@ export default class PodcastInfo extends React.PureComponent { description, datePublished, value, - socialInteracts + socialInteract } = item let {result} = this.state // try to use episode image, fall back to feed images @@ -259,7 +259,7 @@ export default class PodcastInfo extends React.PureComponent { transcriptUrl={transcriptUrl} description={description} datePublished={datePublished} - hasComments={socialInteracts && socialInteracts.length > 0} + hasComments={socialInteract && socialInteract.length > 0} onPlay={this.onEpisodePlay} onPause={this.onEpisodePause} />