Skip to content

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

Notifications tray: keep it open for thread switches off screen

AdityaUmale20241301e3f8
diff --git a/src/state/store.test.ts b/src/state/store.test.ts
index 975eb03712..69fb25abdf 100644
--- a/src/state/store.test.ts
+++ b/src/state/store.test.ts
@@ -3170,11 +3170,27 @@ describe("notifications feed", () => {
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);
+ const inRoom = { ...open, selectedId: "room-1", groups: [{ id: "room-1", threadId: "room-t" }] as AppState["groups"] };
+ const roomSwitch = { type: "switchGroupTask", groupId: "room-1", threadId: "room-thread" } as const;
+ expect(reducer(inRoom, roomSwitch).notificationsOpen).toBe(false);
+ expect(reducer({ ...inRoom, notificationsPinned: true }, roomSwitch).notificationsOpen).toBe(true);
+ });
+
+ it("a thread switch in a room that is not on screen leaves the tray as it is", () => {
+ const open = { ...reducer(initialState, { type: "toggleNotifications", open: true }), selectedId: "bot-1",
+ groups: [{ id: "room-1", threadId: "room-t" }] as AppState["groups"] };
+ expect(reducer(open, { type: "switchGroupTask", groupId: "room-1", threadId: "room-thread" }).notificationsOpen).toBe(true);
+ });
+
+ it("re-selecting a thread the bot is already switching to leaves the tray as it is", () => {
+ const open = { ...reducer(initialState, { type: "toggleNotifications", open: true }), selectedId: "bot-1",
+ bots: [{ id: "bot-1", threadId: "t-1", switchingTo: "t-2" }] as AppState["bots"] };
+ expect(reducer(open, { type: "switchTask", botId: "bot-1", threadId: "t-2" }).notificationsOpen).toBe(true);
+ expect(reducer(open, { type: "switchTask", botId: "bot-1", threadId: "t-3" }).notificationsOpen).toBe(false);
});
it("re-selecting the open chat or its open thread leaves the tray as it is", () => {
diff --git a/src/state/store.tsx b/src/state/store.tsx
index 5abbd95a69..e6a8a53d18 100644
--- a/src/state/store.tsx
+++ b/src/state/store.tsx
@@ -583,7 +583,7 @@ export interface AppState {
computerOpen: boolean;
inspectorOpen: boolean;
activityOpen: boolean;
- /** Cross-bot, so a bot switch leaves it open; pinned, opening another side panel leaves it open too. */
+ /** Shared across bots. Unpinned, it closes on a chat switch and when another side panel opens; pinned, it stays open. */
notificationsOpen: boolean;
notificationsPinned: boolean;
notifications: NotificationLogEntry[];
@@ -1727,7 +1727,7 @@ export function reducer(state: AppState, action: Action): AppState {
})), threadId, message.at, true);
}
case "switchGroupTask":
- return closeTrayUnlessShown(state, action.groupId, action.threadId);
+ return state.selectedId === action.groupId && state.activeView === "chat" ? closeTrayUnlessShown(state, action.groupId, action.threadId) : state;
case "deleteTask":
case "newGroupTask":
case "deleteGroupTask":
diff --git a/src/state/thread-navigation.ts b/src/state/thread-navigation.ts
index 81724362ec..aaf7330822 100644
--- a/src/state/thread-navigation.ts
+++ b/src/state/thread-navigation.ts
@@ -127,7 +127,9 @@ export function closeUnpinnedTray<T extends NotificationTray>(state: T): T {
/** Opening the chat already on screen is not leaving it. */
export function closeTrayUnlessShown(state: AppState, id: string, threadId: string): AppState {
- const shown = state.activeView === "chat" && id === state.selectedId && [...state.bots, ...state.groups].find((chat) => chat.id === id)?.threadId === threadId;
+ const chat = [...state.bots, ...state.groups].find((candidate) => candidate.id === id);
+ const shownThreadId = chat && "switchingTo" in chat ? chat.switchingTo ?? chat.threadId : chat?.threadId;
+ const shown = state.activeView === "chat" && id === state.selectedId && shownThreadId === threadId;
return shown ? state : closeUnpinnedTray(state);
}