openvibers/openvibe.community Commits
Activity: a thread links to its own slug (#406)
Changes
@@@ -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 openingFROM threads t JOIN spaces s ON s.id = t.space_idWHERE 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 }),@@@ -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));});
@@ -55,7 +55,7 @@ function createActivity({ db, config = {} } = {}) {
@@ -55,7 +55,7 @@ function createActivity({ db, config = {} } = {}) {
}
}
async function threads(since, limit) {
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
(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
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
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 = {} } = {}) {
@@ -64,7 +64,7 @@ function createActivity({ db, config = {} } = {}) {
return rows.map((t) => ({
return rows.map((t) => ({
service: 'community', type: 'thread', id: String(t.id),
service: 'community', type: 'thread', id: String(t.id),
title: clean(t.title, 300) || 'A thread', text: clean(t.opening, 280),
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',
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,
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 }),
counts: counts({ views: t.views, likes: t.score, comments: t.reply_count }),
@@ -64,10 +64,14 @@ const ITEM = {
@@ -64,10 +64,14 @@ const ITEM = {
VALUES (?, ?, 'user', 'paste', ?, ?, ?, ?)`).run('public-one', ITEM.subject, 'A public paste', 'hello', 'public', at);
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)
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);
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');
const r = await t.get('/api/v1/activity?limit=50');
assert.strictEqual(r.status, 200, r.text);
assert.strictEqual(r.status, 200, r.text);
const items = r.json().items;
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.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.some((i) => i.id === 'private-one'), 'a private paste never leaves Community');
assert.ok(items.every((i) => i.service === 'community' && i.at && i.url));
assert.ok(items.every((i) => i.service === 'community' && i.at && i.url));
});
});