fix: message scheduling 404 and date/time picker UX
API fix: delay was embedded in the path string causing 404 — moved to
proper query param object; prefix changed from '' to the full MSC4140
unstable prefix so authedRequest builds the correct URL. Cancel and
restart endpoints fixed the same way.
Date/time picker: replaced single datetime-local (hard to use time
portion) with separate date + time inputs side by side; colorScheme:'dark'
hints the browser to render calendar/clock popups in dark mode to match
the app. Preview row now shows as a styled Primary.Container chip with
clock icon. Relative time ("in 2h 15m") shown below the label.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,11 +14,12 @@ export async function scheduleMessage(
|
||||
content: IContent,
|
||||
sendAtMs: number,
|
||||
): Promise<string> {
|
||||
const delayMs = sendAtMs - Date.now();
|
||||
const delayMs = Math.max(1000, Math.round(sendAtMs - Date.now()));
|
||||
const txnId = `sched_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
||||
const path = `/_matrix/client/unstable/org.matrix.msc4140/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${txnId}?delay=${Math.max(1000, Math.round(delayMs))}`;
|
||||
const res = (await mx.http.authedRequest(Method.Put, path, undefined, content, {
|
||||
prefix: '',
|
||||
// Use the path relative to the MSC4140 prefix — authedRequest prepends prefix to path.
|
||||
const path = `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${txnId}`;
|
||||
const res = (await mx.http.authedRequest(Method.Put, path, { delay: delayMs }, content, {
|
||||
prefix: '/_matrix/client/unstable/org.matrix.msc4140',
|
||||
})) as { delay_id: string };
|
||||
return res.delay_id;
|
||||
}
|
||||
@@ -29,17 +30,27 @@ export async function scheduleMessage(
|
||||
* @param delayId - The delay_id from scheduleMessage
|
||||
*/
|
||||
export async function cancelScheduledMessage(mx: MatrixClient, delayId: string): Promise<void> {
|
||||
const path = `/_matrix/client/unstable/org.matrix.msc4140/delayed_events/${encodeURIComponent(delayId)}`;
|
||||
await mx.http.authedRequest(Method.Post, path, undefined, { action: 'cancel' }, { prefix: '' });
|
||||
const path = `/delayed_events/${encodeURIComponent(delayId)}`;
|
||||
await mx.http.authedRequest(
|
||||
Method.Post,
|
||||
path,
|
||||
undefined,
|
||||
{ action: 'cancel' },
|
||||
{
|
||||
prefix: '/_matrix/client/unstable/org.matrix.msc4140',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart (refresh heartbeat) a scheduled message via MSC4140.
|
||||
* Resets the delay timer from now.
|
||||
* @param mx - Matrix client instance
|
||||
* @param delayId - The delay_id from scheduleMessage
|
||||
*/
|
||||
export async function restartScheduledMessage(mx: MatrixClient, delayId: string): Promise<void> {
|
||||
const path = `/_matrix/client/unstable/org.matrix.msc4140/delayed_events/${encodeURIComponent(delayId)}`;
|
||||
await mx.http.authedRequest(Method.Post, path, undefined, { action: 'restart' }, { prefix: '' });
|
||||
const path = `/delayed_events/${encodeURIComponent(delayId)}`;
|
||||
await mx.http.authedRequest(
|
||||
Method.Post,
|
||||
path,
|
||||
undefined,
|
||||
{ action: 'restart' },
|
||||
{
|
||||
prefix: '/_matrix/client/unstable/org.matrix.msc4140',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user