Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

feat(desktop): note sharing state + service

Gabriel Stein0b21148b5273
diff --git a/src/services/NoteSharingService.ts b/src/services/NoteSharingService.ts
new file mode 100644
index 000000000..6a4eb3f1e
--- /dev/null
+++ b/src/services/NoteSharingService.ts
@@ -0,0 +1,88 @@
+import { cloudGet, cloudPost, cloudPatch, cloudDelete } from "./cloudApi.js";
+import type {
+ NoteShareInvitation,
+ ShareSettings,
+ ShareVisibility,
+} from "../types/electron";
+
+export interface ShareStateResponse {
+ share: ShareSettings;
+ invitations: NoteShareInvitation[];
+}
+
+export interface ShareMutationResponse {
+ share: ShareSettings;
+ raw_token: string | null;
+}
+
+export interface RotateTokenResponse {
+ share: ShareSettings;
+ raw_token: string;
+}
+
+export interface CreateInvitationsResponse {
+ created: NoteShareInvitation[];
+ already_invited: string[];
+ email_failed_ids: string[];
+}
+
+function sharePath(cloudId: string, suffix: string = ""): string {
+ return `/api/notes/${encodeURIComponent(cloudId)}/share${suffix}`;
+}
+
+async function getShareSettings(cloudNoteId: string): Promise<ShareStateResponse> {
+ return cloudGet<ShareStateResponse>(sharePath(cloudNoteId));
+}
+
+async function updateShareSettings(
+ cloudNoteId: string,
+ visibility: ShareVisibility,
+ domainAllowlist: string[]
+): Promise<ShareMutationResponse> {
+ return cloudPatch<ShareMutationResponse>(sharePath(cloudNoteId), {
+ visibility,
+ domain_allowlist: domainAllowlist,
+ });
+}
+
+async function clearShare(cloudNoteId: string): Promise<{ share: ShareSettings }> {
+ return cloudDelete<{ share: ShareSettings }>(sharePath(cloudNoteId));
+}
+
+async function rotateToken(cloudNoteId: string): Promise<RotateTokenResponse> {
+ return cloudPost<RotateTokenResponse>(sharePath(cloudNoteId, "/rotate-token"));
+}
+
+async function inviteEmails(
+ cloudNoteId: string,
+ emails: string[]
+): Promise<CreateInvitationsResponse> {
+ return cloudPost<CreateInvitationsResponse>(sharePath(cloudNoteId, "/invitations"), {
+ emails,
+ });
+}
+
+async function revokeInvite(cloudNoteId: string, invitationId: string): Promise<void> {
+ await cloudDelete(
+ sharePath(cloudNoteId, `/invitations/${encodeURIComponent(invitationId)}`)
+ );
+}
+
+async function resendInvite(
+ cloudNoteId: string,
+ invitationId: string
+): Promise<{ id: string; resent: boolean }> {
+ return cloudPost<{ id: string; resent: boolean }>(
+ sharePath(cloudNoteId, `/invitations/${encodeURIComponent(invitationId)}/resend`)
+ );
+}
+
+export const NoteSharingService = {
+ getShareSettings,
+ updateShareSettings,
+ clearShare,
+ rotateToken,
+ inviteEmails,
+ revokeInvite,
+ resendInvite,
+};
diff --git a/src/stores/noteStore.ts b/src/stores/noteStore.ts
index b146a2673..ecab6c8b4 100644
--- a/src/stores/noteStore.ts
+++ b/src/stores/noteStore.ts
@@ -1,11 +1,20 @@
import { create } from "zustand";
-import type { NoteItem } from "../types/electron";
+import type { NoteItem, NoteShareInvitation, ShareSettings } from "../types/electron";
+
+export interface NoteShareCacheEntry {
+ share: ShareSettings;
+ invitations: NoteShareInvitation[];
+ // Raw token is returned by the API exactly once (on generate or rotate)
+ // and is only kept in memory for the active dialog session.
+ rawToken: string | null;
+}
interface NoteState {
notes: NoteItem[];
activeNoteId: number | null;
activeFolderId: number | null;
migration: { total: number; done: number } | null;
+ shareByCloudId: Map<string, NoteShareCacheEntry>;
}
const useNoteStore = create<NoteState>()(() => ({
@@ -13,6 +22,7 @@ const useNoteStore = create<NoteState>()(() => ({
activeNoteId: null,
activeFolderId: null,
migration: null,
+ shareByCloudId: new Map<string, NoteShareCacheEntry>(),
}));
let hasBoundIpcListeners = false;
@@ -194,3 +204,34 @@ export async function startMigration(): Promise<void> {
useNoteStore.setState({ migration: null });
}
+
+export function setShareCache(cloudId: string, entry: NoteShareCacheEntry): void {
+ const { shareByCloudId } = useNoteStore.getState();
+ const next = new Map(shareByCloudId);
+ next.set(cloudId, entry);
+ useNoteStore.setState({ shareByCloudId: next });
+}
+
+export function updateShareCache(
+ cloudId: string,
+ updater: (current: NoteShareCacheEntry | undefined) => NoteShareCacheEntry
+): void {
+ const { shareByCloudId } = useNoteStore.getState();
+ const next = new Map(shareByCloudId);
+ next.set(cloudId, updater(next.get(cloudId)));
+ useNoteStore.setState({ shareByCloudId: next });
+}
+
+export function clearShareCache(cloudId: string): void {
+ const { shareByCloudId } = useNoteStore.getState();
+ if (!shareByCloudId.has(cloudId)) return;
+ const next = new Map(shareByCloudId);
+ next.delete(cloudId);
+ useNoteStore.setState({ shareByCloudId: next });
+}
+
+export function useShareCacheEntry(cloudId: string | null): NoteShareCacheEntry | null {
+ return useNoteStore((state) =>
+ cloudId ? state.shareByCloudId.get(cloudId) ?? null : null
+ );
+}
diff --git a/src/types/electron.ts b/src/types/electron.ts
index 579de1dff..ff6c6495f 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -64,6 +64,26 @@ export interface NoteItem {
team_id?: string | null;
}
+export type ShareVisibility = "private" | "link" | "domain" | "invited";
+
+export interface ShareSettings {
+ visibility: ShareVisibility;
+ token_prefix: string | null;
+ domain_allowlist: string[];
+ updated_by_user_id: string | null;
+ updated_at: string | null;
+}
+
+export interface NoteShareInvitation {
+ id: string;
+ email: string;
+ invited_by_user_id: string;
+ accepted_at: string | null;
+ revoked_at: string | null;
+ last_emailed_at: string | null;
+ created_at: string;
+}
+
export interface FolderItem {
id: number;
name: string;
diff --git a/src/utils/personalEmailDomains.ts b/src/utils/personalEmailDomains.ts
new file mode 100644
index 000000000..daeb30ad3
--- /dev/null
+++ b/src/utils/personalEmailDomains.ts
@@ -0,0 +1,45 @@
+const PERSONAL_EMAIL_DOMAINS = new Set<string>([
+ "gmail.com",
+ "googlemail.com",
+ "outlook.com",
+ "hotmail.com",
+ "live.com",
+ "msn.com",
+ "yahoo.com",
+ "yahoo.co.uk",
+ "ymail.com",
+ "rocketmail.com",
+ "icloud.com",
+ "me.com",
+ "mac.com",
+ "proton.me",
+ "protonmail.com",
+ "pm.me",
+ "aol.com",
+ "fastmail.com",
+ "fastmail.fm",
+ "tutanota.com",
+ "tuta.io",
+ "gmx.com",
+ "gmx.de",
+ "gmx.net",
+ "mail.com",
+ "zoho.com",
+ "yandex.com",
+ "yandex.ru",
+ "duck.com",
+ "hey.com",
+ "qq.com",
+ "163.com",
+ "126.com",
+ "sina.com",
+]);
+
+export function emailDomain(email: string): string {
+ const at = email.indexOf("@");
+ return at === -1 ? "" : email.slice(at + 1).toLowerCase();
+}
+
+export function isPersonalEmailDomain(domain: string): boolean {
+ return PERSONAL_EMAIL_DOMAINS.has(domain.toLowerCase());
+}