diff --git a/lib/forum-activity.js b/lib/forum-activity.js index db608603e..ada71c949 100644 --- a/lib/forum-activity.js +++ b/lib/forum-activity.js @@ -20,12 +20,17 @@ async function recursiveFetchDiscourse(url, before = null, acc = []) { } async function fetchForum(url) { - if (!url.match(/discourse/) && !url.match(/socialhub\.activitypub\.rocks/)) return "Did not fetch forum at " + url; - // TODO: fix case where discourse URL is for a specific category à la - // https://discourse.wicg.io/c/web-mapping - // TODO: detect if forum is discourse more reliably? + if (url.match(/slack\.com\//) || url.match(/google.com\//)) { + return `Forum ${url} is hosted on a non-supported platform`; + } if (url.endsWith("/")) url = url.slice(0, -1); - return {items: await recursiveFetchDiscourse(url + '/posts.json')}; + try { + return {items: await recursiveFetchDiscourse(url + '/posts.json')}; + } catch (e) { + return `Did not recognize discourse API for ${url}`; + } + // TODO: handle case where discourse URL is for a specific category à la + // https://discourse.wicg.io/c/web-mapping } module.exports.fetchForum = fetchForum; diff --git a/test/forum-activity.js b/test/forum-activity.js index d576efbb3..c715c19a8 100644 --- a/test/forum-activity.js +++ b/test/forum-activity.js @@ -16,7 +16,7 @@ const agent = new MockAgent(); let counter = 0; const testUrl = () => { counter++; - return new URL(`https://example.test/discourse/mail${counter}/`); + return new URL(`https://example.test/disc/mail${counter}/`); } const toDiscourseAPI = p => p + 'posts.json'; @@ -45,6 +45,14 @@ describe('The Forum Activity monitor', function () { assert.equal(data[0].created_at, "2023-11-01T21:30:42.605Z", 'Date retrieved from discourse post'); }); + it('skips Google Groups and Slacks', async function() { + const data = await fetchForum("https://groups.google.com/g/test"); + assert.equal(typeof data, 'string'); + const data2 = await fetchForum("https://test.slack.com/channel"); + assert.equal(typeof data2, 'string'); + }); + + /* it("returns an error when the archive doesn't exist", async function() { const u = testUrl();