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.

chore: deprecate channels entity query (#1333)

gbirman5638a4ee0640
diff --git a/js/app/packages/app/component/Soup.tsx b/js/app/packages/app/component/Soup.tsx
index 27584d0076..5aec7aaa49 100644
--- a/js/app/packages/app/component/Soup.tsx
+++ b/js/app/packages/app/component/Soup.tsx
@@ -680,9 +680,6 @@ export function Soup() {
notificationSource,
'channel',
(notification) => {
- entityQueryClient.invalidateQueries({
- queryKey: queryKeys.all.channel,
- });
entityQueryClient.invalidateQueries({
queryKey: queryKeys.all.dss,
});
diff --git a/js/app/packages/block-channel/definition.ts b/js/app/packages/block-channel/definition.ts
index 2a54b7f2e4..31259637ce 100644
--- a/js/app/packages/block-channel/definition.ts
+++ b/js/app/packages/block-channel/definition.ts
@@ -1,9 +1,6 @@
import { defineBlock, type ExtractLoadType, LoadErrors } from '@core/block';
import { isErr, ok } from '@core/util/maybeResult';
-import {
- fetchAndCacheChannel,
- optimisticUpdateChannelViewedAt,
-} from '@queries/channel/channel';
+import { fetchAndCacheChannel } from '@queries/channel/channel';
import ChannelBlock from './component/Block';
export const definition = defineBlock({
@@ -29,8 +26,6 @@ export const definition = defineBlock({
const [, channelData] = channel;
- optimisticUpdateChannelViewedAt(source.id);
-
return ok({
...channelData.channel,
});
diff --git a/js/app/packages/core/internal/trackBlockOpened.ts b/js/app/packages/core/internal/trackBlockOpened.ts
index d2c27bae5a..540d9e1d60 100644
--- a/js/app/packages/core/internal/trackBlockOpened.ts
+++ b/js/app/packages/core/internal/trackBlockOpened.ts
@@ -18,6 +18,8 @@ export function track(
) {
const itemType = blockNameToItemType(blockName);
+ // TODO: we can also optimistically update viewed at on dss query
+
if (!isCloudStorageItem(itemType)) return;
const upsertToHistoryMutation = useUpsertToHistoryMutation(undefined, client);
diff --git a/js/app/packages/macro-entity/src/index.tsx b/js/app/packages/macro-entity/src/index.tsx
index 50d6a3fa66..200fd20789 100644
--- a/js/app/packages/macro-entity/src/index.tsx
+++ b/js/app/packages/macro-entity/src/index.tsx
@@ -11,7 +11,6 @@ export {
} from './components/UnifiedList';
export { UnreadIndicator } from './components/Unread';
export * from './contexts/soup';
-export { createChannelsQuery } from './queries/channel';
export { useQueryClient } from './queries/client';
export {
createChatsInfiniteQuery,
diff --git a/js/app/packages/macro-entity/src/queries/channel.ts b/js/app/packages/macro-entity/src/queries/channel.ts
deleted file mode 100644
index d75cc17813..0000000000
--- a/js/app/packages/macro-entity/src/queries/channel.ts
+++ /dev/null
@@ -1,69 +0,0 @@
-import type { ApiChannelWithLatest } from '@service-comms/generated/models';
-import { useQuery } from '@tanstack/solid-query';
-import { SERVER_HOSTS } from 'core/constant/servers';
-import { platformFetch } from 'core/util/platformFetch';
-import type { Accessor } from 'solid-js';
-import type { ChannelEntity } from '../types/entity';
-import {
- createApiTokenQuery,
- handleFetchResponse,
- withApiTokenRetry,
-} from './auth';
-import { queryKeys } from './key';
-
-const fetchChannels = async ({ apiToken }: { apiToken?: string }) => {
- if (!apiToken) throw new Error('No API token provided');
- const Authorization = `Bearer ${apiToken}`;
-
- const response = await platformFetch(
- `${SERVER_HOSTS['document-storage-service']}/comms/channels`,
- {
- headers: { Authorization },
- }
- );
-
- await handleFetchResponse(response, 'Failed to fetch channels');
-
- const channels: ApiChannelWithLatest[] = await response.json();
- return channels;
-};
-
-export function createChannelsQuery(options?: {
- disabled?: Accessor<boolean>;
-}) {
- const authQuery = createApiTokenQuery();
- return useQuery(() => ({
- queryKey: queryKeys.all.channel,
- queryFn: () =>
- withApiTokenRetry(authQuery, (apiToken) => fetchChannels({ apiToken })),
- select: (data) =>
- data.map(
- (channel): ChannelEntity => ({
- type: 'channel',
- id: channel.id,
- name: channel.name ?? 'Unknown Channel',
- channelType: channel.channel_type,
- ownerId: channel.owner_id,
- frecencyScore: channel.frecency_score ?? 0,
- createdAt: Date.parse(channel.created_at),
- updatedAt: Date.parse(channel.updated_at),
- participantIds: channel.participants.map((p) => p.user_id),
- viewedAt: channel.viewed_at
- ? Date.parse(channel.viewed_at)
- : channel.interacted_at
- ? Date.parse(channel.interacted_at)
- : undefined,
- latestMessage: channel.latest_non_thread_message
- ? {
- content: channel.latest_non_thread_message.content,
- senderId: channel.latest_non_thread_message.sender_id,
- createdAt: Date.parse(
- channel.latest_non_thread_message.created_at
- ),
- }
- : undefined,
- })
- ),
- enabled: authQuery.isSuccess && !options?.disabled?.(),
- }));
-}
diff --git a/js/app/packages/macro-entity/src/queries/key.ts b/js/app/packages/macro-entity/src/queries/key.ts
index 8b7af949ed..846749f876 100644
--- a/js/app/packages/macro-entity/src/queries/key.ts
+++ b/js/app/packages/macro-entity/src/queries/key.ts
@@ -7,7 +7,6 @@ const BASE_AUTH = ['auth'];
const ENTITY = 'entity';
const BASE_ENTITY = {
entity: [ENTITY],
- channel: [ENTITY, 'channel'],
dss: [ENTITY, 'dss'],
email: [ENTITY, 'email'],
search: [ENTITY, 'search'],
@@ -44,7 +43,6 @@ export const queryKeys = {
{ ...args },
],
},
- channel: (args: KeyOptions) => [...BASE_ENTITY.channel, { ...args }],
chat: (args?: InfiniteKeyOptions) => [
...BASE_ENTITY.dss,
{ type: 'chat', ...args },
diff --git a/js/app/packages/macro-entity/src/queries/rename.ts b/js/app/packages/macro-entity/src/queries/rename.ts
index effc671e6b..a0590468ba 100644
--- a/js/app/packages/macro-entity/src/queries/rename.ts
+++ b/js/app/packages/macro-entity/src/queries/rename.ts
@@ -249,7 +249,8 @@ const bulkRenameOnSettled = (
toast.failure('Failed to rename');
if (!onMutateResult) {
- // TODO: refetch everything since we don't have rollback data
+ // most likely nothing to rollback, but it's possible there were mutations that succeeded before the OnMutate failed
+ // TODO: refetch everything to be safe
return;
}
diff --git a/js/app/packages/queries/channel/channel.ts b/js/app/packages/queries/channel/channel.ts
index 7e5ad0823c..ff26b300df 100644
--- a/js/app/packages/queries/channel/channel.ts
+++ b/js/app/packages/queries/channel/channel.ts
@@ -5,7 +5,6 @@ import {
ok,
throwOnErr,
} from '@core/util/maybeResult';
-import { queryKeys } from '@macro-entity';
import { commsServiceClient } from '@service-comms/client';
import type { getChannelResponseError } from '@service-comms/generated/client';
import type {
@@ -177,17 +176,3 @@ export function softInvalidateChannelWithID(channelID: string) {
refetchType: 'inactive',
});
}
-
-export function optimisticUpdateChannelViewedAt(channelId: string) {
- const now = new Date().toISOString();
-
- queryClient.setQueryData<ApiChannelWithLatest[]>(
- queryKeys.all.channel,
- (old) => {
- if (!old) return old;
- return old.map((channel) =>
- channel.id === channelId ? { ...channel, viewed_at: now } : channel
- );
- }
- );
-}