CI / Build & Quality Checks (push) Skipped
CI / Secret scan (gitleaks) (push) Skipped
CI / Playwright smoke (e2e) (push) Skipped
Discord/Spotify-style now playing, served by the new Lotus now-playing service (matrix repo, now-playing/): - Profile popout: a "Listening to" card (cover, track, artist, album, live progress); member list: a 🎵 line when the member has no typed status. Data comes from GET /now-playing/v1/users, batched across all visible users and polled every 20 s while the page is visible. - Settings → Profile: "Share what I'm listening to", off by default, stored by the service (GET/PUT /v1/me). Auth is a Matrix OpenID token. - Status text: while Lotus is open and sharing, the Matrix status shows "🎵 Artist – Track" so other clients see it, but only when the user has no typed status, and never in DND/Invisible. The typed status and its auto-clear are never touched. The music text uses a thin space after the note, and every device reads it as "no typed status" (pickHeartbeatStatus, Profile sync), so it can't be adopted as the user's status. Clearing or auto-clearing a status falls back to the music; closing the window drops it (pagehide sends the typed status). - config.json: nowPlaying → https://matrix.lotusguild.org/now-playing. Tests: nowPlaying.test.ts (format, marker, priority matrix, position, config/cover URLs) and a heartbeat case in ownStatusSync.test.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
120 lines
3.5 KiB
TypeScript
120 lines
3.5 KiB
TypeScript
import { test } from 'node:test';
|
||
import assert from 'node:assert/strict';
|
||
import { LOCAL_WRITE_GRACE_MS, pickHeartbeatStatus } from './ownStatusSync';
|
||
import { NOW_PLAYING_PREFIX } from './nowPlaying';
|
||
|
||
const now = 1_000_000;
|
||
const old = { lastLocalWriteAt: 0, now };
|
||
|
||
test('a status cleared on another device is not re-published (DP3)', () => {
|
||
assert.equal(
|
||
pickHeartbeatStatus({ ...old, local: 'stale', server: { presence: 'online', status_msg: '' } }),
|
||
'',
|
||
);
|
||
assert.equal(pickHeartbeatStatus({ ...old, local: 'stale', server: { presence: 'online' } }), '');
|
||
});
|
||
|
||
test('a status set on another device is kept', () => {
|
||
assert.equal(
|
||
pickHeartbeatStatus({
|
||
...old,
|
||
local: 'stale',
|
||
server: { presence: 'unavailable', status_msg: 'new' },
|
||
}),
|
||
'new',
|
||
);
|
||
});
|
||
|
||
test('falls back to the local copy when the read failed or we are invisible', () => {
|
||
assert.equal(pickHeartbeatStatus({ ...old, local: 'mine', server: undefined }), 'mine');
|
||
assert.equal(
|
||
pickHeartbeatStatus({ ...old, local: 'mine', server: { presence: 'offline', status_msg: '' } }),
|
||
'mine',
|
||
);
|
||
});
|
||
|
||
test("a fresh local save wins over a server read that hasn't caught up", () => {
|
||
const server = { presence: 'online', status_msg: 'previous' };
|
||
assert.equal(
|
||
pickHeartbeatStatus({ local: 'just saved', server, lastLocalWriteAt: now - 2000, now }),
|
||
'just saved',
|
||
);
|
||
assert.equal(
|
||
pickHeartbeatStatus({
|
||
local: 'just saved',
|
||
server,
|
||
lastLocalWriteAt: now - LOCAL_WRITE_GRACE_MS - 1,
|
||
now,
|
||
}),
|
||
'previous',
|
||
);
|
||
});
|
||
|
||
test('pickHeartbeatStatus: the "dnd" sentinel is never adopted as the user status (#283)', () => {
|
||
const base = { lastLocalWriteAt: 0, now: 100_000 };
|
||
// leaving DND: the server still says "dnd" → restore the real local status
|
||
assert.equal(
|
||
pickHeartbeatStatus({
|
||
...base,
|
||
local: '🎮 Gaming',
|
||
server: { presence: 'unavailable', status_msg: 'dnd' },
|
||
}),
|
||
'🎮 Gaming',
|
||
);
|
||
// a local copy that had absorbed the sentinel becomes empty, not "dnd"
|
||
assert.equal(
|
||
pickHeartbeatStatus({
|
||
...base,
|
||
local: 'dnd',
|
||
server: { presence: 'online', status_msg: 'dnd' },
|
||
}),
|
||
'',
|
||
);
|
||
// ordinary statuses are unaffected
|
||
assert.equal(
|
||
pickHeartbeatStatus({
|
||
...base,
|
||
local: 'old',
|
||
server: { presence: 'online', status_msg: 'new' },
|
||
}),
|
||
'new',
|
||
);
|
||
});
|
||
|
||
test('[Gitea #491] music text on the server is never adopted as a typed status', () => {
|
||
const music = `${NOW_PLAYING_PREFIX}Maroon 5 – Animals`;
|
||
// Music is only published with no typed status, so it reads as "none" —
|
||
// including when another device has since cleared the typed status.
|
||
assert.equal(
|
||
pickHeartbeatStatus({ ...old, local: '', server: { presence: 'online', status_msg: music } }),
|
||
'',
|
||
);
|
||
assert.equal(
|
||
pickHeartbeatStatus({
|
||
...old,
|
||
local: 'cleared elsewhere',
|
||
server: { presence: 'online', status_msg: music },
|
||
}),
|
||
'',
|
||
);
|
||
// A fresh local save still wins over a server read showing the old music.
|
||
assert.equal(
|
||
pickHeartbeatStatus({
|
||
local: 'studying',
|
||
server: { presence: 'online', status_msg: music },
|
||
lastLocalWriteAt: now - 1000,
|
||
now,
|
||
}),
|
||
'studying',
|
||
);
|
||
// A status the user typed that merely starts with 🎵 is theirs.
|
||
assert.equal(
|
||
pickHeartbeatStatus({
|
||
...old,
|
||
local: '',
|
||
server: { presence: 'online', status_msg: '🎵 vibes' },
|
||
}),
|
||
'🎵 vibes',
|
||
);
|
||
});
|