Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(email): refetch soup threads on refresh_email backfill events (#4026)

gbirman1863c144aa62
diff --git a/js/app/packages/queries/email/sync.ts b/js/app/packages/queries/email/sync.ts
new file mode 100644
index 0000000000..c84a6a8c2a
--- /dev/null
+++ b/js/app/packages/queries/email/sync.ts
@@ -0,0 +1,23 @@
+import { invalidateAllSoup } from '@queries/soup/normalized-cache';
+import { leadingAndTrailing, throttle } from '@solid-primitives/scheduled';
+
+const BACKFILL_SOUP_REFRESH_INTERVAL = 5_000;
+
+const throttledBackfillSoupRefresh = leadingAndTrailing(
+ throttle,
+ invalidateAllSoup,
+ BACKFILL_SOUP_REFRESH_INTERVAL
+);
+
+/**
+ * Handles `refresh_email` websocket events. Only `backfill` events refetch
+ * here: steady-state mutations (`upsert_message`, `update_labels`,
+ * `delete_message`) already invalidate soup through the notification-driven
+ * path, and reacting to them again would double-refetch. Backfill produces no
+ * notifications, so this is its only refresh signal — throttled because the
+ * backend emits one event per batch of backfilled threads.
+ */
+export function handleRefreshEmail(eventType: unknown): void {
+ if (eventType !== 'backfill') return;
+ throttledBackfillSoupRefresh();
+}
diff --git a/js/app/packages/queries/sync/SyncProvider.tsx b/js/app/packages/queries/sync/SyncProvider.tsx
index 0bac61d30a..a0a01333f8 100644
--- a/js/app/packages/queries/sync/SyncProvider.tsx
+++ b/js/app/packages/queries/sync/SyncProvider.tsx
@@ -5,6 +5,7 @@ import {
} from '@queries/channel/sync';
import { handleCommsTyping } from '@queries/channel/typing';
import { invalidateContacts } from '@queries/contacts/contacts';
+import { handleRefreshEmail } from '@queries/email/sync';
import {
applyNotificationStatusUpdate,
notificationStatusUpdatePayloadSchema,
@@ -86,6 +87,9 @@ export function QuerySyncProvider(props: SyncProviderProps) {
}
applyNotificationStatusUpdate(result.data);
})
+ .with({ type: 'refresh_email' }, () => {
+ handleRefreshEmail(data.data);
+ })
.with({ type: 'task_duplicate_matches_updated' }, () => {
withParsedWebsocketPayload(
data.type,