feat: bookmarks, message scheduling, image compression, room insights

P3-1: Message Bookmarks — right-click any message to bookmark; saved to
io.lotus.bookmarks account data (max 500, syncs across devices); star
icon in sidebar opens BookmarksPanel with filter, Jump-to-message, and
remove buttons; reactive to AccountData events

P3-2: Message Scheduling (MSC4140) — clock button next to send opens
ScheduleMessageModal with datetime-local picker; validates ≥1 min future;
calls PUT org.matrix.msc4140 delayed event API; collapsible
ScheduledMessagesTray above composer lists pending messages with cancel;
local Jotai atom tracks scheduled messages per room

P3-3: File Upload Compression — opt-in checkbox per JPEG/PNG file ≥200KB
in upload preview; canvas API compresses at 0.82 quality; shows before/
after size estimate; compressed blob used in upload when checked

P3-7: Room Insights — new Insights tab in room settings; top 5 active
members (bar chart), top 5 reactions (chips), media breakdown (4 tiles),
24-hour activity heatmap (CSS bar chart); all from local cache only with
disclaimer banner; never the first tab shown

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 10:26:08 -04:00
parent ad508ac61e
commit 9273eb5f2e
19 changed files with 1694 additions and 7 deletions
+69
View File
@@ -0,0 +1,69 @@
export type CompressionResult = {
blob: Blob;
originalSize: number;
compressedSize: number;
width: number;
height: number;
};
const COMPRESSIBLE_TYPES = ['image/jpeg', 'image/png'];
const COMPRESSION_SKIP_THRESHOLD = 200 * 1024; // 200 KB
/** Returns true if this file type can be compressed AND the file is large enough to bother. */
export function isCompressible(file: File): boolean {
return COMPRESSIBLE_TYPES.includes(file.type) && file.size >= COMPRESSION_SKIP_THRESHOLD;
}
/**
* Compress an image file via canvas.toBlob.
* Returns null if the file type is not compressible (GIF, SVG, WebP, video, audio, etc.).
*/
export async function compressImage(file: File, quality = 0.82): Promise<CompressionResult | null> {
if (!COMPRESSIBLE_TYPES.includes(file.type)) return null;
const img = await loadImage(file);
const canvas = document.createElement('canvas');
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
const ctx = canvas.getContext('2d')!;
ctx.drawImage(img, 0, 0);
return new Promise((resolve) => {
canvas.toBlob(
(blob) => {
if (!blob) {
resolve(null);
return;
}
resolve({
blob,
originalSize: file.size,
compressedSize: blob.size,
width: img.naturalWidth,
height: img.naturalHeight,
});
},
'image/jpeg',
quality,
);
});
}
function loadImage(file: File): Promise<HTMLImageElement> {
return new Promise((resolve, reject) => {
const url = URL.createObjectURL(file);
const img = new Image();
img.onload = () => {
URL.revokeObjectURL(url);
resolve(img);
};
img.onerror = reject;
img.src = url;
});
}
export function formatFileSize(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}
+45
View File
@@ -0,0 +1,45 @@
import { IContent, MatrixClient, Method } from 'matrix-js-sdk';
/**
* Schedule a message via MSC4140 (delayed messages).
* @param mx - Matrix client instance
* @param roomId - The room to send the message in
* @param content - The message event content
* @param sendAtMs - Unix timestamp (ms) when the message should be sent
* @returns The delay_id returned by the server (use to cancel/restart)
*/
export async function scheduleMessage(
mx: MatrixClient,
roomId: string,
content: IContent,
sendAtMs: number,
): Promise<string> {
const delayMs = 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: '',
})) as { delay_id: string };
return res.delay_id;
}
/**
* Cancel a scheduled message via MSC4140.
* @param mx - Matrix client instance
* @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: '' });
}
/**
* 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: '' });
}