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.

1.4 KB
Raw Blame
import {
  ChannelListSoupDocument,
  ChannelUnreadPresenceDocument,
  HomeUnreadPresenceDocument,
} from '@service-storage/graphql/generated/graphql';
import type { Client } from '@urql/core';
import { delegateChannelNotificationRefresh } from '../../channel/notification-refresh';
import { getActiveGraphqlSoupRevalidations } from './active-queries';

/** Filtered notification membership must be re-evaluated after status writes. */
export function getChannelListRevalidations(client?: Pick<Client, 'query'>) {
  return getActiveGraphqlSoupRevalidations(client).filter(
    (query) =>
      query.document === ChannelListSoupDocument ||
      query.document === ChannelUnreadPresenceDocument ||
      query.document === HomeUnreadPresenceDocument
  );
}

/** Refresh only mounted channel-list pages, never full notification history. */
export async function revalidateChannelLists(
  client: Pick<Client, 'query'>
): Promise<void> {
  await Promise.all(
    getChannelListRevalidations(client).map(async ({ document, variables }) => {
      try {
        if (delegateChannelNotificationRefresh(client, { document, variables }))
          return;
        const result = await client
          .query(document, variables, { requestPolicy: 'network-only' })
          .toPromise();
        if (result.error) throw result.error;
      } catch (error) {
        console.error('Failed to refresh channel unread state', error);
      }
    })
  );
}