Skip to content

Commit

Permalink
Issue #213: socialInteract from the API
Browse files Browse the repository at this point in the history
As Podcastindex-org/docs-api#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.
  • Loading branch information
dellagustin committed Feb 11, 2023
1 parent 61ae1cc commit f2037c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
4 changes: 2 additions & 2 deletions ui/src/pages/Podcast/PodcastInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export default class PodcastInfo extends React.PureComponent<IProps> {
description,
datePublished,
value,
socialInteracts
socialInteract
} = item
let {result} = this.state
// try to use episode image, fall back to feed images
Expand All @@ -259,7 +259,7 @@ export default class PodcastInfo extends React.PureComponent<IProps> {
transcriptUrl={transcriptUrl}
description={description}
datePublished={datePublished}
hasComments={socialInteracts && socialInteracts.length > 0}
hasComments={socialInteract && socialInteract.length > 0}
onPlay={this.onEpisodePlay}
onPause={this.onEpisodePause}
/>
Expand Down

0 comments on commit f2037c2

Please sign in to comment.