Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix: team roster, date grouping correctness
Chadpiha49b786ed66d8
diff --git a/src/components/notes/SpacesTree.tsx b/src/components/notes/SpacesTree.tsxindex 429e31337..122cdedc3 100644--- a/src/components/notes/SpacesTree.tsx+++ b/src/components/notes/SpacesTree.tsx@@ -1126,10 +1126,12 @@ export default function SpacesTree({: false;const teamSpaces = useMemo(() => spaces.filter((s) => s.kind === "team"), [spaces]);const showWorkspaceGroups = workspaces.length > 1;- const { groups: teamSpaceGroups, ungrouped: ungroupedTeamSpaces } = useMemo(- () => groupTeamSpacesByWorkspace(workspaces, teamSpaces),- [teamSpaces, workspaces]- );+ const {+ groups: teamSpaceGroups,+ ungrouped: ungroupedTeamSpaces,+ ordered: groupedTeamSpaces,+ } = useMemo(() => groupTeamSpacesByWorkspace(workspaces, teamSpaces), [teamSpaces, workspaces]);+ const orderedTeamSpaces = showWorkspaceGroups ? groupedTeamSpaces : teamSpaces;const visibleSpaces = teamCapability ? spaces : privateSpaces;const spacesById = useMemo(() => new Map(spaces.map((space) => [space.id, space])), [spaces]);// Valid move destinations per source space (the source itself stays listed —@@ -1389,9 +1391,9 @@ export default function SpacesTree({});};privateSpaces.forEach(pushPrivateSpace);- if (teamCapability) teamSpaces.forEach(pushSpace);+ if (teamCapability) orderedTeamSpaces.forEach(pushSpace);return rows;- }, [privateSpaces, teamSpaces, folders, notesByContainer, expanded, teamCapability]);+ }, [privateSpaces, orderedTeamSpaces, folders, notesByContainer, expanded, teamCapability]);const effectiveFocusKey =focusedKey && visibleRows.some((r) => r.key === focusedKey)diff --git a/src/helpers/database.js b/src/helpers/database.jsindex a69bf2e50..9166551f8 100644--- a/src/helpers/database.js+++ b/src/helpers/database.js@@ -4055,9 +4055,12 @@ class DatabaseManager {getPendingConversations() {try {if (!this.db) throw new Error("Database not initialized");+ // The cloud conversation contract has no space/folder scope yet.+ // Keep container chats local so another device cannot pull them as+ // global chats. Cloud-backed tombstones still use the delete queue.return this.db.prepare(- "SELECT * FROM agent_conversations WHERE sync_status = 'pending' AND deleted_at IS NULL"+ "SELECT * FROM agent_conversations WHERE sync_status = 'pending' AND deleted_at IS NULL AND space_id IS NULL AND folder_id IS NULL").all();} catch (error) {diff --git a/src/hooks/useTeamRoster.ts b/src/hooks/useTeamRoster.tsindex 51bee418c..85d1c8664 100644--- a/src/hooks/useTeamRoster.ts+++ b/src/hooks/useTeamRoster.ts@@ -1,23 +1,25 @@-import { useEffect, useState } from "react";+import { useCallback, useEffect, useState, useSyncExternalStore } from "react";import { SpacesService } from "../services/SpacesService";+import {+ fetchCachedSpaceRoster,+ readSpaceRosterVersion,+ subscribeSpaceRoster,+} from "../lib/spaceRosterCache";import type { TeamMember } from "../types/electron";-// Union rosters cached per cloud space so repeated lookups (conflict-// attribution, note authorship) don't refetch.-const rosterCache = new Map<string, Promise<TeamMember[]>>();-export function fetchSpaceRoster(cloudSpaceId: string): Promise<TeamMember[]> {- let roster = rosterCache.get(cloudSpaceId);- if (!roster) {- roster = SpacesService.listMembers(cloudSpaceId);- roster.catch(() => rosterCache.delete(cloudSpaceId));- rosterCache.set(cloudSpaceId, roster);- }- return roster;+ return fetchCachedSpaceRoster(cloudSpaceId, () => SpacesService.listMembers(cloudSpaceId));}export function useSpaceRoster(cloudSpaceId: string | null): Map<string, TeamMember> | null {const [membersById, setMembersById] = useState<Map<string, TeamMember> | null>(null);+ const subscribe = useCallback(+ (listener: () => void) =>+ cloudSpaceId ? subscribeSpaceRoster(cloudSpaceId, listener) : () => {},+ [cloudSpaceId]+ );+ const getVersion = useCallback(() => readSpaceRosterVersion(cloudSpaceId), [cloudSpaceId]);+ const version = useSyncExternalStore(subscribe, getVersion, getVersion);useEffect(() => {if (!cloudSpaceId) {@@ -35,7 +37,7 @@ export function useSpaceRoster(cloudSpaceId: string | null): Map<string, TeamMemreturn () => {stale = true;};- }, [cloudSpaceId]);+ }, [cloudSpaceId, version]);return membersById;}diff --git a/src/lib/spaceRosterCache.ts b/src/lib/spaceRosterCache.tsnew file mode 100644index 000000000..a72da0466--- /dev/null+++ b/src/lib/spaceRosterCache.ts@@ -0,0 +1,43 @@+const rosterCache = new Map<string, Promise<unknown>>();+const rosterVersions = new Map<string, number>();+const rosterListeners = new Map<string, Set<() => void>>();++export function fetchCachedSpaceRoster<T>(+ cloudSpaceId: string,+ loader: () => Promise<T>+): Promise<T> {+ let roster = rosterCache.get(cloudSpaceId) as Promise<T> | undefined;+ if (!roster) {+ roster = loader();+ roster.catch(() => {+ if (rosterCache.get(cloudSpaceId) === roster) rosterCache.delete(cloudSpaceId);+ });+ rosterCache.set(cloudSpaceId, roster);+ }+ return roster;+}++export function subscribeSpaceRoster(cloudSpaceId: string, listener: () => void): () => void {+ const listeners = rosterListeners.get(cloudSpaceId) ?? new Set<() => void>();+ listeners.add(listener);+ rosterListeners.set(cloudSpaceId, listeners);+ return () => {+ listeners.delete(listener);+ if (listeners.size === 0) rosterListeners.delete(cloudSpaceId);+ };+}++export function readSpaceRosterVersion(cloudSpaceId: string | null): number {+ return cloudSpaceId ? (rosterVersions.get(cloudSpaceId) ?? 0) : 0;+}++export function invalidateSpaceRoster(cloudSpaceId?: string): void {+ const ids = cloudSpaceId+ ? [cloudSpaceId]+ : [...new Set([...rosterCache.keys(), ...rosterListeners.keys()])];+ for (const id of ids) {+ rosterCache.delete(id);+ rosterVersions.set(id, (rosterVersions.get(id) ?? 0) + 1);+ for (const listener of [...(rosterListeners.get(id) ?? [])]) listener();+ }+}diff --git a/src/lib/workspaceSelection.ts b/src/lib/workspaceSelection.tsindex 588dfa3eb..e686971b6 100644--- a/src/lib/workspaceSelection.ts+++ b/src/lib/workspaceSelection.ts@@ -12,7 +12,7 @@ export interface TeamSpaceGroup<S> {export function groupTeamSpacesByWorkspace<S extends { workspace_id?: string | null }>(workspaces: Workspace[],teamSpaces: S[]-): { groups: TeamSpaceGroup<S>[]; ungrouped: S[] } {+): { groups: TeamSpaceGroup<S>[]; ungrouped: S[]; ordered: S[] } {const groups = workspaces.map((workspace) => ({workspace,@@ -30,7 +30,10 @@ export function groupTeamSpacesByWorkspace<S extends { workspace_id?: string | nconst ungrouped = teamSpaces.filter((space) => space.workspace_id == null || !workspaceIds.has(space.workspace_id));- return { groups, ungrouped };+ // Canonical visual order used by both rendering and keyboard navigation:+ // workspace order first, then legacy/unrecognized spaces.+ const ordered = [...groups.flatMap((group) => group.spaces), ...ungrouped];+ return { groups, ungrouped, ordered };}export function selectWorkspaceForSpaceCreation(diff --git a/src/services/spaceActions.ts b/src/services/spaceActions.tsindex 09a06d413..e745f2376 100644--- a/src/services/spaceActions.ts+++ b/src/services/spaceActions.ts@@ -2,6 +2,7 @@ import { TeamsService } from "./TeamsService";import { SpacesService } from "./SpacesService";import { markSpacePurged, syncService, upsertCloudSpaces } from "./SyncService";import { loadSpaces, purgeSpace, updateSpaceMeta } from "../stores/noteStore";+import { invalidateSpaceRoster } from "../lib/spaceRosterCache";import type { SpaceItem, TeamRole } from "../types/electron";// Single mutation path for spaces and their assigned teams: server call → local@@ -29,6 +30,10 @@ async function settleAddMembers(teamId: string, userIds: string[]): Promise<unkn}async function refreshSpaceMirror(): Promise<void> {+ // Team membership and assignments affect the deduplicated union roster for+ // every space that team reaches. Invalidate before the mirror fetch so a+ // failed refresh cannot leave stale member attribution cached indefinitely.+ invalidateSpaceRoster();await upsertCloudSpaces(await SpacesService.mySpaces());await loadSpaces();}@@ -117,6 +122,7 @@ export async function deleteSpace(space: SpaceItem): Promise<{ success: boolean;} catch (err) {return { success: false, error: errorMessage(err) };}+ invalidateSpaceRoster(space.cloud_space_id);// Park the space id so an in-flight pull can't resurrect purged rows.await markSpacePurged(space.cloud_space_id, "deleted");}diff --git a/test/helpers/containerConversationsDatabase.test.js b/test/helpers/containerConversationsDatabase.test.jsindex 28f0b52c5..b6c1bf260 100644--- a/test/helpers/containerConversationsDatabase.test.js+++ b/test/helpers/containerConversationsDatabase.test.js@@ -102,6 +102,24 @@ test("createAgentConversation stores container scope", (t) => {assert.equal(globalConv.note_id, null);});+test("getPendingConversations excludes scopes the cloud contract cannot preserve", (t) => {+ const db = createDb(t);+ if (!db) return;+ const space = db.createSpace({ name: "Eng" }).space;+ const folder = db.createFolder("Docs", space.id).folder;++ const global = db.createAgentConversation("Global");+ const noteScoped = db.createAgentConversation("Note chat", 123);+ db.createAgentConversation("Space chat", null, space.id);+ db.createAgentConversation("Folder chat", null, space.id, folder.id);++ assert.deepEqual(+ db.getPendingConversations().map((conversation) => conversation.id),+ [global.id, noteScoped.id],+ "space/folder chats must remain local until the cloud API carries their scope"+ );+});+test("getConversationsForContainer separates folder and space-root scopes", (t) => {const db = createDb(t);if (!db) return;diff --git a/test/lib/workspaceSelection.test.js b/test/lib/workspaceSelection.test.jsindex ff0c22565..656928dd5 100644--- a/test/lib/workspaceSelection.test.js+++ b/test/lib/workspaceSelection.test.js@@ -54,6 +54,23 @@ test("groupTeamSpacesByWorkspace: spaces without a known workspace are ungrouped);});+test("groupTeamSpacesByWorkspace: ordered matches grouped render order", () => {+ const workspaces = [workspace("a", "owner"), workspace("b", "member")];+ const spaces = [+ space(1, "b"),+ space(2, "a"),+ space(3, "missing"),+ space(4, "b"),+ space(5, "a"),+ space(6, null),+ ];+ const { ordered } = groupTeamSpacesByWorkspace(workspaces, spaces);+ assert.deepEqual(+ ordered.map((entry) => entry.id),+ [2, 5, 1, 4, 3, 6]+ );+});+test("selectWorkspaceForSpaceCreation: preselected id wins when manageable", () => {const manageable = [workspace("a", "owner"), workspace("b", "admin")];assert.equal(selectWorkspaceForSpaceCreation(manageable, null, "b")?.id, "b");diff --git a/test/services/teamRosterCache.test.js b/test/services/teamRosterCache.test.jsnew file mode 100644index 000000000..a2caafe01--- /dev/null+++ b/test/services/teamRosterCache.test.js@@ -0,0 +1,36 @@+const test = require("node:test");+const assert = require("node:assert/strict");++test("space roster invalidation evicts cached successful fetches", async (t) => {+ const {+ fetchCachedSpaceRoster,+ invalidateSpaceRoster,+ readSpaceRosterVersion,+ subscribeSpaceRoster,+ } = await import("../../src/lib/spaceRosterCache.ts");+ let calls = 0;+ const load = async () => {+ calls += 1;+ return [{ user_id: `user-${calls}` }];+ };+ t.after(() => invalidateSpaceRoster());++ const first = await fetchCachedSpaceRoster("space-1", load);+ const cached = await fetchCachedSpaceRoster("space-1", load);+ assert.equal(calls, 1);+ assert.deepEqual(cached, first);++ let notifications = 0;+ const version = readSpaceRosterVersion("space-1");+ const unsubscribe = subscribeSpaceRoster("space-1", () => {+ notifications += 1;+ });+ t.after(unsubscribe);+ invalidateSpaceRoster("space-1");+ assert.equal(notifications, 1, "mounted consumers are notified");+ assert.equal(readSpaceRosterVersion("space-1"), version + 1);++ const refreshed = await fetchCachedSpaceRoster("space-1", load);+ assert.equal(calls, 2);+ assert.notDeepEqual(refreshed, first);+});diff --git a/test/utils/dateGrouping.test.js b/test/utils/dateGrouping.test.jsindex 3fed1de95..1f9be818c 100644--- a/test/utils/dateGrouping.test.js+++ b/test/utils/dateGrouping.test.js@@ -14,10 +14,13 @@ const t = (key) =>"chat.older": "Older",})[key] || key;-// Local-time constructors keep these assertions timezone-independent.const NOON_JUNE_15 = new Date(2024, 5, 15, 12, 0, 0).getTime();-function localDbDate(year, month, day, hour) {+function localIsoDate(year, month, day, hour) {+ return new Date(year, month, day, hour).toISOString();+}++function utcDbDate(year, month, day, hour) {// normalizeDbDate treats zoneless SQLite timestamps as UTC, so emit UTC.return new Date(Date.UTC(year, month, day, hour)).toISOString().replace("T", " ").slice(0, 19);}@@ -27,11 +30,11 @@ test("groups newest-first items into calendar buckets in order", async (t2) => {t2.mock.timers.enable({ apis: ["Date"], now: NOON_JUNE_15 });const items = [- { id: 1, updated_at: "2024-06-15T10:00:00Z" },- { id: 2, updated_at: "2024-06-15T08:00:00Z" },- { id: 3, updated_at: "2024-06-14T22:00:00Z" },- { id: 4, updated_at: "2024-06-10T12:00:00Z" },- { id: 5, updated_at: "2024-01-01T12:00:00Z" },+ { id: 1, updated_at: localIsoDate(2024, 5, 15, 10) },+ { id: 2, updated_at: localIsoDate(2024, 5, 15, 8) },+ { id: 3, updated_at: localIsoDate(2024, 5, 14, 22) },+ { id: 4, updated_at: localIsoDate(2024, 5, 10, 12) },+ { id: 5, updated_at: localIsoDate(2024, 0, 1, 12) },];const groups = groupItemsByDate(items, (i) => i.updated_at, t);@@ -51,8 +54,8 @@ test("boundary days land in the nearest bucket", async (t2) => {const items = [// Exactly 7 days back is still "Previous 7 days"; 8 days back is "Older".- { id: 1, updated_at: localDbDate(2024, 5, 8, 12) },- { id: 2, updated_at: localDbDate(2024, 5, 7, 12) },+ { id: 1, updated_at: localIsoDate(2024, 5, 8, 12) },+ { id: 2, updated_at: localIsoDate(2024, 5, 7, 12) },];const groups = groupItemsByDate(items, (i) => i.updated_at, t);assert.deepEqual(@@ -71,7 +74,7 @@ test("SQLite zoneless timestamps are grouped like their UTC instant", async (t2)t2.mock.timers.enable({ apis: ["Date"], now: NOON_JUNE_15 });const utcNow = new Date();- const todayDb = localDbDate(+ const todayDb = utcDbDate(utcNow.getUTCFullYear(),utcNow.getUTCMonth(),utcNow.getUTCDate(),