openvibers/openvibe.community Commits

The Feed names a wiki page by its title (#321)

OP OpenVibers committed 4 days ago · 2a2430833a · 2 files, +7 −1

Changes

ddiff --git a/server/pulse/consumer.js b/server/pulse/consumer.js
iindex 9e33198..1b68557 100644
---- a/server/pulse/consumer.js
++++ b/server/pulse/consumer.js
@@@ -71,7 +71,8 @@ function itemFor(event) {
// blog.post.published names its blog as { id, handle } (contracts payload v1); a plain string is still read.
const blogName = clean(p.blog && typeof p.blog === 'object' ? p.blog.handle : p.blog, 60);
const title = k[0] === 'blog' ? (blogName ? `New post on the ${blogName} blog` : 'New post on an OpenVibe blog')
-- : k[0] === 'wiki' ? `Wiki: ${clean(p.space, 40)} / ${clean(p.slug, 60)}`
++ // A wiki page by its title when the event carries one (contracts 0.366.0), else by where it lives.
++ : k[0] === 'wiki' ? (clean(p.title, 160) || `Wiki: ${clean(p.space, 40)} / ${clean(p.slug, 60)}`)
: `News: ${clean(p.topic, 60) || 'a new story'}`;
const actor = event.actor && event.actor.type === 'user' ? subjectOf(event.actor) : null;
// An edited page moves to the top: the feed says "new and updated Wiki articles", not only first publications.
ddiff --git a/test/pulse-consumer.test.js b/test/pulse-consumer.test.js
iindex 29892b8..ab368b3 100644
---- a/test/pulse-consumer.test.js
++++ b/test/pulse-consumer.test.js
@@@ -148,6 +148,11 @@ let SECRET, db, app, vipDrops, USR, seq, evt;
const wikiRows = await db.prepare("SELECT * FROM pulse_items WHERE source_service = 'wiki' AND source_id = 'pg_3'").all();
assert.strictEqual(wikiRows.length, 1, 'one row per page');
assert.notStrictEqual(wikiRows[0].occurred_at, oldAt, 'an edit moves it up');
++ // With a title (contracts 0.366.0) the item is named by it, not by where it lives.
++ r = await post(evt({ event_type: 'wiki.page.published', source: 'wiki', subject: { type: 'page', id: 'pg_titled' },
++ payload: { canonical_url: 'https://openvibe.wiki/w/help/titled', publication_state: 'published', visibility: 'public', space: 'help', slug: 'titled', title: 'How to go live from a phone', indexability: { decision: 'index', reasons: [] } } }));
++ const titled = await db.prepare("SELECT title FROM pulse_items WHERE source_service = 'wiki' AND source_id = 'pg_titled'").get();
++ assert.strictEqual(titled && titled.title, 'How to go live from a phone', JSON.stringify(r.json));
assert.strictEqual(wikiRows[0].source_type, 'page');
// Chat: a public room's fifth message in an hour becomes one summary card, refreshed only every five after that.