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.3 KB
Raw Blame
import { throwOnErr } from '@core/util/result';
import {
  type ApiChannelParticipant,
  storageServiceClient,
} from '@service-storage/client';
import { useQuery } from '@tanstack/solid-query';
import type { Accessor } from 'solid-js';
import { queryClient } from '../client';
import { channelKeys } from './keys';

export function channelParticipantsQueryOptions(channelId: string) {
  return {
    queryKey: channelKeys.participants(channelId).queryKey,
    queryFn: async (): Promise<ApiChannelParticipant[]> => {
      return await throwOnErr(
        async () =>
          await storageServiceClient.getChannelParticipants({
            channel_id: channelId,
          })
      );
    },
    staleTime: Infinity,
  };
}

export function useChannelParticipantsQuery(channelId: Accessor<string>) {
  return useQuery(() => ({
    ...channelParticipantsQueryOptions(channelId()),
    enabled: !!channelId(),
  }));
}

export function invalidateChannelParticipants(channelId: string) {
  return queryClient.invalidateQueries({
    queryKey: channelKeys.participants(channelId).queryKey,
  });
}

export function softInvalidateChannelParticipants(channelId: string) {
  return queryClient.invalidateQueries({
    queryKey: channelKeys.participants(channelId).queryKey,
    refetchType: 'inactive',
  });
}