Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Notifications: make the tray pin work

AdityaUmale9fc8ebbd8476
diff --git a/src/components/NotificationsPanel.tsx b/src/components/NotificationsPanel.tsx
index 6d8958605d..9ed3c037e2 100644
--- a/src/components/NotificationsPanel.tsx
+++ b/src/components/NotificationsPanel.tsx
@@ -3,6 +3,7 @@ import { AlertTriangle, AtSign, Bell, CheckCircle2, CircleHelp, HandHelping, Inf
import { api, useStore, openNotificationTarget, type Action } from "@/state/store";
import { cn } from "@/lib/cn";
import { t } from "@/lib/i18n";
+import { setNotificationTrayPinned } from "@/lib/notification-preferences";
import { useShowThreads } from "@/lib/thread-preferences";
import type { LocaleKey } from "@/locales";
import { BotAvatar, type BotAvatarProps } from "./Avatar";
@@ -124,6 +125,13 @@ export function NotificationsPanel() {
void postNotificationRead(`/api/notifications/${entry.id}/read`, dispatch);
}
openNotificationTarget(dispatch, { botId: entry.botId, threadId: entry.threadId }, state, showThreads);
+ if (!state.notificationsPinned) dispatch({ type: "toggleNotifications", open: false });
+ };
+
+ const togglePinned = () => {
+ const pinned = !state.notificationsPinned;
+ dispatch({ type: "toggleNotificationsPinned", pinned });
+ setNotificationTrayPinned(pinned);
};
const markAllRead = () => {
@@ -146,7 +154,7 @@ export function NotificationsPanel() {
</button>
<button
type="button"
- onClick={() => dispatch({ type: "toggleNotificationsPinned" })}
+ onClick={togglePinned}
aria-label={state.notificationsPinned ? t("notifications.unpin") : t("notifications.pin")}
aria-pressed={state.notificationsPinned}
title={state.notificationsPinned ? t("notifications.unpin") : t("notifications.pin")}
diff --git a/src/lib/notification-preferences.test.ts b/src/lib/notification-preferences.test.ts
index 3d92f1c557..2abeec91a5 100644
--- a/src/lib/notification-preferences.test.ts
+++ b/src/lib/notification-preferences.test.ts
@@ -190,3 +190,18 @@ describe("finished-work notifications preference", () => {
expect(preference.finishedNotificationsEnabled()).toBe(true);
});
});
+
+describe("notification tray pin (email 1a1a4fb0)", () => {
+ it("defaults off and survives a renderer reload", async () => {
+ let preference = await import("./notification-preferences");
+ expect(preference.notificationTrayPinned()).toBe(false);
+ preference.setNotificationTrayPinned(true);
+ expect(local.getItem(preference.NOTIFICATION_TRAY_PINNED_KEY)).toBe("1");
+ vi.resetModules();
+ preference = await import("./notification-preferences");
+ expect(preference.notificationTrayPinned()).toBe(true);
+ preference.setNotificationTrayPinned(false);
+ expect(local.getItem(preference.NOTIFICATION_TRAY_PINNED_KEY)).toBeNull();
+ expect(preference.notificationTrayPinned()).toBe(false);
+ });
+});
diff --git a/src/lib/notification-preferences.ts b/src/lib/notification-preferences.ts
index faabc76e5b..d44fd8c6f0 100644
--- a/src/lib/notification-preferences.ts
+++ b/src/lib/notification-preferences.ts
@@ -3,6 +3,7 @@ import { useSyncExternalStore } from "react";
export const NOTIFICATION_SOUNDS_KEY = "omb-notification-sounds";
export const NOTIFICATION_FEED_KEY = "omb-notification-feed";
export const FINISHED_NOTIFICATIONS_KEY = "omb-finished-notifications";
+export const NOTIFICATION_TRAY_PINNED_KEY = "omb-notification-tray-pinned";
let sessionChoice: boolean | undefined;
let feedSessionChoice: boolean | undefined;
@@ -118,3 +119,21 @@ export function setFinishedNotifications(enabled: boolean): void {
export function useFinishedNotifications(): boolean {
return useSyncExternalStore(subscribe, finishedNotificationsEnabled, () => true);
}
+
+/** Per device: the notification tray stays open while the person switches chats. */
+export function notificationTrayPinned(): boolean {
+ try {
+ return storage()?.getItem(NOTIFICATION_TRAY_PINNED_KEY) === "1";
+ } catch {
+ return false;
+ }
+}
+
+export function setNotificationTrayPinned(pinned: boolean): void {
+ try {
+ if (pinned) storage()?.setItem(NOTIFICATION_TRAY_PINNED_KEY, "1");
+ else storage()?.removeItem(NOTIFICATION_TRAY_PINNED_KEY);
+ } catch {
+ // Storage can be full or blocked; the pin still holds for this session.
+ }
+}
diff --git a/src/state/store.test.ts b/src/state/store.test.ts
index 16ac350cca..43fd5bc84c 100644
--- a/src/state/store.test.ts
+++ b/src/state/store.test.ts
@@ -38,6 +38,7 @@ import {
import { LAST_CONVERSATION_KEY } from "@/lib/last-conversation";
import { cacheDesktopCapabilities, desktopCapabilitiesNow } from "@/lib/desktop";
import { LAST_BOT_SECTION_KEY } from "@/lib/last-bot-section";
+import { NOTIFICATION_TRAY_PINNED_KEY } from "@/lib/notification-preferences";
import { transcriptLookups } from "@/lib/transcript-derivations";
import { openLiveEvents, type LiveEventSourceLike, type LiveEventsPlatform } from "../lib/live-events";
import type { ModelVariantState, RuntimeEvent } from "../../shared/runtime-events";
@@ -3019,6 +3020,13 @@ describe("restoring the open conversation", () => {
expect(stored.get(LAST_CONVERSATION_KEY)).toBe("room-1");
});
+ it("the provider restores the notification tray pin remembered on this device (email 1a1a4fb0)", async () => {
+ const { stream } = await boot({ [NOTIFICATION_TRAY_PINNED_KEY]: "1" });
+ stream.send(hello());
+ await settle();
+ expect(seen.notificationsPinned).toBe(true);
+ });
+
it("the provider remembers a section only while it is expanded", async () => {
const { stored, stream } = await boot({ [LAST_BOT_SECTION_KEY]: "model" });
stream.send(hello());
@@ -3157,10 +3165,21 @@ describe("notifications feed", () => {
expect(state).toMatchObject({ notificationsPinned: true, notificationsOpen: false });
});
- it("survives a bot switch: select/switchTask never reset it", () => {
- const withOpen = reducer(initialState, { type: "toggleNotifications", open: true });
- const afterSwitch = reducer(withOpen, { type: "switchTask", botId: "other-bot", threadId: "other-thread" });
- expect(afterSwitch.notificationsOpen).toBe(true);
+ it("unpinned, switching chats closes it; pinned, it stays open (email 1a1a4fb0)", () => {
+ const open = { ...reducer(initialState, { type: "toggleNotifications", open: true }), selectedId: "bot-1" };
+ const switches = [
+ { type: "select", id: "other-bot" } as const,
+ { type: "switchTask", botId: "other-bot", threadId: "other-thread" } as const,
+ { type: "switchGroupTask", groupId: "room-1", threadId: "room-thread" } as const,
+ ];
+ for (const action of switches) expect(reducer(open, action).notificationsOpen).toBe(false);
+ const pinned = reducer(open, { type: "toggleNotificationsPinned" });
+ for (const action of switches) expect(reducer(pinned, action).notificationsOpen).toBe(true);
+ });
+
+ it("re-selecting the open chat leaves the tray as it is", () => {
+ const open = { ...reducer(initialState, { type: "toggleNotifications", open: true }), selectedId: "bot-1" };
+ expect(reducer(open, { type: "select", id: "bot-1" }).notificationsOpen).toBe(true);
});
it("pinned, the feed survives Computer/Inspector/Activity/AppSettings opening", () => {
diff --git a/src/state/store.tsx b/src/state/store.tsx
index 771c9a8e3f..4ab897de8e 100644
--- a/src/state/store.tsx
+++ b/src/state/store.tsx
@@ -19,7 +19,7 @@ import { DATA_ROUTES, type DataSheet, type DataTable } from "../../shared/data-s
import type { NotificationLogEntry } from "../../shared/notification";
import { isNotificationFeedAction, reduceNotificationFeed, type NotificationFeedAction } from "./notification-feed";
import { bumpThreadUpdatedAt, mergeTaskStamps, rewindThreadUpdatedAt } from "./thread-stamps";
-import { botOpensTo, openBot, openNotificationTarget, visibleNotificationThread } from "./thread-navigation";
+import { botOpensTo, closeUnpinnedTray, openBot, openNotificationTarget, visibleNotificationThread, withRememberedTrayPin } from "./thread-navigation";
import { patchGroupTask } from "./thread-edits";
import type { EngineInstall } from "./engine-install";
import { optimisticMessageId, optimisticUserMessage, sendArrived, sendReconciled } from "./optimistic-send";
@@ -1081,7 +1081,7 @@ export function reducer(state: AppState, action: Action): AppState {
const room = state.groups.find((g) => g.id === action.id);
if (room) {
return {
- ...state,
+ ...(action.id === state.selectedId ? state : closeUnpinnedTray(state)),
unreadDivider: openedUnreadDivider(state, room.threadId, room.unread, room.messages, room.lastReadMessageId),
activeView: "chat",
selectedId: action.id,
@@ -1092,7 +1092,7 @@ export function reducer(state: AppState, action: Action): AppState {
return updateBot(
withMascotMotion(
{
- ...state,
+ ...(action.id === state.selectedId ? state : closeUnpinnedTray(state)),
unreadDivider: opened
? openedUnreadDivider(state, opened.threadId, threadOpensUnread(opened), visibleMessages(opened), threadReadCursor(opened))
: state.unreadDivider,
@@ -1726,9 +1726,10 @@ export function reducer(state: AppState, action: Action): AppState {
activeLeafId: message.id,
})), threadId, message.at, true);
}
+ case "switchGroupTask":
+ return closeUnpinnedTray(state);
case "deleteTask":
case "newGroupTask":
- case "switchGroupTask":
case "deleteGroupTask":
case "regenerateTaskTitle":
return state;
@@ -1736,8 +1737,7 @@ export function reducer(state: AppState, action: Action): AppState {
return action.cwd !== undefined ? state : { ...state, selectedId: action.botId, activeView: "chat" };
case "switchTask": {
const { [action.threadId]: _old, ...backgroundThreadEvents } = state.backgroundThreadEvents;
- return updateBot({ ...state, backgroundThreadEvents, selectedId: action.botId, activeView: "chat" }, action.botId,
- (bot) => ({ ...bot, switchingTo: action.threadId }));
+ return updateBot({ ...closeUnpinnedTray(state), backgroundThreadEvents, selectedId: action.botId, activeView: "chat" }, action.botId, (bot) => ({ ...bot, switchingTo: action.threadId }));
}
case "switchTaskFailed":
return updateBot(state, action.botId, (bot) => bot.switchingTo === action.threadId ? { ...bot, switchingTo: undefined } : bot);
@@ -2111,7 +2111,7 @@ export function StoreProvider({ children }: { children: ReactNode }) {
...bot,
tasks: bot.tasks?.map((task) => ({ ...task, ...taskPatchFields(taskWrites.get(task.threadId)?.patch ?? {}) })),
});
- const [state, rawDispatch] = useReducer(reducer, initialState, restoreBotSettingsSection);
+ const [state, rawDispatch] = useReducer(reducer, initialState, (initial) => withRememberedTrayPin(restoreBotSettingsSection(initial)));
const stateRef = useRef(state), selectionRevision = useRef(0);
stateRef.current = state;
const showThreads = useShowThreads();
diff --git a/src/state/thread-navigation.ts b/src/state/thread-navigation.ts
index a50681d0d7..a7982d33ea 100644
--- a/src/state/thread-navigation.ts
+++ b/src/state/thread-navigation.ts
@@ -1,3 +1,4 @@
+import { notificationTrayPinned } from "@/lib/notification-preferences";
import type { NotificationTarget } from "@/lib/notify";
import type { Action, AppState } from "./store";
import { openOwnTeamChat } from "./team-chats";
@@ -117,3 +118,15 @@ export function openThread(
dispatch({ type: "notice", notice: { kind: "thread-gone", botName: bot?.name ?? null } });
return false;
}
+
+type NotificationTray = Pick<AppState, "notificationsOpen" | "notificationsPinned">;
+
+/** Leaving a chat closes the notification tray unless the person pinned it. */
+export function closeUnpinnedTray<T extends NotificationTray>(state: T): T {
+ return state.notificationsOpen && !state.notificationsPinned ? { ...state, notificationsOpen: false } : state;
+}
+
+/** The tray pin is remembered per device, so it holds after a restart. */
+export function withRememberedTrayPin<T extends NotificationTray>(state: T): T {
+ return notificationTrayPinned() ? { ...state, notificationsPinned: true } : state;
+}