openvibers/openvibe.chat Commits

Chat: a room with nobody consenting reads quiet, not an old overview (#482)

OP OpenVibers committed 4 days ago · 244819edb2 · 2 files, +14 −1

Changes

ddiff --git a/server/chat/room-insight.js b/server/chat/room-insight.js
iindex cb4d082..a3ca33a 100644
---- a/server/chat/room-insight.js
++++ b/server/chat/room-insight.js
@@@ -42,7 +42,9 @@ function _timeline(events) {
}
function _shape(row, events) {
-- const fresh = !!(row && row.overview && row.window_end && Date.now() - _time(row.window_end) < QUIET_AFTER_MS);
++ // A summary written from nobody's messages is not a read of the room: zero consenting people means
++ // quiet, however recent the row is (rows written before the consent filter carry no people count).
++ const fresh = !!(row && row.overview && Number(row.people) > 0 && row.window_end && Date.now() - _time(row.window_end) < QUIET_AFTER_MS);
const state = fresh ? 'ready' : 'quiet';
return {
overview: {
ddiff --git a/test/room-insight.test.js b/test/room-insight.test.js
iindex 9243bb9..17221c9 100644
---- a/test/room-insight.test.js
++++ b/test/room-insight.test.js
@@@ -27,6 +27,17 @@ t('a fresh summary is ready and keeps its topics, people and timeline', async ()
assert.strictEqual(shaped.overview.from, from);
});
++t('a fresh summary with nobody consenting is quiet, never served as a read of the room', async () => {
++ const now = sqliteNow();
++ const shaped = roomInsight._shape({
++ overview: 'written before the consent filter', window_start: now, window_end: now, updated_at: now,
++ people: 0, window_message_count: 300, topics_json: '[]',
++ }, []);
++ assert.strictEqual(shaped.state, 'quiet');
++ assert.strictEqual(shaped.overview.text, '');
++ assert.strictEqual(shaped.overview.messages, 0);
++});
++
t('an old summary is quiet: no text, no topics, the timeline stays', async () => {
const old = sqliteNow(-48 * 3600e3);
const shaped = roomInsight._shape({