Files
cinny/src/app/utils/ownStatusSync.test.ts
T
Lotus CIandClaude Opus 5.5 d9c797f3f5
CI / Build & Quality Checks (pull_request) Successful in 3m9s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 7s
CI / Playwright smoke (e2e) (pull_request) Successful in 12m36s
fix(presence): leaving Do Not Disturb restores your status instead of "dnd" (#283)
Lotus encodes DND as status_msg "dnd". After switching back to Auto, the
heartbeat read the server's status, adopted "dnd" as the user's own and
kept re-sending it, so the custom status was lost and other clients kept
showing "dnd"; the Settings status field showed "dnd" too.

pickHeartbeatStatus (unit-tested) never adopts the "dnd" sentinel and
falls back to the device's real status; Profile neither mirrors it into
the local status nor shows it in the field.

Verified on the local Synapse: "🎮 Gaming" → DND (unavailable/dnd) → Auto
→ online/"🎮 Gaming" (before: online/"dnd").

Still open in #283: while in DND other clients show the literal "dnd";
that needs MSC3026 busy presence on the homeserver (matrix#19).

Refs #283

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
2026-10-12 12:39:38 -04:00

82 lines
2.3 KiB
TypeScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { LOCAL_WRITE_GRACE_MS, pickHeartbeatStatus } from './ownStatusSync';
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',
);
});