Skip to content

Commit

Permalink
Detects discourse forum through API end point rather than URL
Browse files Browse the repository at this point in the history
  • Loading branch information
dontcallmedom committed Nov 13, 2023
1 parent 2a80130 commit 6f13f59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
15 changes: 10 additions & 5 deletions lib/forum-activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
10 changes: 9 additions & 1 deletion test/forum-activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6f13f59

Please sign in to comment.