openvibers/openvibe.community Commits

Activity: a thread links to its own slug (#406)

OP OpenVibers committed 21 h ago · ff2f0645d0 · 2 files, +6 −2

The public activity read now selects the thread slug; menu and Pulse thread cards open the thread, not its space.

Changes

ddiff --git a/server/activity/service.js b/server/activity/service.js
iindex 1f19999..5884802 100644
---- a/server/activity/service.js
++++ b/server/activity/service.js
@@@ -55,7 +55,7 @@ function createActivity({ db, config = {} } = {}) {
}
async function threads(since, limit) {
-- const rows = await db.prepare(`SELECT t.id, t.title, t.created_at, t.author_subject, t.origin, t.views, t.score, t.reply_count, s.slug AS space,
++ const rows = await db.prepare(`SELECT t.id, t.slug AS thread_slug, t.title, t.created_at, t.author_subject, t.origin, t.views, t.score, t.reply_count, s.slug AS space,
(SELECT b.body_markdown FROM posts b WHERE b.thread_id = t.id AND b.is_opening = 1 AND b.deleted_at IS NULL LIMIT 1) AS opening
FROM threads t JOIN spaces s ON s.id = t.space_id
WHERE s.visibility = 'public' AND s.members_only_owner IS NULL AND t.members_only_owner IS NULL
@@@ -64,7 +64,7 @@ function createActivity({ db, config = {} } = {}) {
return rows.map((t) => ({
service: 'community', type: 'thread', id: String(t.id),
title: clean(t.title, 300) || 'A thread', text: clean(t.opening, 280),
-- url: `${base}/forum/${encodeURIComponent(t.space)}/${encodeURIComponent(t.slug || '')}`,
++ url: `${base}/forum/${encodeURIComponent(t.space)}/${encodeURIComponent(t.thread_slug || '')}`,
actor: t.author_subject || null, origin: t.origin === 'ai' ? 'ai' : t.origin === 'system' ? 'system' : 'user',
at: iso(t.created_at), kind: 'post', picture_url: null, media_ratio: null,
counts: counts({ views: t.views, likes: t.score, comments: t.reply_count }),
ddiff --git a/test/feed-proxy.test.js b/test/feed-proxy.test.js
iindex ee8bd23..8cb3b90 100644
---- a/test/feed-proxy.test.js
++++ b/test/feed-proxy.test.js
@@@ -64,10 +64,14 @@ const ITEM = {
VALUES (?, ?, 'user', 'paste', ?, ?, ?, ?)`).run('public-one', ITEM.subject, 'A public paste', 'hello', 'public', at);
await t.db.prepare(`INSERT INTO pastes (slug, owner_subject, origin, type, title, content, visibility, created_at)
VALUES (?, ?, 'user', 'paste', ?, ?, ?, ?)`).run('private-one', ITEM.subject, 'A private paste', 'secret', 'private', at);
++ const space = await t.db.prepare("SELECT id FROM spaces WHERE slug = 'general'").get();
++ await t.db.prepare(`INSERT INTO threads (space_id, slug, title, author_subject, origin, created_at)
++ VALUES (?, 'one-feed', 'A thread about one feed', ?, 'user', ?)`).run(space.id, ITEM.subject, at);
const r = await t.get('/api/v1/activity?limit=50');
assert.strictEqual(r.status, 200, r.text);
const items = r.json().items;
assert.ok(items.some((i) => i.id === 'public-one' && i.url === 'https://openvibe.community/p/public-one'));
++ assert.ok(items.some((i) => i.title === 'A thread about one feed' && i.url === 'https://openvibe.community/forum/general/one-feed'), 'a thread links to its own slug');
assert.ok(!items.some((i) => i.id === 'private-one'), 'a private paste never leaves Community');
assert.ok(items.every((i) => i.service === 'community' && i.at && i.url));
});