Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
feat(notifications): clear all, with Undo
mantrandev8b02e5d87824
diff --git a/server/message-db.ts b/server/message-db.tsindex d46d8ec643..a630e8f530 100644--- a/server/message-db.ts+++ b/server/message-db.ts@@ -109,7 +109,7 @@ function open(): DatabaseSync {CREATE INDEX IF NOT EXISTS notification_log_at ON notification_log(at);`);const notificationColumns = db.prepare("PRAGMA table_info(notification_log)").all() as Array<{ name: string }>;- for (const added of ["for_person", "read_by"]) if (!notificationColumns.some((column) => column.name === added)) db.exec(`ALTER TABLE notification_log ADD COLUMN ${added} TEXT`);+ for (const added of ["for_person", "read_by", "cleared_by"]) if (!notificationColumns.some((column) => column.name === added)) db.exec(`ALTER TABLE notification_log ADD COLUMN ${added} TEXT`);ensureRecallIndex(db);ensureMemoryIndex(db);return db;@@ -314,16 +314,16 @@ export function logNotification(notification: Notification): NotificationLogEntr}export function recentNotificationLog(limit = NOTIFICATION_LOG_LIMIT, reader?: string): NotificationLogEntry[] {- const read = reader === undefined ? "read" : "(read = 1 OR EXISTS (SELECT 1 FROM json_each(coalesce(read_by, '[]')) WHERE value = ?)) AS read";- const rows = db().prepare(`SELECT id, at, kind, bot_id, bot_name, thread_id, group_id, title, body, avatar_url, for_person, ${read} FROM notification_log ORDER BY at DESC, rowid DESC LIMIT ?`)- .all(...(reader === undefined ? [] : [reader]), limit) as Array<Parameters<typeof rowToNotificationLogEntry>[0]>;+ const [read, kept] = reader === undefined ? ["read", ""] : ["(read = 1 OR EXISTS (SELECT 1 FROM json_each(coalesce(read_by, '[]')) WHERE value = ?1)) AS read", "WHERE NOT EXISTS (SELECT 1 FROM json_each(coalesce(cleared_by, '[]')) WHERE value = ?1)"];+ const rows = db().prepare(`SELECT id, at, kind, bot_id, bot_name, thread_id, group_id, title, body, avatar_url, for_person, ${read} FROM notification_log ${kept} ORDER BY at DESC, rowid DESC LIMIT ${reader === undefined ? "?1" : "?2"}`).all(...(reader === undefined ? [] : [reader]), limit) as Array<Parameters<typeof rowToNotificationLogEntry>[0]>;return rows.map(rowToNotificationLogEntry);}export function markNotificationLogRead(ids: readonly string[], reader?: string): void {if (reader === undefined) db().prepare("UPDATE notification_log SET read = 1 WHERE read = 0 AND id IN (SELECT value FROM json_each(?))").run(JSON.stringify(ids));else db().prepare("UPDATE notification_log SET read_by = json_insert(coalesce(read_by, '[]'), '$[#]', ?1) WHERE id IN (SELECT value FROM json_each(?2)) AND NOT EXISTS (SELECT 1 FROM json_each(coalesce(read_by, '[]')) WHERE value = ?1)").run(reader, JSON.stringify(ids));}-export function forgetNotificationReader(person: string): void { db().prepare("UPDATE notification_log SET read_by = (SELECT json_group_array(value) FROM json_each(read_by) WHERE value <> ?1) WHERE EXISTS (SELECT 1 FROM json_each(coalesce(read_by, '[]')) WHERE value = ?1)").run(person); }+export function clearNotificationLog(ids: readonly string[], reader?: string): void { if (reader === undefined) db().prepare("DELETE FROM notification_log WHERE id IN (SELECT value FROM json_each(?))").run(JSON.stringify(ids)); else db().prepare("UPDATE notification_log SET cleared_by = json_insert(coalesce(cleared_by, '[]'), '$[#]', ?1) WHERE id IN (SELECT value FROM json_each(?2)) AND NOT EXISTS (SELECT 1 FROM json_each(coalesce(cleared_by, '[]')) WHERE value = ?1)").run(reader, JSON.stringify(ids)); }+export function forgetNotificationReader(person: string): void { for (const column of ["read_by", "cleared_by"]) db().prepare(`UPDATE notification_log SET ${column} = (SELECT json_group_array(value) FROM json_each(${column}) WHERE value <> ?1) WHERE EXISTS (SELECT 1 FROM json_each(coalesce(${column}, '[]')) WHERE value = ?1)`).run(person); }export function saveChatFollowup(followup: Omit<ChatFollowup, "status">): void {writeFollowups((connection) => connection.prepare(diff --git a/server/request-auth.ts b/server/request-auth.tsindex 76d0610b4b..1fd6dd0340 100644--- a/server/request-auth.ts+++ b/server/request-auth.ts@@ -312,6 +312,7 @@ export const CLIENT_ALLOW: ReadonlyArray<{ methods: readonly string[]; path: Reg{ methods: ["GET"], path: /^\/api\/auth\/session$/ },{ methods: ["GET"], path: /^\/api\/notifications$/ },{ methods: ["POST"], path: /^\/api\/notifications\/read-all$/ },+ { methods: ["POST"], path: /^\/api\/notifications\/clear$/ },{ methods: ["POST"], path: /^\/api\/notifications\/[\w-]+\/read$/ },// the update check only reads a version{ methods: ["GET"], path: /^\/api\/updates\/check$/ },diff --git a/server/routes/notifications.test.ts b/server/routes/notifications.test.tsindex dd6294e4b8..187f47f518 100644--- a/server/routes/notifications.test.ts+++ b/server/routes/notifications.test.ts@@ -4,7 +4,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";import { json, readBody } from "../harness/http.ts";import type { NotificationLogEntry } from "../../shared/notification.ts";-import { forgetNotificationReader, insertNotificationLog, markNotificationLogRead, recentNotificationLog } from "../message-db.ts";+import { clearNotificationLog, forgetNotificationReader, insertNotificationLog, markNotificationLogRead, recentNotificationLog } from "../message-db.ts";import type { RequestAuth } from "../request-auth.ts";import { createNotificationRoutes, notificationListedFor, readThreadNotifications } from "./notifications.ts";import { dispatchRoutes } from "./table.ts";@@ -21,7 +21,7 @@ async function serve(shown?: (auth: RequestAuth) => (threadId: string) => boolean,reaches?: (auth: RequestAuth, entry: NotificationLogEntry) => boolean,) {- const deps = { recent: vi.fn(() => entries), markRead: vi.fn() };+ const deps = { recent: vi.fn(() => entries), markRead: vi.fn(), clear: vi.fn() };const routes = [createNotificationRoutes(deps, notificationListedFor(shown, reaches))];const server = createServer(async (req, res) => {const url = new URL(req.url ?? "/", "http://localhost");@@ -71,6 +71,18 @@ describe("notification routes", () => {expect(deps.markRead).toHaveBeenCalledTimes(1);});+ it("clears what the viewer's own list shows, all of it or what came before a time", async () => {+ const old = { ...sample, id: "n2", at: 10 };+ const hidden = { ...sample, id: "n3", threadId: "private" };+ const { base, deps } = await serve([sample, old, hidden], () => (threadId) => threadId !== "private");+ expect((await fetch(`${base}/api/notifications/clear?before=5`, { method: "POST" })).status).toBe(200);+ expect(deps.clear).toHaveBeenLastCalledWith(["n1"]);+ expect((await fetch(`${base}/api/notifications/clear`, { method: "POST" })).status).toBe(200);+ expect(deps.clear).toHaveBeenLastCalledWith(["n1", "n2"]);+ expect((await fetch(`${base}/api/notifications/clear?before=soon`, { method: "POST" })).status).toBe(400);+ expect(deps.clear).toHaveBeenCalledTimes(2);+ });+it("opening a conversation reads only what the opener's own list shows", () => {const ask = { ...sample, id: "n2", kind: "question" as const };const elsewhere = { ...sample, id: "n3", threadId: "t2" };@@ -119,6 +131,18 @@ describe("notification routes", () => {expect(unread("p_cleo")).toEqual(["f1"]);});+ it("clearing deletes the entries, and on a team hides them from that person alone", () => {+ for (const id of ["c1", "c2", "c3"]) insertNotificationLog({ ...sample, id, threadId: "clear-t" });+ const ids = (person?: string) => recentNotificationLog(undefined, person).filter((entry) => entry.threadId === "clear-t").map((entry) => entry.id).sort();+ clearNotificationLog(["c1"]);+ expect(ids()).toEqual(["c2", "c3"]);+ clearNotificationLog(["c2"], "p_ada");+ expect(ids("p_ada")).toEqual(["c3"]);+ expect(ids("p_cleo")).toEqual(["c2", "c3"]);+ forgetNotificationReader("p_ada");+ expect(ids("p_ada")).toEqual(["c2", "c3"]);+ });+it("leaves other paths and methods to the next handler", async () => {const { base, deps } = await serve();expect((await fetch(`${base}/api/notifications`, { method: "POST" })).status).toBe(404);diff --git a/server/routes/notifications.ts b/server/routes/notifications.tsindex da8a6e1086..5afa249b90 100644--- a/server/routes/notifications.ts+++ b/server/routes/notifications.ts@@ -1,5 +1,5 @@import { userError } from "../user-errors.ts";-import { markNotificationLogRead, recentNotificationLog } from "../message-db.ts";+import { clearNotificationLog, markNotificationLogRead, recentNotificationLog } from "../message-db.ts";import type { NotificationLogEntry } from "../../shared/notification.ts";import { ownerOrAdmin, type RequestAuth } from "../request-auth.ts";import { PASS, type RouteHandler } from "./table.ts";@@ -42,13 +42,19 @@ export function notificationListedFor(shown: (auth: RequestAuth) => (threadId: sexport type NotificationListed = ReturnType<typeof notificationListedFor>;-export function createNotificationRoutes(deps: { recent(reader?: string): NotificationLogEntry[]; markRead(ids: readonly string[], reader?: string): void } = {+export function createNotificationRoutes(deps: {+ recent(reader?: string): NotificationLogEntry[];+ markRead(ids: readonly string[], reader?: string): void;+ clear(ids: readonly string[], reader?: string): void;+} = {recent: (reader) => recentNotificationLog(undefined, reader),markRead: markNotificationLogRead,+ clear: clearNotificationLog,}, listed: NotificationListed = notificationListedFor()): RouteHandler {const visible = (listing: NotificationListing) => deps.recent(listing.reader).filter(listing);const markRead = (ids: string[], reader: string | undefined) => (reader === undefined ? deps.markRead(ids) : deps.markRead(ids, reader));- return async ({ res, path, method, auth, json }) => {+ const clear = (ids: string[], reader: string | undefined) => (reader === undefined ? deps.clear(ids) : deps.clear(ids, reader));+ return async ({ res, url, path, method, auth, json }) => {if (method === "GET" && path === "/api/notifications") {return json(res, 200, { notifications: visible(listed(auth)) });}@@ -59,6 +65,14 @@ export function createNotificationRoutes(deps: { recent(reader?: string): Notifiif (unread.length) markRead(unread, listing.reader);return json(res, 200, { ok: true });}+ if (path === "/api/notifications/clear") {+ const raw = url.searchParams.get("before");+ const before = raw === null ? Infinity : Number(raw);+ if (raw !== null && !Number.isFinite(before)) return json(res, 400, { error: "before must be a time in milliseconds" });+ const ids = visible(listing).filter((entry) => entry.at < before).map((entry) => entry.id);+ if (ids.length) clear(ids, listing.reader);+ return json(res, 200, { ok: true });+ }const m = path.match(/^\/api\/notifications\/([\w-]+)\/read$/);if (!m) return PASS;if (!visible(listing).some((entry) => entry.id === m[1])) return json(res, 404, userError("serverError.notification.missing"));diff --git a/src/components/NotificationsPanel.tsx b/src/components/NotificationsPanel.tsxindex 25abf598b3..a695d331bf 100644--- a/src/components/NotificationsPanel.tsx+++ b/src/components/NotificationsPanel.tsx@@ -1,5 +1,5 @@-import { useEffect, useState } from "react";-import { AlertTriangle, AtSign, Bell, CheckCircle2, CircleHelp, HandHelping, Info, KeyRound, LogIn, Newspaper, Pin, RotateCcw, Wallet, X, type LucideIcon } from "lucide-react";+import { useCallback, useEffect, useRef, useState } from "react";+import { AlertTriangle, AtSign, Bell, CheckCircle2, CircleHelp, HandHelping, Info, KeyRound, LogIn, Newspaper, Pin, RotateCcw, Trash2, Wallet, X, type LucideIcon } from "lucide-react";import { api, useStore, openThread, type Action } from "@/state/store";import { cn } from "@/lib/cn";import { t } from "@/lib/i18n";@@ -11,6 +11,7 @@ import { threadUpdatedLabel } from "./SidebarThreadRow";import type { NotificationLogEntry, NotifyKind } from "../../shared/notification";import { plainPreviewText } from "../../shared/plain-preview";import { Select } from "./Select";+import { UndoToast, useUndoToast } from "./UndoToast";const KIND_LOOK: Record<NotifyKind, { Icon: LucideIcon; className: string; status: LocaleKey }> = {done: { Icon: CheckCircle2, className: "text-success", status: "notifications.status.done" },@@ -119,6 +120,18 @@ export async function postNotificationRead(path: string, dispatch: (action: Actiexport function NotificationsPanel() {const { state, dispatch } = useStore();+ const [toast, setToast] = useUndoToast();+ const pendingClear = useRef<number | null>(null);+ const commitClear = useCallback(() => {+ const before = pendingClear.current;+ if (before === null) return;+ pendingClear.current = null;+ void postNotificationRead(`/api/notifications/clear?before=${before}`, dispatch);+ }, [dispatch]);+ useEffect(() => {+ if (!toast) commitClear();+ }, [toast, commitClear]);+ useEffect(() => commitClear, [commitClear]);const showThreads = useShowThreads();const [now, setNow] = useState(() => Date.now());const [botFilter, setBotFilter] = useState(ALL_BOTS);@@ -151,6 +164,20 @@ export function NotificationsPanel() {void postNotificationRead("/api/notifications/read-all", dispatch);};+ const clearAll = () => {+ const cleared = state.notifications;+ if (cleared.length === 0) return;+ pendingClear.current = Date.now();+ dispatch({ type: "notificationsCleared" });+ setToast({+ text: t("notifications.cleared"),+ undo: () => {+ pendingClear.current = null;+ dispatch({ type: "notificationsHydrated", notifications: cleared });+ },+ });+ };+return (<asidearia-label={t("notifications.title")}@@ -164,6 +191,15 @@ export function NotificationsPanel() {<button type="button" onClick={markAllRead} className="shrink-0 whitespace-nowrap text-[12px] text-accent hover:underline">{t("notifications.markAllRead")}</button>+ <button+ type="button"+ onClick={clearAll}+ aria-label={t("notifications.clearAll")}+ title={t("notifications.clearAll")}+ className="flex size-[26px] shrink-0 items-center justify-center rounded-md text-ink-secondary hover:bg-raised hover:text-ink"+ >+ <Trash2 size={14} />+ </button><buttontype="button"onClick={togglePinned}@@ -210,6 +246,7 @@ export function NotificationsPanel() {<div className="border-t border-hairline/40 px-3.5 py-2 text-center text-[12px] text-ink-tertiary">{t("notifications.retention")}</div>+ <UndoToast toast={toast} onDone={() => setToast(null)} /></aside>);}diff --git a/src/locales/en.json b/src/locales/en.jsonindex 0efb4ccdd6..4016a7b137 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -2004,6 +2004,8 @@"notifications.railUnread": "Notifications, {count} unread","notifications.unread": "{count} unread","notifications.markAllRead": "Mark all read",+ "notifications.clearAll": "Clear all",+ "notifications.cleared": "Notifications cleared","notifications.pin": "Pin Notifications open","notifications.unpin": "Unpin Notifications","notifications.close": "Close Notifications",diff --git a/src/locales/es.json b/src/locales/es.jsonindex 6836429772..95a03cc4ce 100644--- a/src/locales/es.json+++ b/src/locales/es.json@@ -1292,6 +1292,8 @@"notifications.railUnread": "Notificaciones, {count} sin leer","notifications.unread": "{count} sin leer","notifications.markAllRead": "Marcar todo como leído",+ "notifications.clearAll": "Borrar todo",+ "notifications.cleared": "Notificaciones borradas","notifications.pin": "Fijar el panel de notificaciones","notifications.unpin": "Dejar de fijar el panel de notificaciones","notifications.close": "Cerrar el panel de notificaciones",diff --git a/src/locales/it.json b/src/locales/it.jsonindex 57bf1dd39b..4f1833981e 100644--- a/src/locales/it.json+++ b/src/locales/it.json@@ -2002,6 +2002,8 @@"notifications.railUnread": "Notifiche, {count} non lette","notifications.unread": "{count} non lette","notifications.markAllRead": "Segna tutte come lette",+ "notifications.clearAll": "Cancella tutto",+ "notifications.cleared": "Notifiche cancellate","notifications.pin": "Tieni aperto Notifiche","notifications.unpin": "Sgancia Notifiche","notifications.close": "Chiudi Notifiche",diff --git a/src/locales/ja.json b/src/locales/ja.jsonindex 75da991a2e..d311b43ac1 100644--- a/src/locales/ja.json+++ b/src/locales/ja.json@@ -1623,6 +1623,8 @@"notifications.railUnread": "通知、未読{count}件","notifications.unread": "未読{count}件","notifications.markAllRead": "すべて既読にする",+ "notifications.clearAll": "すべて消去",+ "notifications.cleared": "通知を消去しました","notifications.pin": "通知を開いたままにする","notifications.unpin": "通知の固定を解除","notifications.close": "通知を閉じる",diff --git a/src/locales/ko.json b/src/locales/ko.jsonindex 89d41ec73a..eceb2ad2f3 100644--- a/src/locales/ko.json+++ b/src/locales/ko.json@@ -1540,6 +1540,8 @@"notifications.railUnread": "알림, 읽지 않음 {count}개","notifications.unread": "읽지 않음 {count}개","notifications.markAllRead": "모두 읽음으로 표시",+ "notifications.clearAll": "모두 지우기",+ "notifications.cleared": "알림을 지웠습니다","notifications.pin": "알림 고정해서 열어 두기","notifications.unpin": "알림 고정 해제","notifications.close": "알림 닫기",diff --git a/src/locales/pl.json b/src/locales/pl.jsonindex d7f5b01845..87c7a52a16 100644--- a/src/locales/pl.json+++ b/src/locales/pl.json@@ -1471,6 +1471,8 @@"notifications.railUnread": "Powiadomienia, nieprzeczytane: {count}","notifications.unread": "Nieprzeczytane: {count}","notifications.markAllRead": "Oznacz wszystkie jako przeczytane",+ "notifications.clearAll": "Wyczyść wszystko",+ "notifications.cleared": "Powiadomienia wyczyszczone","notifications.pin": "Przypnij panel powiadomień","notifications.unpin": "Odepnij powiadomienia","notifications.close": "Zamknij powiadomienia",diff --git a/src/locales/pt-br.json b/src/locales/pt-br.jsonindex 213b6cf5a9..95d298f122 100644--- a/src/locales/pt-br.json+++ b/src/locales/pt-br.json@@ -1799,6 +1799,8 @@"notifications.railUnread": "Notificações, não lidas: {count}","notifications.unread": "Não lidas: {count}","notifications.markAllRead": "Marcar tudo como lido",+ "notifications.clearAll": "Limpar tudo",+ "notifications.cleared": "Notificações limpas","notifications.pin": "Fixar o painel de notificações aberto","notifications.unpin": "Desafixar o painel de notificações","notifications.close": "Fechar as notificações",diff --git a/src/locales/ru.json b/src/locales/ru.jsonindex 5bc9904602..c405843969 100644--- a/src/locales/ru.json+++ b/src/locales/ru.json@@ -1476,6 +1476,8 @@"notifications.railUnread": "Уведомления, {count} непрочитанных","notifications.unread": "{count} непрочитанных","notifications.markAllRead": "Отметить все как прочитанные",+ "notifications.clearAll": "Очистить всё",+ "notifications.cleared": "Уведомления удалены","notifications.pin": "Закрепить уведомления открытыми","notifications.unpin": "Открепить уведомления","notifications.close": "Закрыть уведомления",diff --git a/src/locales/source-hashes.json b/src/locales/source-hashes.jsonindex 7516669f46..be803a3b40 100644--- a/src/locales/source-hashes.json+++ b/src/locales/source-hashes.json@@ -10988,7 +10988,9 @@"cloudSend.changes.lendCommandsHint": "f2454f4eb2cd204a3de88bf81670931a3906f8783641dbd990d3ec0738c7cfa3","cloudSend.changes.engine": "5cb26111535a50b4390e44357b933b4f72576dc81f3ab2f4e0026b28a4de864a","cloudSend.botMove.goes": "670b500e4fcd0a977b5645e4938a8881cf97f15e76782edaceb4c8f2eadb0062",- "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236"+ "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236",+ "notifications.clearAll": "29a390f9237e3c84e5641785eca25199620e53f7b6f4b9d843b23dcb5c12904f",+ "notifications.cleared": "1465a1fea515a237e70954fa3b274d32af2b09194f7ad06ec230bd5f56773ba7"},"fr": {"pro.fromPrice": "a48a04a457d60b08b54fc83e7a6c4584ffedb1e23621859084900c8521a3af7b",@@ -27079,7 +27081,9 @@"cloudSend.changes.lendCommandsHint": "f2454f4eb2cd204a3de88bf81670931a3906f8783641dbd990d3ec0738c7cfa3","cloudSend.changes.engine": "5cb26111535a50b4390e44357b933b4f72576dc81f3ab2f4e0026b28a4de864a","cloudSend.botMove.goes": "670b500e4fcd0a977b5645e4938a8881cf97f15e76782edaceb4c8f2eadb0062",- "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236"+ "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236",+ "notifications.clearAll": "29a390f9237e3c84e5641785eca25199620e53f7b6f4b9d843b23dcb5c12904f",+ "notifications.cleared": "1465a1fea515a237e70954fa3b274d32af2b09194f7ad06ec230bd5f56773ba7"},"pt-br": {"voice.gemini.keyPlaceholder": "8c87ba2043a4a89d63c90cae8a6dafd5cbd193652e923b97988e381a74773e10",@@ -38930,7 +38934,9 @@"cloudSend.changes.lendCommandsHint": "f2454f4eb2cd204a3de88bf81670931a3906f8783641dbd990d3ec0738c7cfa3","cloudSend.changes.engine": "5cb26111535a50b4390e44357b933b4f72576dc81f3ab2f4e0026b28a4de864a","cloudSend.botMove.goes": "670b500e4fcd0a977b5645e4938a8881cf97f15e76782edaceb4c8f2eadb0062",- "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236"+ "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236",+ "notifications.clearAll": "29a390f9237e3c84e5641785eca25199620e53f7b6f4b9d843b23dcb5c12904f",+ "notifications.cleared": "1465a1fea515a237e70954fa3b274d32af2b09194f7ad06ec230bd5f56773ba7"},"zh": {"pro.fromPrice": "a48a04a457d60b08b54fc83e7a6c4584ffedb1e23621859084900c8521a3af7b",@@ -49282,7 +49288,9 @@"cloudSend.changes.lendCommandsHint": "f2454f4eb2cd204a3de88bf81670931a3906f8783641dbd990d3ec0738c7cfa3","cloudSend.changes.engine": "5cb26111535a50b4390e44357b933b4f72576dc81f3ab2f4e0026b28a4de864a","cloudSend.botMove.goes": "670b500e4fcd0a977b5645e4938a8881cf97f15e76782edaceb4c8f2eadb0062",- "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236"+ "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236",+ "notifications.clearAll": "29a390f9237e3c84e5641785eca25199620e53f7b6f4b9d843b23dcb5c12904f",+ "notifications.cleared": "1465a1fea515a237e70954fa3b274d32af2b09194f7ad06ec230bd5f56773ba7"},"zh-tw": {"whop.description": "1a07cf04ef17029448d3781415cbac16d54e66b821907a40d94e0e6349710e70",@@ -59723,7 +59731,9 @@"cloudSend.changes.lendCommandsHint": "f2454f4eb2cd204a3de88bf81670931a3906f8783641dbd990d3ec0738c7cfa3","cloudSend.changes.engine": "5cb26111535a50b4390e44357b933b4f72576dc81f3ab2f4e0026b28a4de864a","cloudSend.botMove.goes": "670b500e4fcd0a977b5645e4938a8881cf97f15e76782edaceb4c8f2eadb0062",- "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236"+ "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236",+ "notifications.clearAll": "29a390f9237e3c84e5641785eca25199620e53f7b6f4b9d843b23dcb5c12904f",+ "notifications.cleared": "1465a1fea515a237e70954fa3b274d32af2b09194f7ad06ec230bd5f56773ba7"},"uk": {"pro.fromPrice": "a48a04a457d60b08b54fc83e7a6c4584ffedb1e23621859084900c8521a3af7b",@@ -70156,7 +70166,9 @@"cloudSend.changes.lendCommandsHint": "f2454f4eb2cd204a3de88bf81670931a3906f8783641dbd990d3ec0738c7cfa3","cloudSend.changes.engine": "5cb26111535a50b4390e44357b933b4f72576dc81f3ab2f4e0026b28a4de864a","cloudSend.botMove.goes": "670b500e4fcd0a977b5645e4938a8881cf97f15e76782edaceb4c8f2eadb0062",- "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236"+ "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236",+ "notifications.clearAll": "29a390f9237e3c84e5641785eca25199620e53f7b6f4b9d843b23dcb5c12904f",+ "notifications.cleared": "1465a1fea515a237e70954fa3b274d32af2b09194f7ad06ec230bd5f56773ba7"},"tr": {"whop.description": "1a07cf04ef17029448d3781415cbac16d54e66b821907a40d94e0e6349710e70",@@ -76280,7 +76292,9 @@"cloudSend.changes.lendCommandsHint": "f2454f4eb2cd204a3de88bf81670931a3906f8783641dbd990d3ec0738c7cfa3","cloudSend.changes.engine": "5cb26111535a50b4390e44357b933b4f72576dc81f3ab2f4e0026b28a4de864a","cloudSend.botMove.goes": "670b500e4fcd0a977b5645e4938a8881cf97f15e76782edaceb4c8f2eadb0062",- "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236"+ "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236",+ "notifications.clearAll": "29a390f9237e3c84e5641785eca25199620e53f7b6f4b9d843b23dcb5c12904f",+ "notifications.cleared": "1465a1fea515a237e70954fa3b274d32af2b09194f7ad06ec230bd5f56773ba7"},"pl": {"whop.description": "1a07cf04ef17029448d3781415cbac16d54e66b821907a40d94e0e6349710e70",@@ -83605,7 +83619,9 @@"cloudSend.changes.lendCommandsHint": "f2454f4eb2cd204a3de88bf81670931a3906f8783641dbd990d3ec0738c7cfa3","cloudSend.changes.engine": "5cb26111535a50b4390e44357b933b4f72576dc81f3ab2f4e0026b28a4de864a","cloudSend.botMove.goes": "670b500e4fcd0a977b5645e4938a8881cf97f15e76782edaceb4c8f2eadb0062",- "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236"+ "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236",+ "notifications.clearAll": "29a390f9237e3c84e5641785eca25199620e53f7b6f4b9d843b23dcb5c12904f",+ "notifications.cleared": "1465a1fea515a237e70954fa3b274d32af2b09194f7ad06ec230bd5f56773ba7"},"ru": {"whop.description": "1a07cf04ef17029448d3781415cbac16d54e66b821907a40d94e0e6349710e70",@@ -90984,7 +91000,9 @@"cloudSend.changes.lendCommandsHint": "f2454f4eb2cd204a3de88bf81670931a3906f8783641dbd990d3ec0738c7cfa3","cloudSend.changes.engine": "5cb26111535a50b4390e44357b933b4f72576dc81f3ab2f4e0026b28a4de864a","cloudSend.botMove.goes": "670b500e4fcd0a977b5645e4938a8881cf97f15e76782edaceb4c8f2eadb0062",- "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236"+ "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236",+ "notifications.clearAll": "29a390f9237e3c84e5641785eca25199620e53f7b6f4b9d843b23dcb5c12904f",+ "notifications.cleared": "1465a1fea515a237e70954fa3b274d32af2b09194f7ad06ec230bd5f56773ba7"},"it": {"whop.description": "1a07cf04ef17029448d3781415cbac16d54e66b821907a40d94e0e6349710e70",@@ -102754,7 +102772,9 @@"cloudSend.changes.lendCommandsHint": "f2454f4eb2cd204a3de88bf81670931a3906f8783641dbd990d3ec0738c7cfa3","cloudSend.changes.engine": "5cb26111535a50b4390e44357b933b4f72576dc81f3ab2f4e0026b28a4de864a","cloudSend.botMove.goes": "670b500e4fcd0a977b5645e4938a8881cf97f15e76782edaceb4c8f2eadb0062",- "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236"+ "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236",+ "notifications.clearAll": "29a390f9237e3c84e5641785eca25199620e53f7b6f4b9d843b23dcb5c12904f",+ "notifications.cleared": "1465a1fea515a237e70954fa3b274d32af2b09194f7ad06ec230bd5f56773ba7"},"ko": {"connectedWorkspaces.localTitle": "7d6deafeab011d734c3fdd1bfd6f69544fbb746a004019269bdb48544b01164b",@@ -110607,7 +110627,9 @@"cloudSend.changes.lendCommandsHint": "f2454f4eb2cd204a3de88bf81670931a3906f8783641dbd990d3ec0738c7cfa3","cloudSend.changes.engine": "5cb26111535a50b4390e44357b933b4f72576dc81f3ab2f4e0026b28a4de864a","cloudSend.botMove.goes": "670b500e4fcd0a977b5645e4938a8881cf97f15e76782edaceb4c8f2eadb0062",- "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236"+ "cloudSend.changes.commandsTools": "af6e99ce2459132c8aa5a48d21aa12e8e2bbe5d3d4f49b99d7656f947c883236",+ "notifications.clearAll": "29a390f9237e3c84e5641785eca25199620e53f7b6f4b9d843b23dcb5c12904f",+ "notifications.cleared": "1465a1fea515a237e70954fa3b274d32af2b09194f7ad06ec230bd5f56773ba7"}}}diff --git a/src/locales/tr.json b/src/locales/tr.jsonindex bc7452fc7f..8a124c4491 100644--- a/src/locales/tr.json+++ b/src/locales/tr.json@@ -1004,6 +1004,8 @@"notifications.railUnread": "Bildirimler, {count} okunmamış","notifications.unread": "{count} okunmamış","notifications.markAllRead": "Tümünü okundu olarak işaretle",+ "notifications.clearAll": "Tümünü temizle",+ "notifications.cleared": "Bildirimler temizlendi","notifications.pin": "Bildirimleri açık sabitle","notifications.unpin": "Bildirimlerin sabitlemesini kaldır","notifications.close": "Bildirimleri kapat",diff --git a/src/locales/vi.json b/src/locales/vi.jsonindex b3065d4634..afc20cefd0 100644--- a/src/locales/vi.json+++ b/src/locales/vi.json@@ -1004,6 +1004,8 @@"notifications.railUnread": "Thông báo, {count} chưa đọc","notifications.unread": "{count} chưa đọc","notifications.markAllRead": "Đánh dấu tất cả là đã đọc",+ "notifications.clearAll": "Xóa hết",+ "notifications.cleared": "Đã xóa thông báo","notifications.pin": "Ghim để luôn mở Thông báo","notifications.unpin": "Bỏ ghim Thông báo","notifications.close": "Đóng Thông báo",diff --git a/src/locales/zh-tw.json b/src/locales/zh-tw.jsonindex c7cfed257d..ce5f893318 100644--- a/src/locales/zh-tw.json+++ b/src/locales/zh-tw.json@@ -1723,6 +1723,8 @@"notifications.railUnread": "通知,{count} 則未讀","notifications.unread": "{count} 則未讀","notifications.markAllRead": "全部標示為已讀",+ "notifications.clearAll": "全部清除",+ "notifications.cleared": "已清除通知","notifications.pin": "將通知固定為開啟","notifications.unpin": "取消固定通知","notifications.close": "關閉通知",diff --git a/src/locales/zh.json b/src/locales/zh.jsonindex da170c4869..23a161ae85 100644--- a/src/locales/zh.json+++ b/src/locales/zh.json@@ -1863,6 +1863,8 @@"notifications.railUnread": "通知,{count} 条未读","notifications.unread": "{count} 条未读","notifications.markAllRead": "全部标为已读",+ "notifications.clearAll": "全部清除",+ "notifications.cleared": "已清除通知","notifications.pin": "将通知固定为打开状态","notifications.unpin": "取消固定通知","notifications.close": "关闭通知",diff --git a/src/state/notification-feed.ts b/src/state/notification-feed.tsindex 704d6939eb..8f6b579301 100644--- a/src/state/notification-feed.ts+++ b/src/state/notification-feed.ts@@ -7,10 +7,11 @@ export type NotificationFeedAction =| { type: "notificationReceived"; entry: NotificationLogEntry }| { type: "notificationRead"; id: string }| { type: "notificationsRead"; ids: string[] }- | { type: "notificationsMarkAllRead" };+ | { type: "notificationsMarkAllRead" }+ | { type: "notificationsCleared"; before?: number };const FEED_ACTIONS: ReadonlySet<string> = new Set<NotificationFeedAction["type"]>([- "notificationsHydrated", "notificationReceived", "notificationRead", "notificationsRead", "notificationsMarkAllRead",+ "notificationsHydrated", "notificationReceived", "notificationRead", "notificationsRead", "notificationsMarkAllRead", "notificationsCleared",]);/** The feed's own actions, which the app's reducer hands straight to reduceNotificationFeed. */@@ -37,5 +38,9 @@ export function reduceNotificationFeed(feed: NotificationLogEntry[], action: Not}case "notificationsMarkAllRead":return feed.map((entry) => (entry.read ? entry : { ...entry, read: true }));+ case "notificationsCleared": {+ const { before } = action;+ return before === undefined ? [] : feed.filter((entry) => entry.at >= before);+ }}}diff --git a/src/state/store.test.ts b/src/state/store.test.tsindex 9b798626b0..3b3ca89019 100644--- a/src/state/store.test.ts+++ b/src/state/store.test.ts@@ -3334,6 +3334,17 @@ describe("notifications feed", () => {expect(state.notifications.every((n) => n.read)).toBe(true);});+ it("clears every entry, or only those older than a time", () => {+ let state = reducer(initialState, {+ type: "notificationsHydrated",+ notifications: [entry("n1", 1), entry("n2", 2), entry("n3", 3)],+ });+ state = reducer(state, { type: "notificationsCleared", before: 2 });+ expect(state.notifications.map((n) => n.id)).toEqual(["n3", "n2"]);+ state = reducer(state, { type: "notificationsCleared" });+ expect(state.notifications).toEqual([]);+ });+it("marks the entries a conversation read elsewhere, and only those", () => {let state = reducer(initialState, {type: "notificationsHydrated",