import { createSource, createSourceOptions, downloadImages, fetchChannel, getPostIdFromPathname } from "../lib.js" let mastodon = {} mastodon.createSource = (usertag, options, postReducerCallback, cache) => { let [ user, hostname ] = usertag.toLowerCase().split('@') let source = { type: 'mastodon', description: `Aggregate feed for @${user} at ${hostname}`, hostname, pathname: '@' + user + ".rss", name: `${hostname}-${user}`, displayName: user, user, ...createSourceOptions(options) } return createSource(source, fetchChannel, postReducerCallback, cache) } mastodon.isRepost = (post) => { // Mastodon's rss does not provide retweets/retoots return false } mastodon.pullImages = async (post, view, discardPostIfNoImages) => { let media = post.item.getElementsByTagName('media:content') let images = [] for(let image of media) { images.push(image.getAttribute('url')) } if(!discardPostIfNoImages || media.length > 0) { post.images = await downloadImages( images, post.source, getPostIdFromPathname(post), view ) return post } } export default mastodon