mirror of https://github.com/msgbyte/tailchat
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
import { ChatConverseInfo, fetchConverseInfo } from '../model/converse';
|
|
import { findGroupInviteByCode, GroupInvite } from '../model/group';
|
|
import {
|
|
fetchLocalStaticRegistryPlugins,
|
|
fetchRegistryPlugins,
|
|
fetchServiceRegistryPlugins,
|
|
PluginManifest,
|
|
} from '../model/plugin';
|
|
import { fetchUserInfo, UserBaseInfo } from '../model/user';
|
|
import { parseUrlStr } from '../utils/url-helper';
|
|
import { queryClient } from './index';
|
|
|
|
/**
|
|
* 获取缓存的用户信息
|
|
*/
|
|
export async function getCachedUserInfo(
|
|
userId: string,
|
|
refetch = false
|
|
): Promise<UserBaseInfo> {
|
|
const data = await queryClient.fetchQuery(
|
|
['user', userId],
|
|
() => fetchUserInfo(userId),
|
|
{
|
|
staleTime: refetch ? 0 : 2 * 60 * 60 * 1000, // 缓存2小时
|
|
}
|
|
);
|
|
|
|
return data;
|
|
}
|
|
|
|
/**
|
|
* 获取缓存的会话信息
|
|
*/
|
|
export async function getCachedConverseInfo(
|
|
converseId: string
|
|
): Promise<ChatConverseInfo> {
|
|
const data = await queryClient.fetchQuery(['converse', converseId], () =>
|
|
fetchConverseInfo(converseId)
|
|
);
|
|
|
|
return data;
|
|
}
|
|
|
|
/**
|
|
* 获取缓存的邀请码信息
|
|
*/
|
|
export async function getCachedGroupInviteInfo(
|
|
inviteCode: string
|
|
): Promise<GroupInvite | null> {
|
|
const data = await queryClient.fetchQuery(['groupInvite', inviteCode], () =>
|
|
findGroupInviteByCode(inviteCode)
|
|
);
|
|
|
|
return data;
|
|
}
|
|
|
|
/**
|
|
* 获取缓存的插件列表
|
|
*/
|
|
export async function getCachedRegistryPlugins(): Promise<PluginManifest[]> {
|
|
const data = await queryClient.fetchQuery(
|
|
['pluginRegistry'],
|
|
() =>
|
|
Promise.all([
|
|
fetchRegistryPlugins().catch(() => []),
|
|
fetchServiceRegistryPlugins()
|
|
.then((list) =>
|
|
list.map((manifest) => ({
|
|
...manifest,
|
|
// 后端url策略。根据前端的url在获取时自动变更为当前链接的后端地址
|
|
url: parseUrlStr(manifest.url),
|
|
}))
|
|
)
|
|
.catch(() => []),
|
|
fetchLocalStaticRegistryPlugins().catch(() => []),
|
|
]).then(([a, b, c]) => [...a, ...b, ...c]),
|
|
{
|
|
staleTime: 2 * 60 * 60 * 1000, // 缓存2小时
|
|
}
|
|
);
|
|
|
|
return data;
|
|
}
|