mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-18 06:13:52 +02:00
refactor queryRequest
This commit is contained in:
@@ -2,7 +2,6 @@ import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
const mockRequest = vi.fn();
|
||||
const mockPatchAndRefetchActiveQuery = vi.fn(() => Promise.resolve());
|
||||
const mockFetchWithEntityPolicy = vi.fn();
|
||||
|
||||
const mockApplyCurrentUser = vi.fn((json) => ({ id: json.id || 'usr_me', ...json }));
|
||||
const mockApplyUser = vi.fn((json) => ({ ...json }));
|
||||
@@ -24,22 +23,12 @@ vi.mock('../../stores', () => ({
|
||||
}));
|
||||
|
||||
vi.mock('../../queries', () => ({
|
||||
entityQueryPolicies: {
|
||||
user: { staleTime: 20000, gcTime: 90000, retry: 1, refetchOnWindowFocus: false },
|
||||
avatar: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false },
|
||||
world: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false },
|
||||
worldCollection: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false },
|
||||
instance: { staleTime: 0, gcTime: 10000, retry: 0, refetchOnWindowFocus: false }
|
||||
},
|
||||
fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args),
|
||||
patchAndRefetchActiveQuery: (...args) =>
|
||||
mockPatchAndRefetchActiveQuery(...args),
|
||||
queryKeys: {
|
||||
user: (userId) => ['user', userId],
|
||||
avatar: (avatarId) => ['avatar', avatarId],
|
||||
world: (worldId) => ['world', worldId],
|
||||
worldsByUser: (params) => ['worlds', 'user', params.userId, params],
|
||||
instance: (worldId, instanceId) => ['instance', worldId, instanceId]
|
||||
world: (worldId) => ['world', worldId]
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -88,26 +77,4 @@ describe('entity mutation query sync', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('getCachedWorlds uses policy wrapper for world list data', async () => {
|
||||
mockFetchWithEntityPolicy.mockResolvedValue({
|
||||
data: {
|
||||
json: [{ id: 'wrld_1' }],
|
||||
params: { userId: 'usr_me', n: 50, offset: 0 }
|
||||
},
|
||||
cache: true
|
||||
});
|
||||
|
||||
const args = await worldRequest.getCachedWorlds({
|
||||
userId: 'usr_me',
|
||||
n: 50,
|
||||
offset: 0,
|
||||
sort: 'updated',
|
||||
order: 'descending',
|
||||
user: 'me',
|
||||
releaseStatus: 'all'
|
||||
});
|
||||
|
||||
expect(mockFetchWithEntityPolicy).toHaveBeenCalled();
|
||||
expect(args.cache).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
const mockRequest = vi.fn();
|
||||
const mockFetchWithEntityPolicy = vi.fn();
|
||||
const mockInvalidateQueries = vi.fn().mockResolvedValue();
|
||||
const mockHandleFavoriteAdd = vi.fn();
|
||||
const mockHandleFavoriteDelete = vi.fn();
|
||||
@@ -24,24 +23,8 @@ vi.mock('../../stores', () => ({
|
||||
}));
|
||||
|
||||
vi.mock('../../queries', () => ({
|
||||
entityQueryPolicies: {
|
||||
favoriteCollection: {
|
||||
staleTime: 60000,
|
||||
gcTime: 300000,
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false
|
||||
}
|
||||
},
|
||||
fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args),
|
||||
queryClient: {
|
||||
invalidateQueries: (...args) => mockInvalidateQueries(...args)
|
||||
},
|
||||
queryKeys: {
|
||||
favoriteLimits: () => ['favorite', 'limits'],
|
||||
favorites: (params) => ['favorite', 'items', params],
|
||||
favoriteGroups: (params) => ['favorite', 'groups', params],
|
||||
favoriteWorlds: (params) => ['favorite', 'worlds', params],
|
||||
favoriteAvatars: (params) => ['favorite', 'avatars', params]
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -52,21 +35,6 @@ describe('favorite query sync', () => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test('cached favorite reads go through fetchWithEntityPolicy', async () => {
|
||||
mockFetchWithEntityPolicy.mockResolvedValue({
|
||||
data: { json: [], params: { n: 300, offset: 0 } },
|
||||
cache: true
|
||||
});
|
||||
|
||||
const args = await favoriteRequest.getCachedFavorites({
|
||||
n: 300,
|
||||
offset: 0
|
||||
});
|
||||
|
||||
expect(mockFetchWithEntityPolicy).toHaveBeenCalled();
|
||||
expect(args.cache).toBe(true);
|
||||
});
|
||||
|
||||
test('favorite mutations invalidate active favorite queries', async () => {
|
||||
mockRequest.mockResolvedValue({ ok: true });
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
const mockRequest = vi.fn();
|
||||
const mockFetchWithEntityPolicy = vi.fn();
|
||||
const mockInvalidateQueries = vi.fn().mockResolvedValue();
|
||||
const mockApplyUser = vi.fn((json) => json);
|
||||
|
||||
@@ -16,20 +15,8 @@ vi.mock('../../stores/user', () => ({
|
||||
}));
|
||||
|
||||
vi.mock('../../queries', () => ({
|
||||
entityQueryPolicies: {
|
||||
friendList: {
|
||||
staleTime: 20000,
|
||||
gcTime: 90000,
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false
|
||||
}
|
||||
},
|
||||
fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args),
|
||||
queryClient: {
|
||||
invalidateQueries: (...args) => mockInvalidateQueries(...args)
|
||||
},
|
||||
queryKeys: {
|
||||
friends: (params) => ['friends', params]
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -40,22 +27,6 @@ describe('friend query sync', () => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test('getCachedFriends uses query policy wrapper', async () => {
|
||||
mockFetchWithEntityPolicy.mockResolvedValue({
|
||||
data: {
|
||||
json: [{ id: 'usr_1', displayName: 'A' }],
|
||||
params: { n: 50, offset: 0 }
|
||||
},
|
||||
cache: true
|
||||
});
|
||||
|
||||
const args = await friendRequest.getCachedFriends({ n: 50, offset: 0 });
|
||||
|
||||
expect(mockFetchWithEntityPolicy).toHaveBeenCalled();
|
||||
expect(args.cache).toBe(true);
|
||||
expect(args.json[0].id).toBe('usr_1');
|
||||
});
|
||||
|
||||
test('friend mutations invalidate active friends queries', async () => {
|
||||
mockRequest.mockResolvedValue({ ok: true });
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
const mockRequest = vi.fn();
|
||||
const mockFetchWithEntityPolicy = vi.fn();
|
||||
const mockInvalidateQueries = vi.fn().mockResolvedValue();
|
||||
const mockApplyGroup = vi.fn((json) => json);
|
||||
|
||||
@@ -19,32 +18,8 @@ vi.mock('../../stores', () => ({
|
||||
}));
|
||||
|
||||
vi.mock('../../queries', () => ({
|
||||
entityQueryPolicies: {
|
||||
group: {
|
||||
staleTime: 60000,
|
||||
gcTime: 300000,
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false
|
||||
},
|
||||
groupCollection: {
|
||||
staleTime: 60000,
|
||||
gcTime: 300000,
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false
|
||||
}
|
||||
},
|
||||
fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args),
|
||||
queryClient: {
|
||||
invalidateQueries: (...args) => mockInvalidateQueries(...args)
|
||||
},
|
||||
queryKeys: {
|
||||
group: (groupId, includeRoles) => ['group', groupId, Boolean(includeRoles)],
|
||||
groupPosts: (params) => ['group', params.groupId, 'posts', params],
|
||||
groupMember: (params) => ['group', params.groupId, 'member', params.userId],
|
||||
groupMembers: (params) => ['group', params.groupId, 'members', params],
|
||||
groupGallery: (params) => ['group', params.groupId, 'gallery', params.galleryId, params],
|
||||
groupCalendar: (groupId) => ['group', groupId, 'calendar'],
|
||||
groupCalendarEvent: (params) => ['group', params.groupId, 'calendarEvent', params.eventId]
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -55,29 +30,6 @@ describe('group query sync', () => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test('cached group resources use fetchWithEntityPolicy', async () => {
|
||||
mockFetchWithEntityPolicy.mockResolvedValue({
|
||||
data: { json: [], params: { groupId: 'grp_1', n: 100, offset: 0 } },
|
||||
cache: true
|
||||
});
|
||||
|
||||
const a = await groupRequest.getCachedGroupMembers({
|
||||
groupId: 'grp_1',
|
||||
n: 100,
|
||||
offset: 0,
|
||||
sort: 'joinedAt:desc'
|
||||
});
|
||||
const b = await groupRequest.getCachedGroupGallery({
|
||||
groupId: 'grp_1',
|
||||
galleryId: 'gal_1',
|
||||
n: 100,
|
||||
offset: 0
|
||||
});
|
||||
|
||||
expect(mockFetchWithEntityPolicy).toHaveBeenCalledTimes(2);
|
||||
expect(a.cache && b.cache).toBe(true);
|
||||
});
|
||||
|
||||
test('group mutations invalidate scoped active group queries', async () => {
|
||||
mockRequest.mockResolvedValue({ ok: true });
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
const mockRequest = vi.fn();
|
||||
const mockFetchWithEntityPolicy = vi.fn();
|
||||
const mockInvalidateQueries = vi.fn().mockResolvedValue();
|
||||
const mockRemoveQueries = vi.fn();
|
||||
|
||||
@@ -16,27 +15,6 @@ vi.mock('../../stores', () => ({
|
||||
}));
|
||||
|
||||
vi.mock('../../queries', () => ({
|
||||
entityQueryPolicies: {
|
||||
galleryCollection: {
|
||||
staleTime: 60000,
|
||||
gcTime: 300000,
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false
|
||||
},
|
||||
inventoryCollection: {
|
||||
staleTime: 20000,
|
||||
gcTime: 120000,
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false
|
||||
},
|
||||
fileObject: {
|
||||
staleTime: 60000,
|
||||
gcTime: 300000,
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false
|
||||
}
|
||||
},
|
||||
fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args),
|
||||
queryClient: {
|
||||
invalidateQueries: (...args) => mockInvalidateQueries(...args),
|
||||
removeQueries: (...args) => mockRemoveQueries(...args)
|
||||
@@ -51,7 +29,6 @@ vi.mock('../../queries', () => ({
|
||||
}
|
||||
}));
|
||||
|
||||
import inventoryRequest from '../inventory';
|
||||
import miscRequest from '../misc';
|
||||
import vrcPlusIconRequest from '../vrcPlusIcon';
|
||||
import vrcPlusImageRequest from '../vrcPlusImage';
|
||||
@@ -61,25 +38,6 @@ describe('media and inventory query sync', () => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test('cached media/inventory reads go through fetchWithEntityPolicy', async () => {
|
||||
mockFetchWithEntityPolicy.mockResolvedValue({
|
||||
data: { json: [], params: {} },
|
||||
cache: true
|
||||
});
|
||||
|
||||
const a = await vrcPlusIconRequest.getCachedFileList({ tag: 'icon', n: 100 });
|
||||
const b = await vrcPlusImageRequest.getCachedPrints({ n: 100 });
|
||||
const c = await inventoryRequest.getCachedInventoryItems({
|
||||
n: 100,
|
||||
offset: 0,
|
||||
order: 'newest'
|
||||
});
|
||||
const d = await miscRequest.getCachedFile({ fileId: 'file_1' });
|
||||
|
||||
expect(mockFetchWithEntityPolicy).toHaveBeenCalledTimes(4);
|
||||
expect(a.cache && b.cache && c.cache && d.cache).toBe(true);
|
||||
});
|
||||
|
||||
test('media mutations invalidate gallery queries and file delete removes file query', async () => {
|
||||
mockRequest.mockResolvedValue({ ok: true });
|
||||
|
||||
|
||||
174
src/api/__tests__/queryRequest.test.js
Normal file
174
src/api/__tests__/queryRequest.test.js
Normal file
@@ -0,0 +1,174 @@
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
const mockFetchWithEntityPolicy = vi.fn();
|
||||
const mockGetUser = vi.fn();
|
||||
const mockGetWorlds = vi.fn();
|
||||
const mockGetGroupCalendar = vi.fn();
|
||||
|
||||
vi.mock('../../queries', () => ({
|
||||
entityQueryPolicies: {
|
||||
user: { staleTime: 20000, gcTime: 90000, retry: 1, refetchOnWindowFocus: false },
|
||||
worldCollection: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false },
|
||||
groupCollection: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false },
|
||||
avatar: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false },
|
||||
world: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false },
|
||||
group: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false },
|
||||
friendList: { staleTime: 20000, gcTime: 90000, retry: 1, refetchOnWindowFocus: false },
|
||||
favoriteCollection: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false },
|
||||
galleryCollection: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false },
|
||||
inventoryCollection: { staleTime: 20000, gcTime: 120000, retry: 1, refetchOnWindowFocus: false },
|
||||
fileObject: { staleTime: 60000, gcTime: 300000, retry: 1, refetchOnWindowFocus: false }
|
||||
},
|
||||
fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args),
|
||||
queryKeys: {
|
||||
user: (userId) => ['user', userId],
|
||||
worldsByUser: (params) => ['worlds', 'user', params.userId, params],
|
||||
groupCalendar: (groupId) => ['group', groupId, 'calendar'],
|
||||
avatar: (avatarId) => ['avatar', avatarId],
|
||||
world: (worldId) => ['world', worldId],
|
||||
group: (groupId, includeRoles) => ['group', groupId, Boolean(includeRoles)],
|
||||
groupPosts: (params) => ['group', params.groupId, 'posts', params],
|
||||
groupMember: (params) => ['group', params.groupId, 'member', params.userId],
|
||||
groupMembers: (params) => ['group', params.groupId, 'members', params],
|
||||
groupGallery: (params) => ['group', params.groupId, 'gallery', params.galleryId, params],
|
||||
groupCalendarEvent: (params) => ['group', params.groupId, 'calendarEvent', params.eventId],
|
||||
friends: (params) => ['friends', params],
|
||||
favoriteLimits: () => ['favorite', 'limits'],
|
||||
favorites: (params) => ['favorite', 'items', params],
|
||||
favoriteGroups: (params) => ['favorite', 'groups', params],
|
||||
favoriteWorlds: (params) => ['favorite', 'worlds', params],
|
||||
favoriteAvatars: (params) => ['favorite', 'avatars', params],
|
||||
galleryFiles: (params) => ['gallery', 'files', params],
|
||||
prints: (params) => ['gallery', 'prints', params],
|
||||
print: (printId) => ['gallery', 'print', printId],
|
||||
userInventoryItem: (params) => ['inventory', 'item', params.userId, params.inventoryId],
|
||||
inventoryItems: (params) => ['inventory', 'items', params],
|
||||
file: (fileId) => ['file', fileId]
|
||||
}
|
||||
}));
|
||||
|
||||
vi.mock('../user', () => ({
|
||||
default: {
|
||||
getUser: (...args) => mockGetUser(...args)
|
||||
}
|
||||
}));
|
||||
|
||||
vi.mock('../world', () => ({
|
||||
default: {
|
||||
getWorlds: (...args) => mockGetWorlds(...args),
|
||||
getWorld: vi.fn()
|
||||
}
|
||||
}));
|
||||
|
||||
vi.mock('../group', () => ({
|
||||
default: {
|
||||
getGroupCalendar: (...args) => mockGetGroupCalendar(...args),
|
||||
getGroup: vi.fn(),
|
||||
getGroupPosts: vi.fn(),
|
||||
getGroupMember: vi.fn(),
|
||||
getGroupMembers: vi.fn(),
|
||||
getGroupGallery: vi.fn(),
|
||||
getGroupCalendarEvent: vi.fn()
|
||||
}
|
||||
}));
|
||||
|
||||
vi.mock('../avatar', () => ({ default: { getAvatar: vi.fn() } }));
|
||||
vi.mock('../friend', () => ({ default: { getFriends: vi.fn() } }));
|
||||
vi.mock('../favorite', () => ({
|
||||
default: {
|
||||
getFavoriteLimits: vi.fn(),
|
||||
getFavorites: vi.fn(),
|
||||
getFavoriteGroups: vi.fn(),
|
||||
getFavoriteWorlds: vi.fn(),
|
||||
getFavoriteAvatars: vi.fn()
|
||||
}
|
||||
}));
|
||||
vi.mock('../vrcPlusIcon', () => ({ default: { getFileList: vi.fn() } }));
|
||||
vi.mock('../vrcPlusImage', () => ({
|
||||
default: { getPrints: vi.fn(), getPrint: vi.fn() }
|
||||
}));
|
||||
vi.mock('../inventory', () => ({
|
||||
default: { getUserInventoryItem: vi.fn(), getInventoryItems: vi.fn() }
|
||||
}));
|
||||
vi.mock('../misc', () => ({ default: { getFile: vi.fn() } }));
|
||||
|
||||
import queryRequest from '../queryRequest';
|
||||
|
||||
describe('queryRequest', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test('routes user fetch through policy wrapper and returns cache marker', async () => {
|
||||
const data = { json: { id: 'usr_1' }, params: { userId: 'usr_1' } };
|
||||
mockGetUser.mockResolvedValue(data);
|
||||
mockFetchWithEntityPolicy.mockImplementation(async ({ queryFn }) => ({
|
||||
data: await queryFn(),
|
||||
cache: true
|
||||
}));
|
||||
|
||||
const args = await queryRequest.fetch('user', { userId: 'usr_1' });
|
||||
|
||||
expect(mockFetchWithEntityPolicy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
queryKey: ['user', 'usr_1']
|
||||
})
|
||||
);
|
||||
expect(args.cache).toBe(true);
|
||||
expect(args.json.id).toBe('usr_1');
|
||||
});
|
||||
|
||||
test('supports worldsByUser option routing', async () => {
|
||||
const params = {
|
||||
userId: 'usr_me',
|
||||
n: 50,
|
||||
offset: 0,
|
||||
sort: 'updated',
|
||||
order: 'descending',
|
||||
user: 'me',
|
||||
releaseStatus: 'all',
|
||||
option: 'featured'
|
||||
};
|
||||
mockGetWorlds.mockResolvedValue({ json: [], params });
|
||||
mockFetchWithEntityPolicy.mockImplementation(async ({ queryFn }) => ({
|
||||
data: await queryFn(),
|
||||
cache: false
|
||||
}));
|
||||
|
||||
await queryRequest.fetch('worldsByUser', params);
|
||||
|
||||
expect(mockGetWorlds).toHaveBeenCalledWith(params, 'featured');
|
||||
expect(mockFetchWithEntityPolicy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
queryKey: ['worlds', 'user', 'usr_me', params]
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('supports groupCalendar resource shape', async () => {
|
||||
mockGetGroupCalendar.mockResolvedValue({
|
||||
json: { results: [] },
|
||||
params: { groupId: 'grp_1' }
|
||||
});
|
||||
mockFetchWithEntityPolicy.mockImplementation(async ({ queryFn }) => ({
|
||||
data: await queryFn(),
|
||||
cache: false
|
||||
}));
|
||||
|
||||
await queryRequest.fetch('groupCalendar', { groupId: 'grp_1' });
|
||||
|
||||
expect(mockGetGroupCalendar).toHaveBeenCalledWith('grp_1');
|
||||
expect(mockFetchWithEntityPolicy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
queryKey: ['group', 'grp_1', 'calendar']
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('throws on unknown resource', async () => {
|
||||
await expect(
|
||||
// @ts-expect-error verifying runtime guard
|
||||
queryRequest.fetch('missing_resource', {})
|
||||
).rejects.toThrow('Unknown query resource');
|
||||
});
|
||||
});
|
||||
@@ -1,11 +1,6 @@
|
||||
import { patchAndRefetchActiveQuery, queryKeys } from '../queries';
|
||||
import { request } from '../service/request';
|
||||
import { useUserStore } from '../stores';
|
||||
import {
|
||||
entityQueryPolicies,
|
||||
fetchWithEntityPolicy,
|
||||
patchAndRefetchActiveQuery,
|
||||
queryKeys
|
||||
} from '../queries';
|
||||
|
||||
const avatarReq = {
|
||||
/**
|
||||
@@ -23,22 +18,6 @@ const avatarReq = {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch avatar from query cache if fresh. Otherwise, calls API.
|
||||
* @param {{avatarId: string}} params
|
||||
* @returns {Promise<{json: any, ref?: any, cache?: boolean, params: {avatarId: string}}>}
|
||||
*/
|
||||
getCachedAvatar(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.avatar(params.avatarId),
|
||||
policy: entityQueryPolicies.avatar,
|
||||
queryFn: () => avatarReq.getAvatar(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @type {import('../types/api/avatar').GetAvatars}
|
||||
*/
|
||||
@@ -72,7 +51,10 @@ const avatarReq = {
|
||||
queryKey: queryKeys.avatar(params.id),
|
||||
nextData: args
|
||||
}).catch((err) => {
|
||||
console.error('Failed to refresh avatar query after mutation:', err);
|
||||
console.error(
|
||||
'Failed to refresh avatar query after mutation:',
|
||||
err
|
||||
);
|
||||
});
|
||||
return args;
|
||||
});
|
||||
@@ -112,7 +94,7 @@ const avatarReq = {
|
||||
|
||||
/**
|
||||
* @param {{ avatarId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
selectFallbackAvatar(params) {
|
||||
const userStore = useUserStore();
|
||||
@@ -144,7 +126,7 @@ const avatarReq = {
|
||||
|
||||
/**
|
||||
* @param {{ avatarId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
deleteAvatar(params) {
|
||||
return request(`avatars/${params.avatarId}`, {
|
||||
@@ -247,6 +229,8 @@ const avatarReq = {
|
||||
|
||||
/**
|
||||
* @param {{ imageData: string, avatarId: string }}
|
||||
* @param imageData
|
||||
* @param avatarId
|
||||
* @returns {Promise<{json: any, params}>}
|
||||
*/
|
||||
uploadAvatarGalleryImage(imageData, avatarId) {
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import { useFavoriteStore, useUserStore } from '../stores';
|
||||
import { queryClient } from '../queries';
|
||||
import { request } from '../service/request';
|
||||
import {
|
||||
entityQueryPolicies,
|
||||
fetchWithEntityPolicy,
|
||||
queryClient,
|
||||
queryKeys
|
||||
} from '../queries';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function getCurrentUserId() {
|
||||
return useUserStore().currentUser.id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function refetchActiveFavoriteQueries() {
|
||||
queryClient
|
||||
.invalidateQueries({
|
||||
@@ -34,17 +35,6 @@ const favoriteReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedFavoriteLimits() {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.favoriteLimits(),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: () => favoriteReq.getFavoriteLimits()
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @type {import('../types/api/favorite').GetFavorites}
|
||||
*/
|
||||
@@ -61,17 +51,6 @@ const favoriteReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedFavorites(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.favorites(params),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: () => favoriteReq.getFavorites(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @type {import('../types/api/favorite').AddFavorite}
|
||||
*/
|
||||
@@ -92,7 +71,7 @@ const favoriteReq = {
|
||||
|
||||
/**
|
||||
* @param {{ objectId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
deleteFavorite(params) {
|
||||
return request(`favorites/${params.objectId}`, {
|
||||
@@ -110,7 +89,7 @@ const favoriteReq = {
|
||||
|
||||
/**
|
||||
* @param {{ n: number, offset: number, type: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getFavoriteGroups(params) {
|
||||
return request('favorite/groups', {
|
||||
@@ -125,21 +104,10 @@ const favoriteReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedFavoriteGroups(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.favoriteGroups(params),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: () => favoriteReq.getFavoriteGroups(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {{ type: string, group: string, displayName?: string, visibility?: string }} params group is a name
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
saveFavoriteGroup(params) {
|
||||
return request(
|
||||
@@ -163,7 +131,7 @@ const favoriteReq = {
|
||||
* type: string,
|
||||
* group: string
|
||||
* }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
clearFavoriteGroup(params) {
|
||||
return request(
|
||||
@@ -199,17 +167,6 @@ const favoriteReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedFavoriteWorlds(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.favoriteWorlds(params),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: () => favoriteReq.getFavoriteWorlds(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @type {import('../types/api/favorite').GetFavoriteAvatars}
|
||||
*/
|
||||
@@ -224,17 +181,6 @@ const favoriteReq = {
|
||||
};
|
||||
return args;
|
||||
});
|
||||
},
|
||||
|
||||
getCachedFavoriteAvatars(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.favoriteAvatars(params),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: () => favoriteReq.getFavoriteAvatars(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { queryClient } from '../queries';
|
||||
import { request } from '../service/request';
|
||||
import { useUserStore } from '../stores/user';
|
||||
import {
|
||||
entityQueryPolicies,
|
||||
fetchWithEntityPolicy,
|
||||
queryClient,
|
||||
queryKeys
|
||||
} from '../queries';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function refetchActiveFriendListQueries() {
|
||||
queryClient
|
||||
.invalidateQueries({
|
||||
@@ -44,22 +42,6 @@ const friendReq = {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch friends from query cache if still fresh. Otherwise, calls API.
|
||||
* @param {{ n: number, offset: number, offline?: boolean }} params
|
||||
* @returns {Promise<{json: any, params: { n: number, offset: number, offline?: boolean }, cache?: boolean}>}
|
||||
*/
|
||||
getCachedFriends(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.friends(params),
|
||||
policy: entityQueryPolicies.friendList,
|
||||
queryFn: () => friendReq.getFriends(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {{ userId: string }} params
|
||||
* @returns {Promise<{json: any, params: { userId: string }}>}
|
||||
@@ -96,6 +78,7 @@ const friendReq = {
|
||||
|
||||
/**
|
||||
* @param {{ userId: string }} params
|
||||
* @param customMsg
|
||||
* @returns {Promise<{json: any, params: { userId: string }}>}
|
||||
*/
|
||||
deleteFriend(params, customMsg) {
|
||||
|
||||
159
src/api/group.js
159
src/api/group.js
@@ -1,16 +1,18 @@
|
||||
import { useGroupStore, useUserStore } from '../stores';
|
||||
import { queryClient } from '../queries';
|
||||
import { request } from '../service/request';
|
||||
import {
|
||||
entityQueryPolicies,
|
||||
fetchWithEntityPolicy,
|
||||
queryClient,
|
||||
queryKeys
|
||||
} from '../queries';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function getCurrentUserId() {
|
||||
return useUserStore().currentUser.id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupId
|
||||
*/
|
||||
function refetchActiveGroupScope(groupId) {
|
||||
if (!groupId) {
|
||||
return;
|
||||
@@ -47,7 +49,7 @@ const groupReq = {
|
||||
|
||||
/**
|
||||
* @param {{ groupId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
cancelGroupRequest(params) {
|
||||
return request(`groups/${params.groupId}/requests`, {
|
||||
@@ -63,7 +65,7 @@ const groupReq = {
|
||||
|
||||
/**
|
||||
* @param {{ groupId: string, postId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
deleteGroupPost(params) {
|
||||
return request(`groups/${params.groupId}/posts/${params.postId}`, {
|
||||
@@ -87,35 +89,18 @@ const groupReq = {
|
||||
includeRoles: params.includeRoles || false
|
||||
}
|
||||
}).then((json) => {
|
||||
const groupStore = useGroupStore();
|
||||
const args = {
|
||||
json,
|
||||
params
|
||||
};
|
||||
args.ref = groupStore.applyGroup(json);
|
||||
return args;
|
||||
});
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @param {{ groupId: string }} params
|
||||
* @return { Promise<{json: any, ref: any, cache?: boolean, params}> }
|
||||
*/
|
||||
getCachedGroup(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.group(params.groupId, params.includeRoles),
|
||||
policy: entityQueryPolicies.group,
|
||||
queryFn: () => groupReq.getGroup(params).then((args) => {
|
||||
const groupStore = useGroupStore();
|
||||
args.ref = groupStore.applyGroup(args.json);
|
||||
return args;
|
||||
})
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
/**
|
||||
* @param {{ userId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getRepresentedGroup(params) {
|
||||
return request(`users/${params.userId}/groups/represented`, {
|
||||
@@ -130,7 +115,7 @@ const groupReq = {
|
||||
},
|
||||
/**
|
||||
* @param {{ userId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getGroups(params) {
|
||||
return request(`users/${params.userId}/groups`, {
|
||||
@@ -145,7 +130,7 @@ const groupReq = {
|
||||
},
|
||||
/**
|
||||
* @param {{ groupId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
joinGroup(params) {
|
||||
return request(`groups/${params.groupId}/join`, {
|
||||
@@ -161,7 +146,7 @@ const groupReq = {
|
||||
},
|
||||
/**
|
||||
* @param {{ groupId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
leaveGroup(params) {
|
||||
return request(`groups/${params.groupId}/leave`, {
|
||||
@@ -177,7 +162,7 @@ const groupReq = {
|
||||
},
|
||||
/**
|
||||
* @param {{ query: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
groupStrictsearch(params) {
|
||||
return request(`groups/strictsearch`, {
|
||||
@@ -199,7 +184,10 @@ const groupReq = {
|
||||
isSubscribedToAnnouncements: bool,
|
||||
managerNotes: string
|
||||
}
|
||||
*/
|
||||
* @param userId
|
||||
* @param groupId
|
||||
* @param params
|
||||
*/
|
||||
setGroupMemberProps(userId, groupId, params) {
|
||||
return request(`groups/${groupId}/members/${userId}`, {
|
||||
method: 'PUT',
|
||||
@@ -221,7 +209,7 @@ const groupReq = {
|
||||
* groupId: string,
|
||||
* roleId: string
|
||||
* }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
addGroupMemberRole(params) {
|
||||
return request(
|
||||
@@ -244,7 +232,7 @@ const groupReq = {
|
||||
* groupId: string,
|
||||
* roleId: string
|
||||
* }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
removeGroupMemberRole(params) {
|
||||
return request(
|
||||
@@ -278,7 +266,7 @@ const groupReq = {
|
||||
n: number,
|
||||
offset: number
|
||||
}} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getGroupPosts(params) {
|
||||
return request(`groups/${params.groupId}/posts`, {
|
||||
@@ -292,16 +280,6 @@ const groupReq = {
|
||||
return args;
|
||||
});
|
||||
},
|
||||
getCachedGroupPosts(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.groupPosts(params),
|
||||
policy: entityQueryPolicies.groupCollection,
|
||||
queryFn: () => groupReq.getGroupPosts(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
editGroupPost(params) {
|
||||
return request(`groups/${params.groupId}/posts/${params.postId}`, {
|
||||
method: 'PUT',
|
||||
@@ -333,7 +311,7 @@ const groupReq = {
|
||||
* groupId: string,
|
||||
* userId: string
|
||||
* }} params
|
||||
* @return { Promise<{json: any, params, ref?: any}> }
|
||||
* @returns { Promise<{json: any, params, ref?: any}> }
|
||||
*/
|
||||
getGroupMember(params) {
|
||||
return request(`groups/${params.groupId}/members/${params.userId}`, {
|
||||
@@ -346,23 +324,13 @@ const groupReq = {
|
||||
return args;
|
||||
});
|
||||
},
|
||||
getCachedGroupMember(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.groupMember(params),
|
||||
policy: entityQueryPolicies.groupCollection,
|
||||
queryFn: () => groupReq.getGroupMember(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
/**
|
||||
* @param {{
|
||||
* groupId: string,
|
||||
* n: number,
|
||||
* offset: number
|
||||
* }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getGroupMembers(params) {
|
||||
return request(`groups/${params.groupId}/members`, {
|
||||
@@ -376,16 +344,6 @@ const groupReq = {
|
||||
return args;
|
||||
});
|
||||
},
|
||||
getCachedGroupMembers(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.groupMembers(params),
|
||||
policy: entityQueryPolicies.groupCollection,
|
||||
queryFn: () => groupReq.getGroupMembers(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
/**
|
||||
* @param {{
|
||||
* groupId: string,
|
||||
@@ -393,7 +351,7 @@ const groupReq = {
|
||||
* n: number,
|
||||
* offset: number
|
||||
* }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getGroupMembersSearch(params) {
|
||||
return request(`groups/${params.groupId}/members/search`, {
|
||||
@@ -411,7 +369,7 @@ const groupReq = {
|
||||
* @param {{
|
||||
* groupId: string
|
||||
* }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
blockGroup(params) {
|
||||
return request(`groups/${params.groupId}/block`, {
|
||||
@@ -430,7 +388,7 @@ const groupReq = {
|
||||
* groupId: string,
|
||||
* userId: string
|
||||
* }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
unblockGroup(params) {
|
||||
return request(`groups/${params.groupId}/members/${params.userId}`, {
|
||||
@@ -449,7 +407,7 @@ const groupReq = {
|
||||
* groupId: string,
|
||||
* userId: string
|
||||
* }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
sendGroupInvite(params) {
|
||||
return request(`groups/${params.groupId}/invites`, {
|
||||
@@ -470,7 +428,7 @@ const groupReq = {
|
||||
* groupId: string,
|
||||
* userId: string
|
||||
* }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
kickGroupMember(params) {
|
||||
return request(`groups/${params.groupId}/members/${params.userId}`, {
|
||||
@@ -486,7 +444,7 @@ const groupReq = {
|
||||
},
|
||||
/**
|
||||
* @param {{ groupId: string, userId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
banGroupMember(params) {
|
||||
return request(`groups/${params.groupId}/bans`, {
|
||||
@@ -517,7 +475,7 @@ const groupReq = {
|
||||
},
|
||||
/**
|
||||
* @param {{ groupId: string, userId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
deleteSentGroupInvite(params) {
|
||||
return request(`groups/${params.groupId}/invites/${params.userId}`, {
|
||||
@@ -601,7 +559,7 @@ const groupReq = {
|
||||
},
|
||||
/**
|
||||
* @param {{ groupId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getGroupAuditLogTypes(params) {
|
||||
return request(`groups/${params.groupId}/auditLogTypes`, {
|
||||
@@ -615,8 +573,8 @@ const groupReq = {
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @param {{ groupId: string, n: number, offset: number, eventTypes?: array }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @param {{groupId: string, n: number, offset: number, eventTypes?: Array}} params
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getGroupLogs(params) {
|
||||
return request(`groups/${params.groupId}/auditLogs`, {
|
||||
@@ -632,7 +590,7 @@ const groupReq = {
|
||||
},
|
||||
/**
|
||||
* @param {{ groupId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getGroupInvites(params) {
|
||||
return request(`groups/${params.groupId}/invites`, {
|
||||
@@ -648,7 +606,7 @@ const groupReq = {
|
||||
},
|
||||
/**
|
||||
* @param {{ groupId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getGroupJoinRequests(params) {
|
||||
return request(`groups/${params.groupId}/requests`, {
|
||||
@@ -664,7 +622,7 @@ const groupReq = {
|
||||
},
|
||||
/**
|
||||
* @param {{ groupId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getGroupInstances(params) {
|
||||
return request(
|
||||
@@ -682,7 +640,7 @@ const groupReq = {
|
||||
},
|
||||
/**
|
||||
* @param {{ groupId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getGroupRoles(params) {
|
||||
return request(`groups/${params.groupId}/roles`, {
|
||||
@@ -715,7 +673,7 @@ const groupReq = {
|
||||
order: string,
|
||||
sortBy: string
|
||||
}} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
groupSearch(params) {
|
||||
return request(`groups`, {
|
||||
@@ -736,7 +694,7 @@ const groupReq = {
|
||||
n: number,
|
||||
offset: number
|
||||
}} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getGroupGallery(params) {
|
||||
return request(
|
||||
@@ -756,16 +714,6 @@ const groupReq = {
|
||||
return args;
|
||||
});
|
||||
},
|
||||
getCachedGroupGallery(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.groupGallery(params),
|
||||
policy: entityQueryPolicies.groupCollection,
|
||||
queryFn: () => groupReq.getGroupGallery(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
getGroupCalendar(groupId) {
|
||||
return request(`calendar/${groupId}`, {
|
||||
@@ -780,23 +728,13 @@ const groupReq = {
|
||||
return args;
|
||||
});
|
||||
},
|
||||
getCachedGroupCalendar(groupId) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.groupCalendar(groupId),
|
||||
policy: entityQueryPolicies.groupCollection,
|
||||
queryFn: () => groupReq.getGroupCalendar(groupId)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
groupId: string,
|
||||
eventId: string
|
||||
}} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getGroupCalendarEvent(params) {
|
||||
return request(`calendar/${params.groupId}/${params.eventId}`, {
|
||||
@@ -809,17 +747,6 @@ const groupReq = {
|
||||
return args;
|
||||
});
|
||||
},
|
||||
getCachedGroupCalendarEvent(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.groupCalendarEvent(params),
|
||||
policy: entityQueryPolicies.groupCollection,
|
||||
queryFn: () => groupReq.getGroupCalendarEvent(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @type {import('../types/api/group').GetCalendars}
|
||||
*/
|
||||
|
||||
@@ -19,6 +19,7 @@ import miscRequest from './misc';
|
||||
import notificationRequest from './notification';
|
||||
import playerModerationRequest from './playerModeration';
|
||||
import propRequest from './prop';
|
||||
import queryRequest from './queryRequest';
|
||||
import userRequest from './user';
|
||||
import vrcPlusIconRequest from './vrcPlusIcon';
|
||||
import vrcPlusImageRequest from './vrcPlusImage';
|
||||
@@ -43,7 +44,8 @@ window.request = {
|
||||
groupRequest,
|
||||
inventoryRequest,
|
||||
propRequest,
|
||||
imageRequest
|
||||
imageRequest,
|
||||
queryRequest
|
||||
};
|
||||
|
||||
export {
|
||||
@@ -65,5 +67,6 @@ export {
|
||||
groupRequest,
|
||||
inventoryRequest,
|
||||
propRequest,
|
||||
imageRequest
|
||||
imageRequest,
|
||||
queryRequest
|
||||
};
|
||||
|
||||
@@ -3,12 +3,6 @@ import { toast } from 'vue-sonner';
|
||||
import { i18n } from '../plugin/i18n';
|
||||
import { request } from '../service/request';
|
||||
import { useInstanceStore } from '../stores';
|
||||
import {
|
||||
entityQueryPolicies,
|
||||
fetchWithEntityPolicy,
|
||||
patchAndRefetchActiveQuery,
|
||||
queryKeys
|
||||
} from '../queries';
|
||||
|
||||
const instanceReq = {
|
||||
/**
|
||||
@@ -28,21 +22,6 @@ const instanceReq = {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {{worldId: string, instanceId: string}} params
|
||||
* @returns {Promise<{json: any, ref: any, cache?: boolean, params}>}
|
||||
*/
|
||||
getCachedInstance(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.instance(params.worldId, params.instanceId),
|
||||
policy: entityQueryPolicies.instance,
|
||||
queryFn: () => instanceReq.getInstance(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @type {import('../types/api/instance').CreateInstance}
|
||||
*/
|
||||
@@ -57,15 +36,6 @@ const instanceReq = {
|
||||
params
|
||||
};
|
||||
args.ref = instanceStore.applyInstance(json);
|
||||
patchAndRefetchActiveQuery({
|
||||
queryKey: queryKeys.instance(args.ref.worldId, args.ref.instanceId),
|
||||
nextData: args
|
||||
}).catch((err) => {
|
||||
console.error(
|
||||
'Failed to refresh instance query after instance creation:',
|
||||
err
|
||||
);
|
||||
});
|
||||
return args;
|
||||
});
|
||||
},
|
||||
@@ -108,15 +78,6 @@ const instanceReq = {
|
||||
params
|
||||
};
|
||||
args.ref = instanceStore.applyInstance(json);
|
||||
patchAndRefetchActiveQuery({
|
||||
queryKey: queryKeys.instance(args.ref.worldId, args.ref.instanceId),
|
||||
nextData: args
|
||||
}).catch((err) => {
|
||||
console.error(
|
||||
'Failed to refresh instance query after short-name resolve:',
|
||||
err
|
||||
);
|
||||
});
|
||||
return args;
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { queryClient } from '../queries';
|
||||
import { request } from '../service/request';
|
||||
import {
|
||||
entityQueryPolicies,
|
||||
fetchWithEntityPolicy,
|
||||
queryClient,
|
||||
queryKeys
|
||||
} from '../queries';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function refetchActiveInventoryQueries() {
|
||||
queryClient
|
||||
.invalidateQueries({
|
||||
@@ -37,17 +35,6 @@ const inventoryReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedUserInventoryItem(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.userInventoryItem(params),
|
||||
policy: entityQueryPolicies.inventoryCollection,
|
||||
queryFn: () => inventoryReq.getUserInventoryItem(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {{ inventoryId: string }} params
|
||||
* @returns {Promise<{json: any, params}>}
|
||||
@@ -82,17 +69,6 @@ const inventoryReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedInventoryItems(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.inventoryItems(params),
|
||||
policy: entityQueryPolicies.inventoryCollection,
|
||||
queryFn: () => inventoryReq.getInventoryItems(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {{ inventoryId: string }} params
|
||||
* @returns {Promise<{json: any, params}>}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { queryClient, queryKeys } from '../queries';
|
||||
import { request } from '../service/request';
|
||||
import { useUserStore } from '../stores';
|
||||
import {
|
||||
entityQueryPolicies,
|
||||
fetchWithEntityPolicy,
|
||||
queryClient,
|
||||
queryKeys
|
||||
} from '../queries';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function getCurrentUserId() {
|
||||
return useUserStore().currentUser.id;
|
||||
}
|
||||
@@ -24,17 +22,6 @@ const miscReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedFile(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.file(params.fileId),
|
||||
policy: entityQueryPolicies.fileObject,
|
||||
queryFn: () => miscReq.getFile(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
saveNote(params) {
|
||||
return request('userNotes', {
|
||||
method: 'POST',
|
||||
@@ -55,7 +42,7 @@ const miscReq = {
|
||||
* reason: string,
|
||||
* type: string
|
||||
* }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
reportUser(params) {
|
||||
return request(`feedback/${params.userId}/user`, {
|
||||
@@ -80,7 +67,7 @@ const miscReq = {
|
||||
* version: number,
|
||||
* variant: string
|
||||
* }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getFileAnalysis(params) {
|
||||
return request(
|
||||
@@ -218,6 +205,7 @@ const miscReq = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @param params
|
||||
* @params {{
|
||||
userId: string,
|
||||
emojiId: string
|
||||
|
||||
163
src/api/queryRequest.js
Normal file
163
src/api/queryRequest.js
Normal file
@@ -0,0 +1,163 @@
|
||||
import {
|
||||
entityQueryPolicies,
|
||||
fetchWithEntityPolicy,
|
||||
queryKeys
|
||||
} from '../queries';
|
||||
|
||||
import avatarRequest from './avatar';
|
||||
import favoriteRequest from './favorite';
|
||||
import friendRequest from './friend';
|
||||
import groupRequest from './group';
|
||||
import inventoryRequest from './inventory';
|
||||
import miscRequest from './misc';
|
||||
import userRequest from './user';
|
||||
import vrcPlusIconRequest from './vrcPlusIcon';
|
||||
import vrcPlusImageRequest from './vrcPlusImage';
|
||||
import worldRequest from './world';
|
||||
|
||||
const registry = Object.freeze({
|
||||
user: {
|
||||
key: (params) => queryKeys.user(params.userId),
|
||||
policy: entityQueryPolicies.user,
|
||||
queryFn: (params) => userRequest.getUser(params)
|
||||
},
|
||||
avatar: {
|
||||
key: (params) => queryKeys.avatar(params.avatarId),
|
||||
policy: entityQueryPolicies.avatar,
|
||||
queryFn: (params) => avatarRequest.getAvatar(params)
|
||||
},
|
||||
world: {
|
||||
key: (params) => queryKeys.world(params.worldId),
|
||||
policy: entityQueryPolicies.world,
|
||||
queryFn: (params) => worldRequest.getWorld(params)
|
||||
},
|
||||
worldsByUser: {
|
||||
key: (params) => queryKeys.worldsByUser(params),
|
||||
policy: entityQueryPolicies.worldCollection,
|
||||
queryFn: (params) =>
|
||||
worldRequest.getWorlds(params, params.option || undefined)
|
||||
},
|
||||
group: {
|
||||
key: (params) => queryKeys.group(params.groupId, params.includeRoles),
|
||||
policy: entityQueryPolicies.group,
|
||||
queryFn: (params) => groupRequest.getGroup(params)
|
||||
},
|
||||
groupPosts: {
|
||||
key: (params) => queryKeys.groupPosts(params),
|
||||
policy: entityQueryPolicies.groupCollection,
|
||||
queryFn: (params) => groupRequest.getGroupPosts(params)
|
||||
},
|
||||
groupMember: {
|
||||
key: (params) => queryKeys.groupMember(params),
|
||||
policy: entityQueryPolicies.groupCollection,
|
||||
queryFn: (params) => groupRequest.getGroupMember(params)
|
||||
},
|
||||
groupMembers: {
|
||||
key: (params) => queryKeys.groupMembers(params),
|
||||
policy: entityQueryPolicies.groupCollection,
|
||||
queryFn: (params) => groupRequest.getGroupMembers(params)
|
||||
},
|
||||
groupGallery: {
|
||||
key: (params) => queryKeys.groupGallery(params),
|
||||
policy: entityQueryPolicies.groupCollection,
|
||||
queryFn: (params) => groupRequest.getGroupGallery(params)
|
||||
},
|
||||
groupCalendar: {
|
||||
key: (params) => queryKeys.groupCalendar(params.groupId),
|
||||
policy: entityQueryPolicies.groupCollection,
|
||||
queryFn: (params) => groupRequest.getGroupCalendar(params.groupId)
|
||||
},
|
||||
groupCalendarEvent: {
|
||||
key: (params) => queryKeys.groupCalendarEvent(params),
|
||||
policy: entityQueryPolicies.groupCollection,
|
||||
queryFn: (params) => groupRequest.getGroupCalendarEvent(params)
|
||||
},
|
||||
friends: {
|
||||
key: (params) => queryKeys.friends(params),
|
||||
policy: entityQueryPolicies.friendList,
|
||||
queryFn: (params) => friendRequest.getFriends(params)
|
||||
},
|
||||
favoriteLimits: {
|
||||
key: () => queryKeys.favoriteLimits(),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: () => favoriteRequest.getFavoriteLimits()
|
||||
},
|
||||
favorites: {
|
||||
key: (params) => queryKeys.favorites(params),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: (params) => favoriteRequest.getFavorites(params)
|
||||
},
|
||||
favoriteGroups: {
|
||||
key: (params) => queryKeys.favoriteGroups(params),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: (params) => favoriteRequest.getFavoriteGroups(params)
|
||||
},
|
||||
favoriteWorlds: {
|
||||
key: (params) => queryKeys.favoriteWorlds(params),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: (params) => favoriteRequest.getFavoriteWorlds(params)
|
||||
},
|
||||
favoriteAvatars: {
|
||||
key: (params) => queryKeys.favoriteAvatars(params),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: (params) => favoriteRequest.getFavoriteAvatars(params)
|
||||
},
|
||||
galleryFiles: {
|
||||
key: (params) => queryKeys.galleryFiles(params),
|
||||
policy: entityQueryPolicies.galleryCollection,
|
||||
queryFn: (params) => vrcPlusIconRequest.getFileList(params)
|
||||
},
|
||||
prints: {
|
||||
key: (params) => queryKeys.prints(params),
|
||||
policy: entityQueryPolicies.galleryCollection,
|
||||
queryFn: (params) => vrcPlusImageRequest.getPrints(params)
|
||||
},
|
||||
print: {
|
||||
key: (params) => queryKeys.print(params.printId),
|
||||
policy: entityQueryPolicies.galleryCollection,
|
||||
queryFn: (params) => vrcPlusImageRequest.getPrint(params)
|
||||
},
|
||||
userInventoryItem: {
|
||||
key: (params) => queryKeys.userInventoryItem(params),
|
||||
policy: entityQueryPolicies.inventoryCollection,
|
||||
queryFn: (params) => inventoryRequest.getUserInventoryItem(params)
|
||||
},
|
||||
inventoryItems: {
|
||||
key: (params) => queryKeys.inventoryItems(params),
|
||||
policy: entityQueryPolicies.inventoryCollection,
|
||||
queryFn: (params) => inventoryRequest.getInventoryItems(params)
|
||||
},
|
||||
file: {
|
||||
key: (params) => queryKeys.file(params.fileId),
|
||||
policy: entityQueryPolicies.fileObject,
|
||||
queryFn: (params) => miscRequest.getFile(params)
|
||||
}
|
||||
});
|
||||
|
||||
const queryRequest = {
|
||||
/**
|
||||
* @template T
|
||||
* @param {keyof typeof registry} resource
|
||||
* @param {any} [params]
|
||||
* @returns {Promise<T & {cache: boolean}>}
|
||||
*/
|
||||
async fetch(resource, params = {}) {
|
||||
const entry = registry[resource];
|
||||
if (!entry) {
|
||||
throw new Error(`Unknown query resource: ${String(resource)}`);
|
||||
}
|
||||
|
||||
const { data, cache } = await fetchWithEntityPolicy({
|
||||
queryKey: entry.key(params),
|
||||
policy: entry.policy,
|
||||
queryFn: () => entry.queryFn(params)
|
||||
});
|
||||
|
||||
return {
|
||||
...data,
|
||||
cache
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default queryRequest;
|
||||
@@ -1,11 +1,6 @@
|
||||
import { patchAndRefetchActiveQuery, queryKeys } from '../queries';
|
||||
import { request } from '../service/request';
|
||||
import { useUserStore } from '../stores';
|
||||
import {
|
||||
entityQueryPolicies,
|
||||
fetchWithEntityPolicy,
|
||||
patchAndRefetchActiveQuery,
|
||||
queryKeys
|
||||
} from '../queries';
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
@@ -40,21 +35,6 @@ const userReq = {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch user from cache if they're in it. Otherwise, calls API.
|
||||
* @type {import('../types/api/user').GetCachedUser}
|
||||
*/
|
||||
getCachedUser(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.user(params.userId),
|
||||
policy: entityQueryPolicies.user,
|
||||
queryFn: () => userReq.getUser(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @type {import('../types/api/user').GetUsers}
|
||||
*/
|
||||
@@ -147,7 +127,10 @@ const userReq = {
|
||||
queryKey: queryKeys.user(args.ref.id),
|
||||
nextData: args
|
||||
}).catch((err) => {
|
||||
console.error('Failed to refresh user query after mutation:', err);
|
||||
console.error(
|
||||
'Failed to refresh user query after mutation:',
|
||||
err
|
||||
);
|
||||
});
|
||||
return args;
|
||||
});
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { queryClient } from '../queries';
|
||||
import { request } from '../service/request';
|
||||
import {
|
||||
entityQueryPolicies,
|
||||
fetchWithEntityPolicy,
|
||||
queryClient,
|
||||
queryKeys
|
||||
} from '../queries';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function refetchActiveGalleryQueries() {
|
||||
queryClient
|
||||
.invalidateQueries({
|
||||
@@ -31,17 +29,6 @@ const VRCPlusIconsReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedFileList(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.galleryFiles(params),
|
||||
policy: entityQueryPolicies.galleryCollection,
|
||||
queryFn: () => VRCPlusIconsReq.getFileList(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
deleteFile(fileId) {
|
||||
return request(`file/${fileId}`, {
|
||||
method: 'DELETE'
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import { queryClient } from '../queries';
|
||||
import { request } from '../service/request';
|
||||
import { useUserStore } from '../stores';
|
||||
import {
|
||||
entityQueryPolicies,
|
||||
fetchWithEntityPolicy,
|
||||
queryClient,
|
||||
queryKeys
|
||||
} from '../queries';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function getCurrentUserId() {
|
||||
return useUserStore().currentUser.id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function refetchActiveGalleryQueries() {
|
||||
queryClient
|
||||
.invalidateQueries({
|
||||
@@ -70,17 +71,6 @@ const vrcPlusImageReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedPrints(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.prints(params),
|
||||
policy: entityQueryPolicies.galleryCollection,
|
||||
queryFn: () => vrcPlusImageReq.getPrints(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
deletePrint(printId) {
|
||||
return request(`prints/${printId}`, {
|
||||
method: 'DELETE'
|
||||
@@ -122,17 +112,6 @@ const vrcPlusImageReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedPrint(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.print(params.printId),
|
||||
policy: entityQueryPolicies.galleryCollection,
|
||||
queryFn: () => vrcPlusImageReq.getPrint(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
uploadEmoji(imageData, params) {
|
||||
return request('file/image', {
|
||||
uploadImage: true,
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { patchAndRefetchActiveQuery, queryKeys } from '../queries';
|
||||
import { request } from '../service/request';
|
||||
import { useWorldStore } from '../stores';
|
||||
import {
|
||||
entityQueryPolicies,
|
||||
fetchWithEntityPolicy,
|
||||
patchAndRefetchActiveQuery,
|
||||
queryKeys
|
||||
} from '../queries';
|
||||
|
||||
const worldReq = {
|
||||
/**
|
||||
@@ -25,21 +20,6 @@ const worldReq = {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {{worldId: string}} params
|
||||
* @returns {Promise<{json: any, ref: any, cache?: boolean, params}>}
|
||||
*/
|
||||
getCachedWorld(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.world(params.worldId),
|
||||
policy: entityQueryPolicies.world,
|
||||
queryFn: () => worldReq.getWorld(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @type {import('../types/api/world').GetWorlds}
|
||||
*/
|
||||
@@ -64,24 +44,6 @@ const worldReq = {
|
||||
return args;
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @param {object} params
|
||||
* @param {string} [option]
|
||||
* @returns {Promise<{json: any, cache?: boolean, params: any, option?: string}>}
|
||||
*/
|
||||
getCachedWorlds(params, option) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.worldsByUser({
|
||||
...params,
|
||||
option: option || ''
|
||||
}),
|
||||
policy: entityQueryPolicies.worldCollection,
|
||||
queryFn: () => worldReq.getWorlds(params, option)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
/**
|
||||
* @param {{worldId: string}} params
|
||||
* @returns {Promise<{json: any, params}>}
|
||||
@@ -116,7 +78,10 @@ const worldReq = {
|
||||
queryKey: queryKeys.world(args.ref.id),
|
||||
nextData: args
|
||||
}).catch((err) => {
|
||||
console.error('Failed to refresh world query after mutation:', err);
|
||||
console.error(
|
||||
'Failed to refresh world query after mutation:',
|
||||
err
|
||||
);
|
||||
});
|
||||
return args;
|
||||
});
|
||||
@@ -141,7 +106,10 @@ const worldReq = {
|
||||
queryKey: queryKeys.world(args.ref.id),
|
||||
nextData: args
|
||||
}).catch((err) => {
|
||||
console.error('Failed to refresh world query after publish:', err);
|
||||
console.error(
|
||||
'Failed to refresh world query after publish:',
|
||||
err
|
||||
);
|
||||
});
|
||||
return args;
|
||||
});
|
||||
@@ -166,7 +134,10 @@ const worldReq = {
|
||||
queryKey: queryKeys.world(args.ref.id),
|
||||
nextData: args
|
||||
}).catch((err) => {
|
||||
console.error('Failed to refresh world query after unpublish:', err);
|
||||
console.error(
|
||||
'Failed to refresh world query after unpublish:',
|
||||
err
|
||||
);
|
||||
});
|
||||
return args;
|
||||
});
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
import { queryRequest } from '../api';
|
||||
import { useUserStore } from '../stores';
|
||||
import { userRequest } from '../api';
|
||||
|
||||
const userStore = useUserStore();
|
||||
|
||||
@@ -22,18 +22,24 @@
|
||||
|
||||
const username = ref(props.userid);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function parse() {
|
||||
username.value = props.userid;
|
||||
if (props.hint) {
|
||||
username.value = props.hint;
|
||||
} else if (props.userid) {
|
||||
const args = await userRequest.getCachedUser({ userId: props.userid });
|
||||
const args = await queryRequest.fetch('user', { userId: props.userid });
|
||||
if (args?.json?.displayName) {
|
||||
username.value = args.json.displayName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function showUserDialog() {
|
||||
userStore.showUserDialog(props.userid);
|
||||
}
|
||||
|
||||
@@ -407,9 +407,9 @@
|
||||
removeFromArray
|
||||
} from '../../../shared/utils';
|
||||
import { useGalleryStore, useGroupStore, useModalStore, useUserStore } from '../../../stores';
|
||||
import { groupRequest, queryRequest } from '../../../api';
|
||||
import { Badge } from '../../ui/badge';
|
||||
import { formatJsonVars } from '../../../shared/utils/base/ui';
|
||||
import { groupRequest } from '../../../api';
|
||||
|
||||
import DialogJsonTab from '../DialogJsonTab.vue';
|
||||
import GroupDialogInfoTab from './GroupDialogInfoTab.vue';
|
||||
@@ -796,7 +796,7 @@
|
||||
selectedImageUrl: post.imageUrl
|
||||
};
|
||||
}
|
||||
groupRequest.getCachedGroup({ groupId }).then((args) => {
|
||||
queryRequest.fetch('group', { groupId }).then((args) => {
|
||||
D.groupRef = args.ref;
|
||||
});
|
||||
D.visible = true;
|
||||
|
||||
@@ -84,10 +84,8 @@ vi.mock('../../../../service/request', () => ({
|
||||
failedGetRequests: new Map()
|
||||
}));
|
||||
vi.mock('../../../../api', () => ({
|
||||
groupRequest: {
|
||||
getCachedGroupGallery: vi
|
||||
.fn()
|
||||
.mockResolvedValue({ json: [], params: {} })
|
||||
queryRequest: {
|
||||
fetch: vi.fn().mockResolvedValue({ json: [], params: {} })
|
||||
},
|
||||
userRequest: {}
|
||||
}));
|
||||
|
||||
@@ -2,13 +2,13 @@ import { describe, expect, test, vi, beforeEach } from 'vitest';
|
||||
import { ref } from 'vue';
|
||||
|
||||
vi.mock('../../../../api', () => ({
|
||||
groupRequest: {
|
||||
getCachedGroupGallery: vi.fn()
|
||||
queryRequest: {
|
||||
fetch: vi.fn()
|
||||
}
|
||||
}));
|
||||
|
||||
import { useGroupGalleries } from '../useGroupGalleries';
|
||||
import { groupRequest } from '../../../../api';
|
||||
import { queryRequest } from '../../../../api';
|
||||
|
||||
function createGroupDialog(overrides = {}) {
|
||||
return ref({
|
||||
@@ -120,7 +120,7 @@ describe('useGroupGalleries', () => {
|
||||
galleries: [{ id: 'g1', name: 'Gallery' }]
|
||||
}
|
||||
});
|
||||
groupRequest.getCachedGroupGallery.mockResolvedValue({
|
||||
queryRequest.fetch.mockResolvedValue({
|
||||
json: [],
|
||||
params: { groupId: 'grp_1' }
|
||||
});
|
||||
@@ -145,7 +145,7 @@ describe('useGroupGalleries', () => {
|
||||
]
|
||||
}
|
||||
});
|
||||
groupRequest.getCachedGroupGallery.mockResolvedValue({
|
||||
queryRequest.fetch.mockResolvedValue({
|
||||
json: [],
|
||||
params: { groupId: 'grp_1' }
|
||||
});
|
||||
@@ -153,7 +153,7 @@ describe('useGroupGalleries', () => {
|
||||
const { getGroupGalleries } = useGroupGalleries(groupDialog);
|
||||
await getGroupGalleries();
|
||||
|
||||
expect(groupRequest.getCachedGroupGallery).toHaveBeenCalledTimes(2);
|
||||
expect(queryRequest.fetch).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -162,7 +162,7 @@ describe('useGroupGalleries', () => {
|
||||
const groupDialog = createGroupDialog();
|
||||
const { getGroupGallery } = useGroupGalleries(groupDialog);
|
||||
|
||||
groupRequest.getCachedGroupGallery.mockResolvedValueOnce({
|
||||
queryRequest.fetch.mockResolvedValueOnce({
|
||||
json: [
|
||||
{
|
||||
groupId: 'grp_1',
|
||||
@@ -190,7 +190,7 @@ describe('useGroupGalleries', () => {
|
||||
const groupDialog = createGroupDialog();
|
||||
const { getGroupGallery } = useGroupGalleries(groupDialog);
|
||||
|
||||
groupRequest.getCachedGroupGallery.mockResolvedValueOnce({
|
||||
queryRequest.fetch.mockResolvedValueOnce({
|
||||
json: [
|
||||
{
|
||||
groupId: 'grp_other',
|
||||
@@ -211,7 +211,7 @@ describe('useGroupGalleries', () => {
|
||||
const groupDialog = createGroupDialog();
|
||||
const { getGroupGallery } = useGroupGalleries(groupDialog);
|
||||
|
||||
groupRequest.getCachedGroupGallery.mockResolvedValueOnce({
|
||||
queryRequest.fetch.mockResolvedValueOnce({
|
||||
json: Array.from({ length: 50 }, (_, i) => ({
|
||||
groupId: 'grp_1',
|
||||
galleryId: 'g1',
|
||||
@@ -223,7 +223,7 @@ describe('useGroupGalleries', () => {
|
||||
|
||||
await getGroupGallery('grp_1', 'g1');
|
||||
|
||||
expect(groupRequest.getCachedGroupGallery).toHaveBeenCalledTimes(1);
|
||||
expect(queryRequest.fetch).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('handles API errors gracefully', async () => {
|
||||
@@ -233,7 +233,7 @@ describe('useGroupGalleries', () => {
|
||||
.spyOn(console, 'error')
|
||||
.mockImplementation(() => {});
|
||||
|
||||
groupRequest.getCachedGroupGallery.mockRejectedValueOnce(
|
||||
queryRequest.fetch.mockRejectedValueOnce(
|
||||
new Error('API Error')
|
||||
);
|
||||
|
||||
|
||||
@@ -3,9 +3,10 @@ import { ref } from 'vue';
|
||||
|
||||
vi.mock('../../../../api', () => ({
|
||||
groupRequest: {
|
||||
getGroupMembersSearch: vi.fn(),
|
||||
getCachedGroupMember: vi.fn(),
|
||||
getCachedGroupMembers: vi.fn()
|
||||
getGroupMembersSearch: vi.fn()
|
||||
},
|
||||
queryRequest: {
|
||||
fetch: vi.fn()
|
||||
},
|
||||
userRequest: {}
|
||||
}));
|
||||
@@ -94,7 +95,7 @@ vi.mock('worker-timers', () => ({
|
||||
}));
|
||||
|
||||
import { useGroupMembers } from '../useGroupMembers';
|
||||
import { groupRequest } from '../../../../api';
|
||||
import { groupRequest, queryRequest } from '../../../../api';
|
||||
import { groupDialogFilterOptions } from '../../../../shared/constants';
|
||||
|
||||
/**
|
||||
@@ -133,7 +134,7 @@ function createDeps(overrides = {}) {
|
||||
describe('useGroupMembers', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
groupRequest.getCachedGroupMembers.mockReset();
|
||||
queryRequest.fetch.mockReset();
|
||||
});
|
||||
|
||||
describe('groupDialogMemberSortValue', () => {
|
||||
@@ -316,7 +317,7 @@ describe('useGroupMembers', () => {
|
||||
|
||||
await loadMoreGroupMembers();
|
||||
|
||||
expect(groupRequest.getCachedGroupMembers).not.toHaveBeenCalled();
|
||||
expect(queryRequest.fetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('does not load when already loading', async () => {
|
||||
@@ -327,12 +328,12 @@ describe('useGroupMembers', () => {
|
||||
|
||||
await loadMoreGroupMembers();
|
||||
|
||||
expect(groupRequest.getCachedGroupMembers).not.toHaveBeenCalled();
|
||||
expect(queryRequest.fetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('marks done when fewer than n results returned', async () => {
|
||||
const groupDialog = createGroupDialog();
|
||||
groupRequest.getCachedGroupMembers.mockResolvedValue({
|
||||
queryRequest.fetch.mockResolvedValue({
|
||||
json: [{ userId: 'usr_1' }],
|
||||
params: { groupId: 'grp_1', n: 100, offset: 0 }
|
||||
});
|
||||
@@ -359,7 +360,7 @@ describe('useGroupMembers', () => {
|
||||
const groupDialog = createGroupDialog({
|
||||
members: [{ userId: 'existing' }]
|
||||
});
|
||||
groupRequest.getCachedGroupMembers.mockResolvedValue({
|
||||
queryRequest.fetch.mockResolvedValue({
|
||||
json: [{ userId: 'usr_new' }],
|
||||
params: { groupId: 'grp_1', n: 100, offset: 0 }
|
||||
});
|
||||
@@ -384,7 +385,7 @@ describe('useGroupMembers', () => {
|
||||
const groupDialog = createGroupDialog({
|
||||
members: [{ userId: 'usr_me' }]
|
||||
});
|
||||
groupRequest.getCachedGroupMembers.mockResolvedValue({
|
||||
queryRequest.fetch.mockResolvedValue({
|
||||
json: [{ userId: 'usr_me' }, { userId: 'usr_2' }],
|
||||
params: { groupId: 'grp_1', n: 100, offset: 0 }
|
||||
});
|
||||
@@ -408,7 +409,7 @@ describe('useGroupMembers', () => {
|
||||
|
||||
test('marks done on error', async () => {
|
||||
const groupDialog = createGroupDialog();
|
||||
groupRequest.getCachedGroupMembers.mockRejectedValue(
|
||||
queryRequest.fetch.mockRejectedValue(
|
||||
new Error('fail')
|
||||
);
|
||||
|
||||
@@ -442,7 +443,7 @@ describe('useGroupMembers', () => {
|
||||
|
||||
await setGroupMemberSortOrder({ value: 'joinedAt:desc' });
|
||||
|
||||
expect(groupRequest.getCachedGroupMembers).not.toHaveBeenCalled();
|
||||
expect(queryRequest.fetch).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -460,7 +461,7 @@ describe('useGroupMembers', () => {
|
||||
|
||||
await setGroupMemberFilter(filter);
|
||||
|
||||
expect(groupRequest.getCachedGroupMembers).not.toHaveBeenCalled();
|
||||
expect(queryRequest.fetch).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -83,10 +83,14 @@ vi.mock('../../../../service/request', () => ({
|
||||
}));
|
||||
vi.mock('../../../../api', () => ({
|
||||
groupRequest: {},
|
||||
userRequest: {}
|
||||
userRequest: {},
|
||||
queryRequest: {
|
||||
fetch: vi.fn()
|
||||
}
|
||||
}));
|
||||
|
||||
import { useGroupModerationData } from '../useGroupModerationData';
|
||||
import { queryRequest } from '../../../../api';
|
||||
|
||||
function createTables() {
|
||||
return {
|
||||
@@ -124,9 +128,6 @@ function createDeps(overrides = {}) {
|
||||
getGroupMembers: vi.fn(),
|
||||
getGroupMembersSearch: vi.fn()
|
||||
},
|
||||
userRequest: {
|
||||
getCachedUser: vi.fn()
|
||||
},
|
||||
...overrides
|
||||
};
|
||||
}
|
||||
@@ -134,6 +135,7 @@ function createDeps(overrides = {}) {
|
||||
describe('useGroupModerationData', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
queryRequest.fetch.mockReset();
|
||||
});
|
||||
|
||||
describe('getAllGroupBans', () => {
|
||||
@@ -343,7 +345,7 @@ describe('useGroupModerationData', () => {
|
||||
await addGroupMemberToSelection('usr_1');
|
||||
|
||||
expect(deps.selection.setSelectedUsers).toHaveBeenCalledWith('usr_1', member);
|
||||
expect(deps.userRequest.getCachedUser).not.toHaveBeenCalled();
|
||||
expect(queryRequest.fetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('falls back to user API when member has no user object', async () => {
|
||||
@@ -353,14 +355,14 @@ describe('useGroupModerationData', () => {
|
||||
params: {}
|
||||
});
|
||||
deps.applyGroupMember.mockReturnValue({ userId: 'usr_1' });
|
||||
deps.userRequest.getCachedUser.mockResolvedValue({
|
||||
queryRequest.fetch.mockResolvedValue({
|
||||
json: { id: 'usr_1', displayName: 'Alice' }
|
||||
});
|
||||
|
||||
const { addGroupMemberToSelection } = useGroupModerationData(deps);
|
||||
await addGroupMemberToSelection('usr_1');
|
||||
|
||||
expect(deps.userRequest.getCachedUser).toHaveBeenCalledWith({ userId: 'usr_1' });
|
||||
expect(queryRequest.fetch).toHaveBeenCalledWith('user', { userId: 'usr_1' });
|
||||
expect(deps.selection.setSelectedUsers).toHaveBeenCalledWith('usr_1', expect.objectContaining({
|
||||
userId: 'usr_1',
|
||||
displayName: 'Alice'
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { computed, ref } from 'vue';
|
||||
import { groupRequest } from '../../../api';
|
||||
|
||||
import { queryRequest } from '../../../api';
|
||||
|
||||
/**
|
||||
* Composable for managing group gallery loading and display state.
|
||||
*
|
||||
* @param {import('vue').Ref} groupDialog - reactive ref to the group dialog state
|
||||
* @returns {{
|
||||
* isGroupGalleryLoading: import('vue').Ref<boolean>,
|
||||
@@ -26,7 +26,7 @@ export function useGroupGalleries(groupDialog) {
|
||||
);
|
||||
|
||||
/**
|
||||
* @param {Object} gallery
|
||||
* @param {object} gallery
|
||||
*/
|
||||
function groupGalleryStatus(gallery) {
|
||||
const style = {};
|
||||
@@ -42,6 +42,7 @@ export function useGroupGalleries(groupDialog) {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param obj
|
||||
*/
|
||||
function updateGroupDialogData(obj) {
|
||||
groupDialog.value = {
|
||||
@@ -79,7 +80,7 @@ export function useGroupGalleries(groupDialog) {
|
||||
};
|
||||
const count = 50; // 5000 max
|
||||
for (let i = 0; i < count; i++) {
|
||||
const args = await groupRequest.getCachedGroupGallery(params);
|
||||
const args = await queryRequest.fetch('groupGallery', params);
|
||||
if (args) {
|
||||
for (const json of args.json) {
|
||||
if (groupDialog.value.id === json.groupId) {
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
import { computed, ref } from 'vue';
|
||||
import { debounce } from '../../../shared/utils';
|
||||
|
||||
import {
|
||||
groupDialogFilterOptions,
|
||||
groupDialogSortingOptions
|
||||
} from '../../../shared/constants';
|
||||
import { groupRequest } from '../../../api';
|
||||
import { groupRequest, queryRequest } from '../../../api';
|
||||
import { debounce } from '../../../shared/utils';
|
||||
|
||||
import * as workerTimers from 'worker-timers';
|
||||
|
||||
/**
|
||||
* Composable for managing group member loading, searching, sorting, and filtering.
|
||||
*
|
||||
* @param {import('vue').Ref} groupDialog - reactive ref to the group dialog state
|
||||
* @param {Object} deps - external dependencies
|
||||
* @param {object} deps - external dependencies
|
||||
* @param {import('vue').Ref} deps.currentUser - reactive ref to the current user
|
||||
* @param {Function} deps.applyGroupMember - function to apply group member data
|
||||
* @param {Function} deps.handleGroupMember - function to handle group member updates
|
||||
* @param {Function} deps.t - i18n translation function
|
||||
* @returns {Object} members composable API
|
||||
* @returns {object} members composable API
|
||||
*/
|
||||
export function useGroupMembers(
|
||||
groupDialog,
|
||||
@@ -185,8 +186,8 @@ export function useGroupMembers(
|
||||
loadMoreGroupMembersParams.value.roleId = D.memberFilter.id;
|
||||
}
|
||||
if (D.inGroup) {
|
||||
await groupRequest
|
||||
.getCachedGroupMember({
|
||||
await queryRequest
|
||||
.fetch('groupMember', {
|
||||
groupId: D.id,
|
||||
userId: currentUser.value.id
|
||||
})
|
||||
@@ -219,8 +220,8 @@ export function useGroupMembers(
|
||||
}
|
||||
D.memberSearch = '';
|
||||
isGroupMembersLoading.value = true;
|
||||
await groupRequest
|
||||
.getCachedGroupMembers(params)
|
||||
await queryRequest
|
||||
.fetch('groupMembers', params)
|
||||
.finally(() => {
|
||||
isGroupMembersLoading.value = false;
|
||||
})
|
||||
@@ -278,7 +279,7 @@ export function useGroupMembers(
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} sortOrder
|
||||
* @param {object} sortOrder
|
||||
*/
|
||||
async function setGroupMemberSortOrder(sortOrder) {
|
||||
const D = groupDialog.value;
|
||||
@@ -290,7 +291,7 @@ export function useGroupMembers(
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} filter
|
||||
* @param {object} filter
|
||||
*/
|
||||
async function setGroupMemberFilter(filter) {
|
||||
const D = groupDialog.value;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { ref } from 'vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
|
||||
import { debounce } from '../../../shared/utils';
|
||||
import { queryRequest } from '../../../api';
|
||||
|
||||
import * as workerTimers from 'worker-timers';
|
||||
|
||||
/**
|
||||
* Composable for group moderation data fetching, member management,
|
||||
* searching, sorting and filtering.
|
||||
*
|
||||
* @param {object} deps
|
||||
* @param {import('vue').Ref} deps.groupMemberModeration - store ref
|
||||
* @param {import('vue').Ref} deps.currentUser - store ref
|
||||
@@ -23,7 +25,6 @@ import * as workerTimers from 'worker-timers';
|
||||
* @param {object} deps.selection.selectedUsers
|
||||
* @param {Function} deps.selection.setSelectedUsers
|
||||
* @param {object} deps.groupRequest - API module
|
||||
* @param {object} deps.userRequest - API module
|
||||
*/
|
||||
export function useGroupModerationData(deps) {
|
||||
const {
|
||||
@@ -33,8 +34,7 @@ export function useGroupModerationData(deps) {
|
||||
handleGroupMember,
|
||||
tables,
|
||||
selection,
|
||||
groupRequest,
|
||||
userRequest
|
||||
groupRequest
|
||||
} = deps;
|
||||
|
||||
const isGroupMembersLoading = ref(false);
|
||||
@@ -60,6 +60,9 @@ export function useGroupModerationData(deps) {
|
||||
|
||||
// ── Members ──────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function getGroupMembers() {
|
||||
members.value = [];
|
||||
isGroupMembersDone.value = false;
|
||||
@@ -94,6 +97,9 @@ export function useGroupModerationData(deps) {
|
||||
await loadMoreGroupMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function loadMoreGroupMembers() {
|
||||
if (isGroupMembersDone.value || isGroupMembersLoading.value) {
|
||||
return;
|
||||
@@ -119,7 +125,10 @@ export function useGroupModerationData(deps) {
|
||||
for (let i = 0; i < args.json.length; i++) {
|
||||
const member = args.json[i];
|
||||
if (member.userId === currentUser.value.id) {
|
||||
if (members.value.length > 0 && members.value[0].userId === currentUser.value.id) {
|
||||
if (
|
||||
members.value.length > 0 &&
|
||||
members.value[0].userId === currentUser.value.id
|
||||
) {
|
||||
members.value.splice(0, 1);
|
||||
}
|
||||
break;
|
||||
@@ -142,12 +151,18 @@ export function useGroupModerationData(deps) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function loadAllGroupMembers() {
|
||||
if (isGroupMembersLoading.value) {
|
||||
return;
|
||||
}
|
||||
await getGroupMembers();
|
||||
while (groupMemberModeration.value.visible && !isGroupMembersDone.value) {
|
||||
while (
|
||||
groupMemberModeration.value.visible &&
|
||||
!isGroupMembersDone.value
|
||||
) {
|
||||
isGroupMembersLoading.value = true;
|
||||
await new Promise((resolve) => {
|
||||
workerTimers.setTimeout(resolve, 1000);
|
||||
@@ -157,6 +172,10 @@ export function useGroupModerationData(deps) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sortOrder
|
||||
*/
|
||||
async function setGroupMemberSortOrder(sortOrder) {
|
||||
if (memberSortOrder.value === sortOrder) {
|
||||
return;
|
||||
@@ -165,6 +184,10 @@ export function useGroupModerationData(deps) {
|
||||
await getGroupMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param filter
|
||||
*/
|
||||
async function setGroupMemberFilter(filter) {
|
||||
if (memberFilter.value === filter) {
|
||||
return;
|
||||
@@ -173,6 +196,9 @@ export function useGroupModerationData(deps) {
|
||||
await getGroupMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function groupMembersSearch() {
|
||||
if (memberSearch.value.length < 3) {
|
||||
tables.members.data = [];
|
||||
@@ -183,6 +209,9 @@ export function useGroupModerationData(deps) {
|
||||
debounce(groupMembersSearchDebounced, 200)();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function groupMembersSearchDebounced() {
|
||||
const groupId = groupMemberModeration.value.id;
|
||||
const search = memberSearch.value;
|
||||
@@ -208,7 +237,9 @@ export function useGroupModerationData(deps) {
|
||||
if (groupId === args.params.groupId) {
|
||||
tables.members.data = args.json.results.map((member) => ({
|
||||
...member,
|
||||
$selected: Boolean(selection.selectedUsers[member.userId])
|
||||
$selected: Boolean(
|
||||
selection.selectedUsers[member.userId]
|
||||
)
|
||||
}));
|
||||
}
|
||||
})
|
||||
@@ -219,6 +250,10 @@ export function useGroupModerationData(deps) {
|
||||
|
||||
// ── Bans ─────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupId
|
||||
*/
|
||||
async function getAllGroupBans(groupId) {
|
||||
tables.bans.data = [];
|
||||
const params = { groupId, n: 100, offset: 0 };
|
||||
@@ -229,7 +264,9 @@ export function useGroupModerationData(deps) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
const args = await groupRequest.getGroupBans(params);
|
||||
if (args && args.json) {
|
||||
if (groupMemberModeration.value.id !== args.params.groupId) {
|
||||
if (
|
||||
groupMemberModeration.value.id !== args.params.groupId
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
args.json.forEach((json) => {
|
||||
@@ -257,6 +294,10 @@ export function useGroupModerationData(deps) {
|
||||
|
||||
// ── Invites / Join Requests / Blocked ────────────────────────
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupId
|
||||
*/
|
||||
async function getAllGroupInvites(groupId) {
|
||||
tables.invites.data = [];
|
||||
const params = { groupId, n: 100, offset: 0 };
|
||||
@@ -267,7 +308,9 @@ export function useGroupModerationData(deps) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
const args = await groupRequest.getGroupInvites(params);
|
||||
if (args) {
|
||||
if (groupMemberModeration.value.id !== args.params.groupId) {
|
||||
if (
|
||||
groupMemberModeration.value.id !== args.params.groupId
|
||||
) {
|
||||
return;
|
||||
}
|
||||
for (const json of args.json) {
|
||||
@@ -291,6 +334,10 @@ export function useGroupModerationData(deps) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupId
|
||||
*/
|
||||
async function getAllGroupJoinRequests(groupId) {
|
||||
tables.joinRequests.data = [];
|
||||
const params = { groupId, n: 100, offset: 0, blocked: false };
|
||||
@@ -323,6 +370,10 @@ export function useGroupModerationData(deps) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupId
|
||||
*/
|
||||
async function getAllGroupBlockedRequests(groupId) {
|
||||
tables.blocked.data = [];
|
||||
const params = { groupId, n: 100, offset: 0, blocked: true };
|
||||
@@ -355,6 +406,10 @@ export function useGroupModerationData(deps) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupId
|
||||
*/
|
||||
async function getAllGroupInvitesAndJoinRequests(groupId) {
|
||||
try {
|
||||
await Promise.all([
|
||||
@@ -369,6 +424,11 @@ export function useGroupModerationData(deps) {
|
||||
|
||||
// ── Logs ─────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupId
|
||||
* @param eventTypes
|
||||
*/
|
||||
async function getAllGroupLogs(groupId, eventTypes = []) {
|
||||
tables.logs.data = [];
|
||||
const params = { groupId, n: 100, offset: 0 };
|
||||
@@ -382,11 +442,15 @@ export function useGroupModerationData(deps) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
const args = await groupRequest.getGroupLogs(params);
|
||||
if (args) {
|
||||
if (groupMemberModeration.value.id !== args.params.groupId) {
|
||||
if (
|
||||
groupMemberModeration.value.id !== args.params.groupId
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
for (const json of args.json.results) {
|
||||
const existsInData = newData.some((dataItem) => dataItem.id === json.id);
|
||||
const existsInData = newData.some(
|
||||
(dataItem) => dataItem.id === json.id
|
||||
);
|
||||
if (!existsInData) {
|
||||
newData.push(json);
|
||||
}
|
||||
@@ -410,10 +474,17 @@ export function useGroupModerationData(deps) {
|
||||
|
||||
// ── User Selection ───────────────────────────────────────────
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userId
|
||||
*/
|
||||
async function addGroupMemberToSelection(userId) {
|
||||
const D = groupMemberModeration.value;
|
||||
let member = {};
|
||||
const memberArgs = await groupRequest.getGroupMember({ groupId: D.id, userId });
|
||||
const memberArgs = await groupRequest.getGroupMember({
|
||||
groupId: D.id,
|
||||
userId
|
||||
});
|
||||
if (memberArgs && memberArgs.json) {
|
||||
member = applyGroupMember(memberArgs.json);
|
||||
}
|
||||
@@ -421,16 +492,21 @@ export function useGroupModerationData(deps) {
|
||||
selection.setSelectedUsers(member.userId, member);
|
||||
return;
|
||||
}
|
||||
const userArgs = await userRequest.getCachedUser({ userId });
|
||||
const userArgs = await queryRequest.fetch('user', { userId });
|
||||
member.userId = userArgs.json.id;
|
||||
member.user = userArgs.json;
|
||||
member.displayName = userArgs.json.displayName;
|
||||
selection.setSelectedUsers(member.userId, member);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userIdInput
|
||||
*/
|
||||
async function selectGroupMemberUserId(userIdInput) {
|
||||
if (!userIdInput) return;
|
||||
const regexUserId = /usr_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
|
||||
const regexUserId =
|
||||
/usr_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
|
||||
let match;
|
||||
const userIdList = new Set();
|
||||
while ((match = regexUserId.exec(userIdInput)) !== null) {
|
||||
@@ -448,6 +524,9 @@ export function useGroupModerationData(deps) {
|
||||
|
||||
// ── Reset ────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function resetData() {
|
||||
tables.members.data = [];
|
||||
tables.bans.data = [];
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
|
||||
import { hasGroupPermission, userImage, userStatusClass } from '../../shared/utils';
|
||||
import { useFriendStore, useGroupStore, useModalStore } from '../../stores';
|
||||
import { groupRequest, userRequest } from '../../api';
|
||||
import { groupRequest, queryRequest } from '../../api';
|
||||
import { VirtualCombobox } from '../ui/virtual-combobox';
|
||||
|
||||
import configRepository from '../../service/config';
|
||||
@@ -224,8 +224,8 @@
|
||||
inviteGroupDialog.value.groupName = '';
|
||||
return;
|
||||
}
|
||||
groupRequest
|
||||
.getCachedGroup({ groupId })
|
||||
queryRequest
|
||||
.fetch('group', { groupId })
|
||||
.then((args) => {
|
||||
inviteGroupDialog.value.groupName = args.ref.name;
|
||||
})
|
||||
@@ -242,8 +242,8 @@
|
||||
function initDialog() {
|
||||
const D = inviteGroupDialog.value;
|
||||
if (D.groupId) {
|
||||
groupRequest
|
||||
.getCachedGroup({
|
||||
queryRequest
|
||||
.fetch('group', {
|
||||
groupId: D.groupId
|
||||
})
|
||||
.then((args) => {
|
||||
@@ -256,7 +256,7 @@
|
||||
}
|
||||
|
||||
if (D.userId) {
|
||||
userRequest.getCachedUser({ userId: D.userId }).then((args) => {
|
||||
queryRequest.fetch('user', { userId: D.userId }).then((args) => {
|
||||
D.userObject = args.ref;
|
||||
D.userIds = [D.userId];
|
||||
});
|
||||
|
||||
@@ -162,7 +162,7 @@
|
||||
useModalStore
|
||||
} from '../../stores';
|
||||
import { checkCanInvite, getLaunchURL, isRealInstance, parseLocation } from '../../shared/utils';
|
||||
import { instanceRequest, worldRequest } from '../../api';
|
||||
import { instanceRequest, queryRequest } from '../../api';
|
||||
|
||||
import InviteDialog from './InviteDialog/InviteDialog.vue';
|
||||
import configRepository from '../../service/config';
|
||||
@@ -230,16 +230,23 @@
|
||||
|
||||
getConfig();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function closeInviteDialog() {
|
||||
inviteDialog.value.visible = false;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param tag
|
||||
*/
|
||||
function showInviteDialog(tag) {
|
||||
if (!isRealInstance(tag)) {
|
||||
return;
|
||||
}
|
||||
const L = parseLocation(tag);
|
||||
worldRequest
|
||||
.getCachedWorld({
|
||||
queryRequest
|
||||
.fetch('world', {
|
||||
worldId: L.worldId
|
||||
})
|
||||
.then((args) => {
|
||||
@@ -259,6 +266,12 @@
|
||||
D.visible = true;
|
||||
});
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param location
|
||||
* @param shortName
|
||||
* @param desktop
|
||||
*/
|
||||
function handleLaunchGame(location, shortName, desktop) {
|
||||
if (isGameRunning.value) {
|
||||
modalStore
|
||||
@@ -280,10 +293,21 @@
|
||||
isVisible.value = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param location
|
||||
* @param shortName
|
||||
*/
|
||||
function handleLaunchDefault(location, shortName) {
|
||||
handleLaunchGame(location, shortName, launchDialog.value.desktop);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param command
|
||||
* @param location
|
||||
* @param shortName
|
||||
*/
|
||||
function handleLaunchCommand(command, location, shortName) {
|
||||
const desktop = command === 'desktop';
|
||||
configRepository.setBool('launchAsDesktop', desktop);
|
||||
@@ -293,10 +317,20 @@
|
||||
launchDialog.value.desktop = desktop;
|
||||
}, 500);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param location
|
||||
* @param shortName
|
||||
*/
|
||||
function handleAttachGame(location, shortName) {
|
||||
tryOpenInstanceInVrc(location, shortName);
|
||||
isVisible.value = false;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param location
|
||||
* @param shortName
|
||||
*/
|
||||
function selfInvite(location, shortName) {
|
||||
const L = parseLocation(location);
|
||||
if (!L.isRealInstance) {
|
||||
@@ -314,9 +348,15 @@
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function getConfig() {
|
||||
configRepository.getBool('launchAsDesktop').then((value) => (launchDialog.value.desktop = value));
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function initLaunchDialog() {
|
||||
const { tag, shortName } = launchDialogData.value;
|
||||
if (!isRealInstance(tag)) {
|
||||
@@ -361,6 +401,10 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param input
|
||||
*/
|
||||
async function copyInstanceMessage(input) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(input);
|
||||
|
||||
@@ -63,9 +63,9 @@
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
import { groupRequest, userRequest } from '../../api';
|
||||
import { hasGroupModerationPermission, userImage } from '../../shared/utils';
|
||||
import { VirtualCombobox } from '../ui/virtual-combobox';
|
||||
import { queryRequest } from '../../api';
|
||||
import { useGroupStore } from '../../stores';
|
||||
|
||||
const { currentUserGroups, moderateGroupDialog } = storeToRefs(useGroupStore());
|
||||
@@ -114,8 +114,8 @@
|
||||
function initDialog() {
|
||||
const D = moderateGroupDialog.value;
|
||||
if (D.groupId) {
|
||||
groupRequest
|
||||
.getCachedGroup({
|
||||
queryRequest
|
||||
.fetch('group', {
|
||||
groupId: D.groupId
|
||||
})
|
||||
.then((args) => {
|
||||
@@ -127,7 +127,7 @@
|
||||
}
|
||||
|
||||
if (D.userId) {
|
||||
userRequest.getCachedUser({ userId: D.userId }).then((args) => {
|
||||
queryRequest.fetch('user', { userId: D.userId }).then((args) => {
|
||||
D.userObject = args.ref;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -580,7 +580,7 @@
|
||||
useUserStore
|
||||
} from '../../stores';
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '../ui/select';
|
||||
import { groupRequest, instanceRequest, worldRequest } from '../../api';
|
||||
import { groupRequest, instanceRequest, queryRequest } from '../../api';
|
||||
import { ToggleGroup, ToggleGroupItem } from '../ui/toggle-group';
|
||||
import { VirtualCombobox } from '../ui/virtual-combobox';
|
||||
|
||||
@@ -797,8 +797,8 @@
|
||||
return;
|
||||
}
|
||||
const L = parseLocation(tag);
|
||||
worldRequest
|
||||
.getCachedWorld({
|
||||
queryRequest
|
||||
.fetch('world', {
|
||||
worldId: L.worldId
|
||||
})
|
||||
.then((args) => {
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
import { miscRequest, notificationRequest, userRequest } from '../../api';
|
||||
import { miscRequest, notificationRequest, queryRequest } from '../../api';
|
||||
import { useGalleryStore, useNotificationStore, useUserStore } from '../../stores';
|
||||
import { VirtualCombobox } from '../ui/virtual-combobox';
|
||||
import { photonEmojis } from '../../shared/constants/photon.js';
|
||||
@@ -99,7 +99,7 @@
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
displayName.value = '';
|
||||
userRequest.getCachedUser({ userId: sendBoopDialog.value.userId }).then((user) => {
|
||||
queryRequest.fetch('user', { userId: sendBoopDialog.value.userId }).then((user) => {
|
||||
displayName.value = user.ref.displayName;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
import DeprecationAlert from '@/components/DeprecationAlert.vue';
|
||||
|
||||
import { useFavoriteStore, useUserStore, useWorldStore } from '../../../stores';
|
||||
import { favoriteRequest } from '../../../api';
|
||||
import { queryRequest } from '../../../api';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
@@ -121,7 +121,7 @@
|
||||
favoriteWorldsTab.value = '0';
|
||||
userDialog.value.userFavoriteWorlds = [];
|
||||
const worldLists = [];
|
||||
const groupArgs = await favoriteRequest.getCachedFavoriteGroups({
|
||||
const groupArgs = await queryRequest.fetch('favoriteGroups', {
|
||||
ownerId: userId,
|
||||
n: 100,
|
||||
offset: 0
|
||||
@@ -145,7 +145,7 @@
|
||||
tag: list.name
|
||||
};
|
||||
try {
|
||||
const args = await favoriteRequest.getCachedFavoriteWorlds(params);
|
||||
const args = await queryRequest.fetch('favoriteWorlds', params);
|
||||
handleFavoriteWorldList(args);
|
||||
return [list.displayName, list.visibility, args.json];
|
||||
} catch (err) {
|
||||
|
||||
@@ -87,8 +87,8 @@
|
||||
|
||||
import { useUserStore, useWorldStore } from '../../../stores';
|
||||
import { userDialogWorldOrderOptions, userDialogWorldSortingOptions } from '../../../shared/constants/';
|
||||
import { queryRequest } from '../../../api';
|
||||
import { useOptionKeySelect } from '../../../composables/useOptionKeySelect';
|
||||
import { worldRequest } from '../../../api';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
@@ -141,7 +141,7 @@
|
||||
try {
|
||||
let offset = 0;
|
||||
while (true) {
|
||||
const args = await worldRequest.getCachedWorlds({
|
||||
const args = await queryRequest.fetch('worldsByUser', {
|
||||
...params,
|
||||
offset
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
miscRequest,
|
||||
notificationRequest,
|
||||
playerModerationRequest,
|
||||
worldRequest
|
||||
queryRequest
|
||||
} from '../../../api';
|
||||
import { copyToClipboard, parseLocation } from '../../../shared/utils';
|
||||
import { database } from '../../../service/database';
|
||||
@@ -259,8 +259,8 @@ export function useUserDialogCommands(
|
||||
},
|
||||
'Invite Message': () => {
|
||||
const L = parseLocation(lastLocation.value.location);
|
||||
worldRequest
|
||||
.getCachedWorld({
|
||||
queryRequest
|
||||
.fetch('world', {
|
||||
worldId: L.worldId
|
||||
})
|
||||
.then((args) => {
|
||||
@@ -288,8 +288,8 @@ export function useUserDialogCommands(
|
||||
currentLocation = lastLocationDestination.value;
|
||||
}
|
||||
const L = parseLocation(currentLocation);
|
||||
worldRequest
|
||||
.getCachedWorld({
|
||||
queryRequest
|
||||
.fetch('world', {
|
||||
worldId: L.worldId
|
||||
})
|
||||
.then((args) => {
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
_entityCacheInternals,
|
||||
fetchWithEntityPolicy,
|
||||
patchAndRefetchActiveQuery,
|
||||
patchUserFromEvent,
|
||||
patchQueryDataWithRecency
|
||||
} from '../entityCache';
|
||||
import { queryClient } from '../client';
|
||||
@@ -130,4 +131,54 @@ describe('entity query cache helpers', () => {
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
test('internal completeness guard requires params + entity identifier', () => {
|
||||
expect(_entityCacheInternals.hasCompleteEntityData(undefined)).toBe(
|
||||
false
|
||||
);
|
||||
expect(_entityCacheInternals.hasCompleteEntityData({})).toBe(false);
|
||||
expect(
|
||||
_entityCacheInternals.hasCompleteEntityData({
|
||||
params: {}
|
||||
})
|
||||
).toBe(false);
|
||||
expect(
|
||||
_entityCacheInternals.hasCompleteEntityData({
|
||||
params: { userId: 'usr_1' }
|
||||
})
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test('patchUserFromEvent skips placeholder cache entries', () => {
|
||||
const queryKey = ['user', 'usr_1'];
|
||||
queryClient.setQueryData(queryKey, {
|
||||
params: {}
|
||||
});
|
||||
|
||||
patchUserFromEvent({
|
||||
id: 'usr_1',
|
||||
displayName: 'Alice'
|
||||
});
|
||||
|
||||
expect(queryClient.getQueryData(queryKey)).toEqual({
|
||||
params: {}
|
||||
});
|
||||
});
|
||||
|
||||
test('patchUserFromEvent patches when query has complete data', () => {
|
||||
const queryKey = ['user', 'usr_1'];
|
||||
queryClient.setQueryData(queryKey, {
|
||||
params: { userId: 'usr_1' },
|
||||
ref: { id: 'usr_1', displayName: 'Old' },
|
||||
json: { id: 'usr_1', displayName: 'Old' }
|
||||
});
|
||||
|
||||
patchUserFromEvent({
|
||||
id: 'usr_1',
|
||||
displayName: 'New'
|
||||
});
|
||||
|
||||
const data = queryClient.getQueryData(queryKey);
|
||||
expect(data.ref.displayName).toBe('New');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,13 +50,6 @@ describe('query policy configuration', () => {
|
||||
refetchOnWindowFocus: false
|
||||
});
|
||||
|
||||
expect(entityQueryPolicies.instance).toMatchObject({
|
||||
staleTime: 0,
|
||||
gcTime: 10000,
|
||||
retry: 0,
|
||||
refetchOnWindowFocus: false
|
||||
});
|
||||
|
||||
expect(entityQueryPolicies.friendList).toMatchObject({
|
||||
staleTime: 20000,
|
||||
gcTime: 90000,
|
||||
@@ -104,9 +97,6 @@ describe('query policy configuration', () => {
|
||||
expect(getEntityQueryPolicy('worldCollection')).toBe(
|
||||
entityQueryPolicies.worldCollection
|
||||
);
|
||||
expect(getEntityQueryPolicy('instance')).toBe(
|
||||
entityQueryPolicies.instance
|
||||
);
|
||||
expect(getEntityQueryPolicy('friendList')).toBe(
|
||||
entityQueryPolicies.friendList
|
||||
);
|
||||
|
||||
@@ -15,6 +15,10 @@ const RECENCY_FIELDS = [
|
||||
'createdAt'
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
function getComparableEntity(data) {
|
||||
if (!data || typeof data !== 'object') {
|
||||
return null;
|
||||
@@ -32,6 +36,10 @@ function getComparableEntity(data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
function parseTimestamp(value) {
|
||||
if (typeof value === 'number' && Number.isFinite(value)) {
|
||||
return value;
|
||||
@@ -45,6 +53,10 @@ function parseTimestamp(value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
function getRecencyTimestamp(data) {
|
||||
const comparable = getComparableEntity(data);
|
||||
if (!comparable) {
|
||||
@@ -61,6 +73,11 @@ function getRecencyTimestamp(data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param currentData
|
||||
* @param nextData
|
||||
*/
|
||||
function shouldReplaceCurrent(currentData, nextData) {
|
||||
if (typeof currentData === 'undefined') {
|
||||
return true;
|
||||
@@ -80,6 +97,35 @@ function shouldReplaceCurrent(currentData, nextData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
function hasCompleteEntityData(data) {
|
||||
if (!data || typeof data !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const params = data.params;
|
||||
if (!params || typeof params !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const hasEntityId = Boolean(
|
||||
data?.ref?.id ||
|
||||
data?.json?.id ||
|
||||
params.userId ||
|
||||
params.avatarId ||
|
||||
params.worldId ||
|
||||
params.groupId ||
|
||||
params.fileId ||
|
||||
params.printId ||
|
||||
params.inventoryId
|
||||
);
|
||||
|
||||
return hasEntityId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{queryKey: unknown[], nextData: any}} options
|
||||
*/
|
||||
@@ -142,7 +188,8 @@ export async function patchAndRefetchActiveQuery({ queryKey, nextData }) {
|
||||
export function patchUserFromEvent(ref) {
|
||||
if (!ref?.id) return;
|
||||
const queryKey = queryKeys.user(ref.id);
|
||||
if (!queryClient.getQueryData(queryKey)) return;
|
||||
const existing = queryClient.getQueryData(queryKey);
|
||||
if (!hasCompleteEntityData(existing)) return;
|
||||
patchQueryDataWithRecency({
|
||||
queryKey,
|
||||
nextData: {
|
||||
@@ -160,7 +207,8 @@ export function patchUserFromEvent(ref) {
|
||||
export function patchAvatarFromEvent(ref) {
|
||||
if (!ref?.id) return;
|
||||
const queryKey = queryKeys.avatar(ref.id);
|
||||
if (!queryClient.getQueryData(queryKey)) return;
|
||||
const existing = queryClient.getQueryData(queryKey);
|
||||
if (!hasCompleteEntityData(existing)) return;
|
||||
patchQueryDataWithRecency({
|
||||
queryKey,
|
||||
nextData: {
|
||||
@@ -178,7 +226,8 @@ export function patchAvatarFromEvent(ref) {
|
||||
export function patchWorldFromEvent(ref) {
|
||||
if (!ref?.id) return;
|
||||
const queryKey = queryKeys.world(ref.id);
|
||||
if (!queryClient.getQueryData(queryKey)) return;
|
||||
const existing = queryClient.getQueryData(queryKey);
|
||||
if (!hasCompleteEntityData(existing)) return;
|
||||
patchQueryDataWithRecency({
|
||||
queryKey,
|
||||
nextData: {
|
||||
@@ -204,7 +253,8 @@ export function patchGroupFromEvent(ref) {
|
||||
};
|
||||
|
||||
const keyFalse = queryKeys.group(ref.id, false);
|
||||
if (queryClient.getQueryData(keyFalse)) {
|
||||
const existingFalse = queryClient.getQueryData(keyFalse);
|
||||
if (hasCompleteEntityData(existingFalse)) {
|
||||
patchQueryDataWithRecency({
|
||||
queryKey: keyFalse,
|
||||
nextData
|
||||
@@ -212,7 +262,8 @@ export function patchGroupFromEvent(ref) {
|
||||
}
|
||||
|
||||
const keyTrue = queryKeys.group(ref.id, true);
|
||||
if (queryClient.getQueryData(keyTrue)) {
|
||||
const existingTrue = queryClient.getQueryData(keyTrue);
|
||||
if (hasCompleteEntityData(existingTrue)) {
|
||||
patchQueryDataWithRecency({
|
||||
queryKey: keyTrue,
|
||||
nextData
|
||||
@@ -220,30 +271,8 @@ export function patchGroupFromEvent(ref) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} ref
|
||||
*/
|
||||
export function patchInstanceFromEvent(ref) {
|
||||
if (!ref?.id) return;
|
||||
|
||||
const [worldId, instanceId] = String(ref.id).split(':');
|
||||
if (!worldId || !instanceId) return;
|
||||
|
||||
const queryKey = queryKeys.instance(worldId, instanceId);
|
||||
if (!queryClient.getQueryData(queryKey)) return;
|
||||
|
||||
patchQueryDataWithRecency({
|
||||
queryKey,
|
||||
nextData: {
|
||||
cache: false,
|
||||
json: ref,
|
||||
params: { worldId, instanceId },
|
||||
ref
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const _entityCacheInternals = {
|
||||
hasCompleteEntityData,
|
||||
getRecencyTimestamp,
|
||||
shouldReplaceCurrent
|
||||
};
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
export { queryClient } from './client';
|
||||
export { queryKeys } from './keys';
|
||||
export { entityQueryPolicies, getEntityQueryPolicy, toQueryOptions } from './policies';
|
||||
export {
|
||||
entityQueryPolicies,
|
||||
getEntityQueryPolicy,
|
||||
toQueryOptions
|
||||
} from './policies';
|
||||
export {
|
||||
fetchWithEntityPolicy,
|
||||
patchAndRefetchActiveQuery,
|
||||
@@ -9,6 +13,5 @@ export {
|
||||
patchAvatarFromEvent,
|
||||
patchWorldFromEvent,
|
||||
patchGroupFromEvent,
|
||||
patchInstanceFromEvent,
|
||||
refetchActiveEntityQuery
|
||||
} from './entityCache';
|
||||
|
||||
@@ -2,7 +2,11 @@ export const queryKeys = Object.freeze({
|
||||
user: (userId) => ['user', userId],
|
||||
avatar: (avatarId) => ['avatar', avatarId],
|
||||
world: (worldId) => ['world', worldId],
|
||||
group: (groupId, includeRoles = false) => ['group', groupId, Boolean(includeRoles)],
|
||||
group: (groupId, includeRoles = false) => [
|
||||
'group',
|
||||
groupId,
|
||||
Boolean(includeRoles)
|
||||
],
|
||||
groupPosts: ({ groupId, n = 100, offset = 0 } = {}) => [
|
||||
'group',
|
||||
groupId,
|
||||
@@ -12,8 +16,19 @@ export const queryKeys = Object.freeze({
|
||||
offset: Number(offset)
|
||||
}
|
||||
],
|
||||
groupMember: ({ groupId, userId } = {}) => ['group', groupId, 'member', userId],
|
||||
groupMembers: ({ groupId, n = 100, offset = 0, sort = '', roleId = '' } = {}) => [
|
||||
groupMember: ({ groupId, userId } = {}) => [
|
||||
'group',
|
||||
groupId,
|
||||
'member',
|
||||
userId
|
||||
],
|
||||
groupMembers: ({
|
||||
groupId,
|
||||
n = 100,
|
||||
offset = 0,
|
||||
sort = '',
|
||||
roleId = ''
|
||||
} = {}) => [
|
||||
'group',
|
||||
groupId,
|
||||
'members',
|
||||
@@ -41,7 +56,6 @@ export const queryKeys = Object.freeze({
|
||||
'calendarEvent',
|
||||
eventId
|
||||
],
|
||||
instance: (worldId, instanceId) => ['instance', worldId, instanceId],
|
||||
worldsByUser: ({
|
||||
userId,
|
||||
n = 50,
|
||||
@@ -91,7 +105,13 @@ export const queryKeys = Object.freeze({
|
||||
type: String(type || '')
|
||||
}
|
||||
],
|
||||
favoriteWorlds: ({ n = 300, offset = 0, ownerId = '', userId = '', tag = '' } = {}) => [
|
||||
favoriteWorlds: ({
|
||||
n = 300,
|
||||
offset = 0,
|
||||
ownerId = '',
|
||||
userId = '',
|
||||
tag = ''
|
||||
} = {}) => [
|
||||
'favorite',
|
||||
'worlds',
|
||||
{
|
||||
@@ -102,7 +122,13 @@ export const queryKeys = Object.freeze({
|
||||
tag: String(tag || '')
|
||||
}
|
||||
],
|
||||
favoriteAvatars: ({ n = 300, offset = 0, tag = '', ownerId = '', userId = '' } = {}) => [
|
||||
favoriteAvatars: ({
|
||||
n = 300,
|
||||
offset = 0,
|
||||
tag = '',
|
||||
ownerId = '',
|
||||
userId = ''
|
||||
} = {}) => [
|
||||
'favorite',
|
||||
'avatars',
|
||||
{
|
||||
@@ -129,7 +155,12 @@ export const queryKeys = Object.freeze({
|
||||
}
|
||||
],
|
||||
print: (printId) => ['gallery', 'print', printId],
|
||||
inventoryItems: ({ n = 100, offset = 0, order = 'newest', types = '' } = {}) => [
|
||||
inventoryItems: ({
|
||||
n = 100,
|
||||
offset = 0,
|
||||
order = 'newest',
|
||||
types = ''
|
||||
} = {}) => [
|
||||
'inventory',
|
||||
'items',
|
||||
{
|
||||
|
||||
@@ -37,12 +37,6 @@ export const entityQueryPolicies = Object.freeze({
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false
|
||||
}),
|
||||
instance: Object.freeze({
|
||||
staleTime: 0,
|
||||
gcTime: 10 * SECOND,
|
||||
retry: 0,
|
||||
refetchOnWindowFocus: false
|
||||
}),
|
||||
friendList: Object.freeze({
|
||||
staleTime: 20 * SECOND,
|
||||
gcTime: 90 * SECOND,
|
||||
@@ -76,7 +70,7 @@ export const entityQueryPolicies = Object.freeze({
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {'user'|'avatar'|'world'|'group'|'groupCollection'|'worldCollection'|'instance'|'friendList'|'favoriteCollection'|'galleryCollection'|'inventoryCollection'|'fileObject'} entity
|
||||
* @param {'user'|'avatar'|'world'|'group'|'groupCollection'|'worldCollection'|'friendList'|'favoriteCollection'|'galleryCollection'|'inventoryCollection'|'fileObject'} entity
|
||||
* @returns {{staleTime: number, gcTime: number, retry: number, refetchOnWindowFocus: boolean}}
|
||||
*/
|
||||
export function getEntityQueryPolicy(entity) {
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
|
||||
import { avatarRequest, groupRequest, instanceRequest, userRequest, worldRequest } from '../api';
|
||||
import { queryKeys } from './keys';
|
||||
import { avatarRequest, groupRequest, userRequest, worldRequest } from '../api';
|
||||
import { entityQueryPolicies, toQueryOptions } from './policies';
|
||||
import { queryKeys } from './keys';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userId
|
||||
* @param options
|
||||
*/
|
||||
export function useUserQuery(userId, options = {}) {
|
||||
return useQuery({
|
||||
...options,
|
||||
@@ -14,6 +19,11 @@ export function useUserQuery(userId, options = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param avatarId
|
||||
* @param options
|
||||
*/
|
||||
export function useAvatarQuery(avatarId, options = {}) {
|
||||
return useQuery({
|
||||
...options,
|
||||
@@ -24,6 +34,11 @@ export function useAvatarQuery(avatarId, options = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param worldId
|
||||
* @param options
|
||||
*/
|
||||
export function useWorldQuery(worldId, options = {}) {
|
||||
return useQuery({
|
||||
...options,
|
||||
@@ -34,6 +49,12 @@ export function useWorldQuery(worldId, options = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupId
|
||||
* @param includeRoles
|
||||
* @param options
|
||||
*/
|
||||
export function useGroupQuery(groupId, includeRoles = false, options = {}) {
|
||||
return useQuery({
|
||||
...options,
|
||||
@@ -43,13 +64,3 @@ export function useGroupQuery(groupId, includeRoles = false, options = {}) {
|
||||
...toQueryOptions(entityQueryPolicies.group)
|
||||
});
|
||||
}
|
||||
|
||||
export function useInstanceQuery(worldId, instanceId, options = {}) {
|
||||
return useQuery({
|
||||
...options,
|
||||
queryKey: queryKeys.instance(worldId, instanceId),
|
||||
queryFn: () => instanceRequest.getInstance({ worldId, instanceId }),
|
||||
enabled: Boolean(worldId && instanceId),
|
||||
...toQueryOptions(entityQueryPolicies.instance)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { groupRequest } from '../../api';
|
||||
import { parseLocation } from './location';
|
||||
import { queryRequest } from '../../api';
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -59,7 +59,7 @@ async function getGroupName(data) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
const args = await groupRequest.getCachedGroup({
|
||||
const args = await queryRequest.fetch('group', {
|
||||
groupId
|
||||
});
|
||||
groupName = args.ref.name;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { parseLocation } from './location';
|
||||
import { queryRequest } from '../../api';
|
||||
import { rpcWorlds } from '../constants';
|
||||
import { worldRequest } from '../../api';
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -13,7 +13,7 @@ async function getWorldName(location) {
|
||||
const L = parseLocation(location);
|
||||
if (L.isRealInstance && L.worldId) {
|
||||
try {
|
||||
const args = await worldRequest.getCachedWorld({
|
||||
const args = await queryRequest.fetch('world', {
|
||||
worldId: L.worldId
|
||||
});
|
||||
worldName = args.ref.name;
|
||||
|
||||
@@ -19,8 +19,8 @@ import { createOverlayDispatch } from '../notification/overlayDispatch';
|
||||
function makeDeps(overrides = {}) {
|
||||
return {
|
||||
getUserIdFromNoty: vi.fn(() => ''),
|
||||
userRequest: {
|
||||
getCachedUser: vi.fn().mockResolvedValue({ json: null })
|
||||
queryRequest: {
|
||||
fetch: vi.fn().mockResolvedValue({ json: null })
|
||||
},
|
||||
notificationsSettingsStore: {
|
||||
notificationTimeout: 5000
|
||||
@@ -66,7 +66,7 @@ describe('notyGetImage', () => {
|
||||
|
||||
test('looks up user currentAvatarThumbnailImageUrl when no image URLs', async () => {
|
||||
deps.getUserIdFromNoty.mockReturnValue('usr_abc');
|
||||
deps.userRequest.getCachedUser.mockResolvedValue({
|
||||
deps.queryRequest.fetch.mockResolvedValue({
|
||||
json: {
|
||||
currentAvatarThumbnailImageUrl: 'https://avatar.jpg'
|
||||
}
|
||||
@@ -80,7 +80,7 @@ describe('notyGetImage', () => {
|
||||
|
||||
test('returns profilePicOverride when available', async () => {
|
||||
deps.getUserIdFromNoty.mockReturnValue('usr_abc');
|
||||
deps.userRequest.getCachedUser.mockResolvedValue({
|
||||
deps.queryRequest.fetch.mockResolvedValue({
|
||||
json: {
|
||||
profilePicOverride: 'https://profile.jpg',
|
||||
currentAvatarThumbnailImageUrl: 'https://avatar.jpg'
|
||||
@@ -95,7 +95,7 @@ describe('notyGetImage', () => {
|
||||
test('returns userIcon when displayVRCPlusIconsAsAvatar is enabled', async () => {
|
||||
deps.getUserIdFromNoty.mockReturnValue('usr_abc');
|
||||
deps.appearanceSettingsStore.displayVRCPlusIconsAsAvatar = true;
|
||||
deps.userRequest.getCachedUser.mockResolvedValue({
|
||||
deps.queryRequest.fetch.mockResolvedValue({
|
||||
json: {
|
||||
userIcon: 'https://icon.jpg',
|
||||
profilePicOverride: 'https://profile.jpg',
|
||||
@@ -114,12 +114,12 @@ describe('notyGetImage', () => {
|
||||
|
||||
const result = await dispatch.notyGetImage({});
|
||||
expect(result).toBe('');
|
||||
expect(deps.userRequest.getCachedUser).not.toHaveBeenCalled();
|
||||
expect(deps.queryRequest.fetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('returns empty string when user lookup fails', async () => {
|
||||
deps.getUserIdFromNoty.mockReturnValue('usr_abc');
|
||||
deps.userRequest.getCachedUser.mockRejectedValue(
|
||||
deps.queryRequest.fetch.mockRejectedValue(
|
||||
new Error('Network error')
|
||||
);
|
||||
dispatch = createOverlayDispatch(deps);
|
||||
@@ -130,7 +130,7 @@ describe('notyGetImage', () => {
|
||||
|
||||
test('returns empty string when user has no json', async () => {
|
||||
deps.getUserIdFromNoty.mockReturnValue('usr_abc');
|
||||
deps.userRequest.getCachedUser.mockResolvedValue({ json: null });
|
||||
deps.queryRequest.fetch.mockResolvedValue({ json: null });
|
||||
dispatch = createOverlayDispatch(deps);
|
||||
|
||||
const result = await dispatch.notyGetImage({});
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
sanitizeEntityJson,
|
||||
storeAvatarImage
|
||||
} from '../shared/utils';
|
||||
import { avatarRequest, miscRequest } from '../api';
|
||||
import { avatarRequest, miscRequest, queryRequest } from '../api';
|
||||
import { AppDebug } from '../service/appConfig';
|
||||
import { database } from '../service/database';
|
||||
import { patchAvatarFromEvent } from '../queries';
|
||||
@@ -174,7 +174,7 @@ export const useAvatarStore = defineStore('Avatar', () => {
|
||||
}
|
||||
const loadAvatarRequest = forceRefresh
|
||||
? avatarRequest.getAvatar({ avatarId })
|
||||
: avatarRequest.getCachedAvatar({ avatarId });
|
||||
: queryRequest.fetch('avatar', { avatarId });
|
||||
loadAvatarRequest
|
||||
.then((args) => {
|
||||
const ref = applyAvatar(args.json);
|
||||
@@ -312,6 +312,9 @@ export const useAvatarStore = defineStore('Avatar', () => {
|
||||
return ref;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function resetCachedAvatarModerations() {
|
||||
cachedAvatarModerations.clear();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
removeFromArray,
|
||||
replaceReactiveObject
|
||||
} from '../shared/utils';
|
||||
import { avatarRequest, favoriteRequest } from '../api';
|
||||
import { avatarRequest, favoriteRequest, queryRequest } from '../api';
|
||||
import { database } from '../service/database';
|
||||
import { processBulk } from '../service/request';
|
||||
import { useAppearanceSettingsStore } from './settings/appearance';
|
||||
@@ -771,7 +771,7 @@ export const useFavoriteStore = defineStore('Favorite', () => {
|
||||
}
|
||||
isFavoriteLoading.value = true;
|
||||
try {
|
||||
const args = await favoriteRequest.getCachedFavoriteLimits();
|
||||
const args = await queryRequest.fetch('favoriteLimits');
|
||||
favoriteLimits.value = {
|
||||
...favoriteLimits.value,
|
||||
...args.json
|
||||
@@ -781,7 +781,7 @@ export const useFavoriteStore = defineStore('Favorite', () => {
|
||||
}
|
||||
let newFavoriteSortOrder = [];
|
||||
processBulk({
|
||||
fn: favoriteRequest.getCachedFavorites,
|
||||
fn: (params) => queryRequest.fetch('favorites', params),
|
||||
N: -1,
|
||||
params: {
|
||||
n: 300,
|
||||
@@ -884,7 +884,7 @@ export const useFavoriteStore = defineStore('Favorite', () => {
|
||||
offset: 0,
|
||||
tag
|
||||
};
|
||||
const args = await favoriteRequest.getCachedFavoriteAvatars(params);
|
||||
const args = await queryRequest.fetch('favoriteAvatars', params);
|
||||
handleFavoriteAvatarList(args);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
isRealInstance,
|
||||
migrateMemos
|
||||
} from '../shared/utils';
|
||||
import { friendRequest, userRequest } from '../api';
|
||||
import { friendRequest, queryRequest, userRequest } from '../api';
|
||||
import { AppDebug } from '../service/appConfig';
|
||||
import { createFriendPresenceCoordinator } from './coordinators/friendPresenceCoordinator';
|
||||
import { createFriendRelationshipCoordinator } from './coordinators/friendRelationshipCoordinator';
|
||||
@@ -259,6 +259,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
{ flush: 'sync' }
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function init() {
|
||||
const friendLogTableFiltersValue = JSON.parse(
|
||||
await configRepository.getString('VRCX_friendLogTableFilters', '[]')
|
||||
@@ -268,6 +271,10 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
|
||||
init();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ref
|
||||
*/
|
||||
function updateUserCurrentStatus(ref) {
|
||||
if (watchState.isFriendsLoaded) {
|
||||
refreshFriendsStatus(ref);
|
||||
@@ -281,6 +288,10 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
function handleFriendStatus(args) {
|
||||
const D = userStore.userDialog;
|
||||
if (D.visible === false || D.id !== args.params.userId) {
|
||||
@@ -292,6 +303,10 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
D.outgoingRequest = json.outgoingRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
function handleFriendDelete(args) {
|
||||
const D = userStore.userDialog;
|
||||
if (D.visible === false || D.id !== args.params.userId) {
|
||||
@@ -302,11 +317,19 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
deleteFriend(args.params.userId);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
function handleFriendAdd(args) {
|
||||
addFriendship(args.params.userId);
|
||||
addFriend(args.params.userId);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ref
|
||||
*/
|
||||
function userOnFriend(ref) {
|
||||
updateFriendship(ref);
|
||||
if (
|
||||
@@ -337,6 +360,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function updateLocalFavoriteFriends() {
|
||||
const favoriteStore = useFavoriteStore();
|
||||
localFavoriteFriends.clear();
|
||||
@@ -365,6 +391,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
updateSidebarFavorites();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function updateSidebarFavorites() {
|
||||
for (const ctx of friends.values()) {
|
||||
const isVIP = localFavoriteFriends.has(ctx.id);
|
||||
@@ -383,6 +412,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
friendPresenceCoordinator.runUpdateFriendFlow(id, stateInput);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function pendingOfflineWorkerFunction() {
|
||||
pendingOfflineWorker = workerTimers.setInterval(() => {
|
||||
friendPresenceCoordinator.runPendingOfflineTickFlow();
|
||||
@@ -510,7 +542,7 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} args
|
||||
* @param {object} args
|
||||
* @returns {Promise<*[]>}
|
||||
*/
|
||||
async function bulkRefreshFriends(args) {
|
||||
@@ -528,10 +560,14 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
intervalMs: 60_000
|
||||
});
|
||||
|
||||
/**
|
||||
*
|
||||
* @param offset
|
||||
*/
|
||||
async function fetchPage(offset) {
|
||||
const result = await executeWithBackoff(
|
||||
async () => {
|
||||
const { json } = await friendRequest.getCachedFriends({
|
||||
const { json } = await queryRequest.fetch('friends', {
|
||||
...args,
|
||||
n: PAGE_SIZE,
|
||||
offset
|
||||
@@ -553,6 +589,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
let stopFlag = false;
|
||||
const friends = [];
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function getNextOffset() {
|
||||
if (stopFlag) return null;
|
||||
const cur = nextOffset;
|
||||
@@ -561,6 +600,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
return cur;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function worker() {
|
||||
while (true) {
|
||||
const offset = getNextOffset();
|
||||
@@ -660,6 +702,10 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
await friendSyncCoordinator.runRefreshFriendsListFlow();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param forceUpdate
|
||||
*/
|
||||
function updateOnlineFriendCounter(forceUpdate = false) {
|
||||
const onlineFriendCounts =
|
||||
vipFriends.value.length + onlineFriends.value.length;
|
||||
@@ -672,6 +718,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function getAllUserStats() {
|
||||
let ref;
|
||||
let item;
|
||||
@@ -741,6 +790,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function getAllUserMutualCount() {
|
||||
const mutualCountMap = await database.getMutualCountForAllUsers();
|
||||
for (const [userId, mutualCount] of mutualCountMap.entries()) {
|
||||
@@ -1027,6 +1079,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function initFriendLogHistoryTable() {
|
||||
friendLogTable.value.loading = true;
|
||||
friendLogTable.value.data = await database.getFriendLogHistory();
|
||||
@@ -1052,6 +1107,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function tryApplyFriendOrder() {
|
||||
const lastUpdate = await configRepository.getString(
|
||||
`VRCX_lastStoreTime_${userStore.currentUser.id}`
|
||||
@@ -1135,6 +1193,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function restoreFriendNumber() {
|
||||
let message;
|
||||
let storedData = null;
|
||||
@@ -1186,6 +1247,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function applyFriendLogFriendOrderInReverse() {
|
||||
state.friendNumber = friends.size + 1;
|
||||
const friendLogTable = getFriendLogFriendOrder();
|
||||
@@ -1210,6 +1274,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
console.log('Applied friend order from friendLog');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function getFriendLogFriendOrder() {
|
||||
const result = [];
|
||||
for (let i = 0; i < friendLogTable.value.data.length; i++) {
|
||||
@@ -1235,6 +1302,12 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param friendLogTable
|
||||
* @param created_at
|
||||
* @param backupUserIds
|
||||
*/
|
||||
function parseFriendOrderBackup(friendLogTable, created_at, backupUserIds) {
|
||||
let i;
|
||||
const backupTable = [];
|
||||
@@ -1296,6 +1369,10 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userIdOrder
|
||||
*/
|
||||
function applyFriendOrderBackup(userIdOrder) {
|
||||
for (let i = 0; i < userIdOrder.length; i++) {
|
||||
const userId = userIdOrder[i];
|
||||
@@ -1316,6 +1393,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function applyFriendLogFriendOrder() {
|
||||
const friendLogTable = getFriendLogFriendOrder();
|
||||
if (state.friendNumber === 0) {
|
||||
@@ -1339,6 +1419,10 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
function confirmDeleteFriend(id) {
|
||||
modalStore
|
||||
.confirm({
|
||||
@@ -1355,6 +1439,9 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function initFriendsList() {
|
||||
await friendSyncCoordinator.runInitFriendsListFlow();
|
||||
}
|
||||
|
||||
@@ -9,12 +9,7 @@ import {
|
||||
getPrintLocalDate,
|
||||
openExternalLink
|
||||
} from '../shared/utils';
|
||||
import {
|
||||
inventoryRequest,
|
||||
userRequest,
|
||||
vrcPlusIconRequest,
|
||||
vrcPlusImageRequest
|
||||
} from '../api';
|
||||
import { queryRequest, vrcPlusImageRequest } from '../api';
|
||||
import { AppDebug } from '../service/appConfig';
|
||||
import { handleImageUploadInput } from '../shared/utils/imageUpload';
|
||||
import { router } from '../plugin/router';
|
||||
@@ -22,8 +17,6 @@ import { useAdvancedSettingsStore } from './settings/advanced';
|
||||
import { useModalStore } from './modal';
|
||||
import { watchState } from '../service/watchState';
|
||||
|
||||
import miscReq from '../api/misc';
|
||||
|
||||
import * as workerTimers from 'worker-timers';
|
||||
|
||||
export const useGalleryStore = defineStore('Gallery', () => {
|
||||
@@ -100,6 +93,10 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
{ flush: 'sync' }
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
function handleFilesList(args) {
|
||||
if (args.params.tag === 'gallery') {
|
||||
galleryTable.value = args.json.reverse();
|
||||
@@ -117,12 +114,19 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
function handleGalleryImageAdd(args) {
|
||||
if (Object.keys(galleryTable.value).length !== 0) {
|
||||
galleryTable.value.unshift(args.json);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function showGalleryPage() {
|
||||
galleryDialogVisible.value = true;
|
||||
if (router.currentRoute.value?.name === 'gallery') {
|
||||
@@ -132,6 +136,9 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
router.push({ name: 'gallery' });
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function loadGalleryData() {
|
||||
refreshGalleryTable();
|
||||
refreshVRCPlusIconsTable();
|
||||
@@ -141,14 +148,17 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
getInventory();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function refreshGalleryTable() {
|
||||
galleryDialogGalleryLoading.value = true;
|
||||
const params = {
|
||||
n: 100,
|
||||
tag: 'gallery'
|
||||
};
|
||||
vrcPlusIconRequest
|
||||
.getCachedFileList(params)
|
||||
queryRequest
|
||||
.fetch('galleryFiles', params)
|
||||
.then((args) => handleFilesList(args))
|
||||
.catch((error) => {
|
||||
console.error('Error fetching gallery files:', error);
|
||||
@@ -158,14 +168,17 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function refreshVRCPlusIconsTable() {
|
||||
galleryDialogIconsLoading.value = true;
|
||||
const params = {
|
||||
n: 100,
|
||||
tag: 'icon'
|
||||
};
|
||||
vrcPlusIconRequest
|
||||
.getCachedFileList(params)
|
||||
queryRequest
|
||||
.fetch('galleryFiles', params)
|
||||
.then((args) => handleFilesList(args))
|
||||
.catch((error) => {
|
||||
console.error('Error fetching VRC Plus icons:', error);
|
||||
@@ -175,6 +188,10 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param e
|
||||
*/
|
||||
function inviteImageUpload(e) {
|
||||
const { file } = handleImageUploadInput(e, {
|
||||
inputSelector: null,
|
||||
@@ -192,6 +209,9 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
r.readAsBinaryString(file);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function clearInviteImageUpload() {
|
||||
const buttonList = document.querySelectorAll(
|
||||
'.inviteImageUploadButton'
|
||||
@@ -200,14 +220,17 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
uploadImage.value = '';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function refreshStickerTable() {
|
||||
galleryDialogStickersLoading.value = true;
|
||||
const params = {
|
||||
n: 100,
|
||||
tag: 'sticker'
|
||||
};
|
||||
vrcPlusIconRequest
|
||||
.getCachedFileList(params)
|
||||
queryRequest
|
||||
.fetch('galleryFiles', params)
|
||||
.then((args) => handleFilesList(args))
|
||||
.catch((error) => {
|
||||
console.error('Error fetching stickers:', error);
|
||||
@@ -217,12 +240,22 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
function handleStickerAdd(args) {
|
||||
if (Object.keys(stickerTable.value).length !== 0) {
|
||||
stickerTable.value.unshift(args.json);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param displayName
|
||||
* @param userId
|
||||
* @param inventoryId
|
||||
*/
|
||||
async function trySaveStickerToFile(displayName, userId, inventoryId) {
|
||||
if (instanceStickersCache.value.includes(inventoryId)) {
|
||||
return;
|
||||
@@ -231,7 +264,7 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
if (instanceStickersCache.value.length > 100) {
|
||||
instanceStickersCache.value.shift();
|
||||
}
|
||||
const args = await inventoryRequest.getCachedUserInventoryItem({
|
||||
const args = await queryRequest.fetch('userInventoryItem', {
|
||||
inventoryId,
|
||||
userId
|
||||
});
|
||||
@@ -262,13 +295,16 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function refreshPrintTable() {
|
||||
galleryDialogPrintsLoading.value = true;
|
||||
const params = {
|
||||
n: 100
|
||||
};
|
||||
try {
|
||||
const args = await vrcPlusImageRequest.getCachedPrints(params);
|
||||
const args = await queryRequest.fetch('prints', params);
|
||||
args.json.sort((a, b) => {
|
||||
return (
|
||||
new Date(b.timestamp).getTime() -
|
||||
@@ -283,6 +319,10 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param printId
|
||||
*/
|
||||
function queueSavePrintToFile(printId) {
|
||||
if (state.printCache.includes(printId)) {
|
||||
return;
|
||||
@@ -304,8 +344,12 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param printId
|
||||
*/
|
||||
async function trySavePrintToFile(printId) {
|
||||
const args = await vrcPlusImageRequest.getCachedPrint({ printId });
|
||||
const args = await queryRequest.fetch('print', { printId });
|
||||
const imageUrl = args.json?.files?.image;
|
||||
if (!imageUrl) {
|
||||
console.error('Print image URL is missing', args);
|
||||
@@ -314,7 +358,7 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
const print = args.json;
|
||||
const createdAt = getPrintLocalDate(print);
|
||||
try {
|
||||
const owner = await userRequest.getCachedUser({
|
||||
const owner = await queryRequest.fetch('user', {
|
||||
userId: print.ownerId
|
||||
});
|
||||
console.log(
|
||||
@@ -349,14 +393,17 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
// #endregion
|
||||
// #region | Emoji
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function refreshEmojiTable() {
|
||||
galleryDialogEmojisLoading.value = true;
|
||||
const params = {
|
||||
n: 100,
|
||||
tag: 'emoji'
|
||||
};
|
||||
vrcPlusIconRequest
|
||||
.getCachedFileList(params)
|
||||
queryRequest
|
||||
.fetch('galleryFiles', params)
|
||||
.then((args) => handleFilesList(args))
|
||||
.catch((error) => {
|
||||
console.error('Error fetching emojis:', error);
|
||||
@@ -366,6 +413,9 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function getInventory() {
|
||||
inventoryTable.value = [];
|
||||
advancedSettingsStore.currentUserInventory.clear();
|
||||
@@ -378,8 +428,7 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
try {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
params.offset = i * params.n;
|
||||
const args =
|
||||
await inventoryRequest.getCachedInventoryItems(params);
|
||||
const args = await queryRequest.fetch('inventoryItems', params);
|
||||
for (const item of args.json.data) {
|
||||
advancedSettingsStore.currentUserInventory.set(
|
||||
item.id,
|
||||
@@ -400,6 +449,9 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function tryDeleteOldPrints() {
|
||||
if (!advancedSettingsStore.autoDeleteOldPrints) {
|
||||
return;
|
||||
@@ -435,6 +487,11 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
await refreshPrintTable();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param imageUrl
|
||||
* @param fileName
|
||||
*/
|
||||
function showFullscreenImageDialog(imageUrl, fileName) {
|
||||
if (!imageUrl) {
|
||||
return;
|
||||
@@ -445,6 +502,11 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
D.visible = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param inventoryId
|
||||
* @param userId
|
||||
*/
|
||||
function queueCheckInstanceInventory(inventoryId, userId) {
|
||||
if (
|
||||
state.instanceInventoryCache.includes(inventoryId) ||
|
||||
@@ -472,8 +534,13 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param inventoryId
|
||||
* @param userId
|
||||
*/
|
||||
async function trySaveEmojiToFile(inventoryId, userId) {
|
||||
const args = await inventoryRequest.getCachedUserInventoryItem({
|
||||
const args = await queryRequest.fetch('userInventoryItem', {
|
||||
inventoryId,
|
||||
userId
|
||||
});
|
||||
@@ -486,7 +553,7 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const userArgs = await userRequest.getCachedUser({
|
||||
const userArgs = await queryRequest.fetch('user', {
|
||||
userId: args.json.holderId
|
||||
});
|
||||
const displayName = userArgs.json?.displayName ?? '';
|
||||
@@ -537,6 +604,10 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fileId
|
||||
*/
|
||||
async function getCachedEmoji(fileId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let ref = cachedEmoji.get(fileId);
|
||||
@@ -544,8 +615,8 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
resolve(ref);
|
||||
return;
|
||||
}
|
||||
miscReq
|
||||
.getCachedFile({ fileId })
|
||||
queryRequest
|
||||
.fetch('file', { fileId })
|
||||
.then((args) => {
|
||||
cachedEmoji.set(fileId, args.json);
|
||||
resolve(args.json);
|
||||
|
||||
@@ -10,12 +10,7 @@ import {
|
||||
replaceBioSymbols,
|
||||
sanitizeEntityJson
|
||||
} from '../shared/utils';
|
||||
import {
|
||||
groupRequest,
|
||||
instanceRequest,
|
||||
userRequest,
|
||||
worldRequest
|
||||
} from '../api';
|
||||
import { groupRequest, instanceRequest, queryRequest } from '../api';
|
||||
import { database } from '../service/database';
|
||||
import { groupDialogFilterOptions } from '../shared/constants/';
|
||||
import { patchGroupFromEvent } from '../queries';
|
||||
@@ -195,8 +190,8 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
D.ownerDisplayName = ref.ownerId;
|
||||
D.visible = true;
|
||||
D.loading = false;
|
||||
userRequest
|
||||
.getCachedUser({
|
||||
queryRequest
|
||||
.fetch('user', {
|
||||
userId: ref.ownerId
|
||||
})
|
||||
.then((args1) => {
|
||||
@@ -221,10 +216,10 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function groupOwnerChange(ref, oldUserId, newUserId) {
|
||||
const oldUser = await userRequest.getCachedUser({
|
||||
const oldUser = await queryRequest.fetch('user', {
|
||||
userId: oldUserId
|
||||
});
|
||||
const newUser = await userRequest.getCachedUser({
|
||||
const newUser = await queryRequest.fetch('user', {
|
||||
userId: newUserId
|
||||
});
|
||||
const oldDisplayName = oldUser?.ref?.displayName;
|
||||
@@ -422,7 +417,7 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
let total = Infinity;
|
||||
let pages = 0;
|
||||
do {
|
||||
const args = await groupRequest.getCachedGroupPosts({
|
||||
const args = await queryRequest.fetch('groupPosts', {
|
||||
groupId: params.groupId,
|
||||
n,
|
||||
offset
|
||||
@@ -466,8 +461,8 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
|
||||
const refPromise = existingRef
|
||||
? Promise.resolve({ ref: existingRef })
|
||||
: groupRequest
|
||||
.getCachedGroup({ groupId, includeRoles: true })
|
||||
: queryRequest
|
||||
.fetch('group', { groupId, includeRoles: true })
|
||||
.then((args) => ({ ref: applyGroup(args.json), args }));
|
||||
|
||||
return refPromise
|
||||
@@ -507,8 +502,8 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
}
|
||||
for (const json of args.json.instances) {
|
||||
instanceStore.applyInstance(json);
|
||||
worldRequest
|
||||
.getCachedWorld({
|
||||
queryRequest
|
||||
.fetch('world', {
|
||||
worldId: json.world.id
|
||||
})
|
||||
.then((args1) => {
|
||||
@@ -521,16 +516,16 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
groupRequest
|
||||
.getCachedGroupCalendar(groupId)
|
||||
queryRequest
|
||||
.fetch('groupCalendar', { groupId })
|
||||
.then((args) => {
|
||||
if (groupDialog.value.id === args.params.groupId) {
|
||||
D.calendar = args.json.results;
|
||||
for (const event of D.calendar) {
|
||||
applyGroupEvent(event);
|
||||
// fetch again for isFollowing
|
||||
groupRequest
|
||||
.getCachedGroupCalendarEvent({
|
||||
queryRequest
|
||||
.fetch('groupCalendarEvent', {
|
||||
groupId,
|
||||
eventId: event.id
|
||||
})
|
||||
@@ -1175,7 +1170,7 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
|
||||
D.groupRef = {};
|
||||
D.auditLogTypes = [];
|
||||
groupRequest.getCachedGroup({ groupId }).then((args) => {
|
||||
queryRequest.fetch('group', { groupId }).then((args) => {
|
||||
D.groupRef = args.ref;
|
||||
if (hasGroupPermission(D.groupRef, 'group-audit-view')) {
|
||||
groupRequest.getGroupAuditLogTypes({ groupId }).then((args) => {
|
||||
|
||||
@@ -23,8 +23,8 @@ import {
|
||||
replaceBioSymbols
|
||||
} from '../shared/utils';
|
||||
import {
|
||||
groupRequest,
|
||||
instanceRequest,
|
||||
queryRequest,
|
||||
userRequest,
|
||||
worldRequest
|
||||
} from '../api';
|
||||
@@ -33,7 +33,6 @@ import {
|
||||
instanceContentSettings
|
||||
} from '../shared/constants';
|
||||
import { database } from '../service/database';
|
||||
import { patchInstanceFromEvent } from '../queries';
|
||||
import { resolveRef } from '../shared/utils/resolveRef';
|
||||
import { useAppearanceSettingsStore } from './settings/appearance';
|
||||
import { useFriendStore } from './friend';
|
||||
@@ -246,7 +245,7 @@ export const useInstanceStore = defineStore('Instance', () => {
|
||||
emptyDefault: { id: '', displayName: '' },
|
||||
idAlias: 'userId',
|
||||
nameKey: 'displayName',
|
||||
fetchFn: (id) => userRequest.getCachedUser({ userId: id })
|
||||
fetchFn: (id) => queryRequest.fetch('user', { userId: id })
|
||||
});
|
||||
}
|
||||
|
||||
@@ -259,7 +258,7 @@ export const useInstanceStore = defineStore('Instance', () => {
|
||||
emptyDefault: { id: '', name: '' },
|
||||
idAlias: 'worldId',
|
||||
nameKey: 'name',
|
||||
fetchFn: (id) => worldRequest.getCachedWorld({ worldId: id })
|
||||
fetchFn: (id) => queryRequest.fetch('world', { worldId: id })
|
||||
});
|
||||
}
|
||||
|
||||
@@ -272,7 +271,7 @@ export const useInstanceStore = defineStore('Instance', () => {
|
||||
emptyDefault: { id: '', name: '' },
|
||||
idAlias: 'groupId',
|
||||
nameKey: 'name',
|
||||
fetchFn: (id) => groupRequest.getCachedGroup({ groupId: id })
|
||||
fetchFn: (id) => queryRequest.fetch('group', { groupId: id })
|
||||
});
|
||||
}
|
||||
|
||||
@@ -340,8 +339,8 @@ export const useInstanceStore = defineStore('Instance', () => {
|
||||
location.worldId &&
|
||||
!worldStore.cachedWorlds.get(location.worldId)?.name
|
||||
) {
|
||||
worldRequest
|
||||
.getCachedWorld({ worldId: location.worldId })
|
||||
queryRequest
|
||||
.fetch('world', { worldId: location.worldId })
|
||||
.then((args) => {
|
||||
uiStore.setDialogCrumbLabel(
|
||||
'previous-instances-info',
|
||||
@@ -467,8 +466,8 @@ export const useInstanceStore = defineStore('Instance', () => {
|
||||
console.error('Error fetching world data:', error);
|
||||
});
|
||||
} else {
|
||||
worldRequest
|
||||
.getCachedWorld({
|
||||
queryRequest
|
||||
.fetch('world', {
|
||||
worldId: currentInstanceLocation.value.worldId
|
||||
})
|
||||
.then((args) => {
|
||||
@@ -537,8 +536,8 @@ export const useInstanceStore = defineStore('Instance', () => {
|
||||
}
|
||||
ref.$location = parseLocation(ref.location);
|
||||
if (ref.world?.id) {
|
||||
worldRequest
|
||||
.getCachedWorld({
|
||||
queryRequest
|
||||
.fetch('world', {
|
||||
worldId: ref.world.id
|
||||
})
|
||||
.then((args) => {
|
||||
@@ -577,7 +576,6 @@ export const useInstanceStore = defineStore('Instance', () => {
|
||||
}
|
||||
}
|
||||
lastInstanceApplied.value = ref.id;
|
||||
patchInstanceFromEvent(ref);
|
||||
return ref;
|
||||
}
|
||||
|
||||
@@ -591,7 +589,7 @@ export const useInstanceStore = defineStore('Instance', () => {
|
||||
const L = parseLocation(location);
|
||||
if (L.isRealInstance && L.worldId && L.instanceId) {
|
||||
try {
|
||||
const args = await instanceRequest.getCachedInstance({
|
||||
const args = await instanceRequest.getInstance({
|
||||
worldId: L.worldId,
|
||||
instanceId: L.instanceId
|
||||
});
|
||||
|
||||
@@ -23,8 +23,7 @@ import {
|
||||
friendRequest,
|
||||
instanceRequest,
|
||||
notificationRequest,
|
||||
userRequest,
|
||||
worldRequest
|
||||
queryRequest
|
||||
} from '../../api';
|
||||
import {
|
||||
getNotificationMessage,
|
||||
@@ -216,7 +215,7 @@ export const useNotificationStore = defineStore('Notification', () => {
|
||||
// get instance name for invite
|
||||
const L = parseLocation(ref.details.worldId);
|
||||
if (L.isRealInstance) {
|
||||
instanceRequest.getCachedInstance({
|
||||
instanceRequest.getInstance({
|
||||
worldId: L.worldId,
|
||||
instanceId: L.instanceId
|
||||
});
|
||||
@@ -350,8 +349,8 @@ export const useNotificationStore = defineStore('Notification', () => {
|
||||
}
|
||||
|
||||
const L = parseLocation(currentLocation);
|
||||
worldRequest
|
||||
.getCachedWorld({
|
||||
queryRequest
|
||||
.fetch('world', {
|
||||
worldId: L.worldId
|
||||
})
|
||||
.then((args1) => {
|
||||
@@ -401,6 +400,9 @@ export const useNotificationStore = defineStore('Notification', () => {
|
||||
notificationInitStatus.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function clearUnseenNotifications() {
|
||||
unseenNotifications.value = [];
|
||||
}
|
||||
@@ -996,7 +998,7 @@ export const useNotificationStore = defineStore('Notification', () => {
|
||||
displayOvrtNotification
|
||||
} = createOverlayDispatch({
|
||||
getUserIdFromNoty,
|
||||
userRequest,
|
||||
queryRequest,
|
||||
notificationsSettingsStore,
|
||||
advancedSettingsStore,
|
||||
appearanceSettingsStore
|
||||
@@ -1285,8 +1287,8 @@ export const useNotificationStore = defineStore('Notification', () => {
|
||||
currentLocation = userStore.currentUser?.$locationTag;
|
||||
}
|
||||
const L = parseLocation(currentLocation);
|
||||
worldRequest
|
||||
.getCachedWorld({ worldId: L.worldId })
|
||||
queryRequest
|
||||
.fetch('world', { worldId: L.worldId })
|
||||
.then((args) => {
|
||||
notificationRequest
|
||||
.sendInvite(
|
||||
|
||||
@@ -6,10 +6,9 @@ import {
|
||||
|
||||
/**
|
||||
* Creates the overlay dispatch functions for the Notification store.
|
||||
*
|
||||
* @param {object} deps
|
||||
* @param {Function} deps.getUserIdFromNoty
|
||||
* @param {object} deps.userRequest
|
||||
* @param {object} deps.queryRequest
|
||||
* @param {object} deps.notificationsSettingsStore
|
||||
* @param {object} deps.advancedSettingsStore
|
||||
* @param {object} deps.appearanceSettingsStore
|
||||
@@ -17,7 +16,7 @@ import {
|
||||
*/
|
||||
export function createOverlayDispatch({
|
||||
getUserIdFromNoty,
|
||||
userRequest,
|
||||
queryRequest,
|
||||
notificationsSettingsStore,
|
||||
advancedSettingsStore,
|
||||
appearanceSettingsStore
|
||||
@@ -54,6 +53,12 @@ export function createOverlayDispatch({
|
||||
return imageLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param noty
|
||||
* @param message
|
||||
* @param image
|
||||
*/
|
||||
function displayDesktopToast(noty, message, image) {
|
||||
const result = getNotificationMessage(noty, message);
|
||||
if (result) {
|
||||
@@ -100,6 +105,14 @@ export function createOverlayDispatch({
|
||||
AppApi.XSNotification('VRCX', text, timeout, opacity, image);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param playOvrtHudNotifications
|
||||
* @param playOvrtWristNotifications
|
||||
* @param noty
|
||||
* @param message
|
||||
* @param image
|
||||
*/
|
||||
function displayOvrtNotification(
|
||||
playOvrtHudNotifications,
|
||||
playOvrtWristNotifications,
|
||||
@@ -146,8 +159,8 @@ export function createOverlayDispatch({
|
||||
} else if (noty.imageUrl) {
|
||||
imageUrl = noty.imageUrl;
|
||||
} else if (userId && !userId.startsWith('grp_')) {
|
||||
imageUrl = await userRequest
|
||||
.getCachedUser({
|
||||
imageUrl = await queryRequest
|
||||
.fetch('user', {
|
||||
userId
|
||||
})
|
||||
.catch((err) => {
|
||||
|
||||
@@ -19,12 +19,12 @@ import {
|
||||
ActivityType,
|
||||
StatusDisplayType
|
||||
} from '../../shared/constants/discord';
|
||||
import { queryRequest } from '../../api';
|
||||
import { useGameLogStore } from '../gameLog';
|
||||
import { useGameStore } from '../game';
|
||||
import { useLocationStore } from '../location';
|
||||
import { useUpdateLoopStore } from '../updateLoop';
|
||||
import { useUserStore } from '../user';
|
||||
import { worldRequest } from '../../api';
|
||||
|
||||
import configRepository from '../../service/config';
|
||||
|
||||
@@ -221,7 +221,7 @@ export const useDiscordPresenceSettingsStore = defineStore(
|
||||
groupAccessName: ''
|
||||
};
|
||||
try {
|
||||
const args = await worldRequest.getCachedWorld({
|
||||
const args = await queryRequest.fetch('world', {
|
||||
worldId: L.worldId
|
||||
});
|
||||
state.lastLocationDetails.worldName = args.ref.name;
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
avatarRequest,
|
||||
groupRequest,
|
||||
instanceRequest,
|
||||
queryRequest,
|
||||
userRequest
|
||||
} from '../api';
|
||||
import { processBulk, request } from '../service/request';
|
||||
@@ -715,8 +716,8 @@ export const useUserStore = defineStore('User', () => {
|
||||
});
|
||||
}
|
||||
AppApi.SendIpc('ShowUserDialog', userId);
|
||||
userRequest
|
||||
.getCachedUser({
|
||||
queryRequest
|
||||
.fetch('user', {
|
||||
userId
|
||||
})
|
||||
.catch((err) => {
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
SEARCH_LIMIT_MAX,
|
||||
SEARCH_LIMIT_MIN
|
||||
} from '../shared/constants';
|
||||
import { avatarRequest, worldRequest } from '../api';
|
||||
import { avatarRequest, queryRequest } from '../api';
|
||||
import {
|
||||
clearPiniaActionTrail,
|
||||
getPiniaActionTrail
|
||||
@@ -684,7 +684,7 @@ export const useVrcxStore = defineStore('Vrcx', () => {
|
||||
toast.error('Invalid local favorite world command');
|
||||
break;
|
||||
}
|
||||
worldRequest.getCachedWorld({ worldId: id }).then(() => {
|
||||
queryRequest.fetch('world', { worldId: id }).then(() => {
|
||||
searchStore.directAccessWorld(id);
|
||||
favoriteStore.addLocalWorldFavorite(id, group);
|
||||
});
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
|
||||
import { isRealInstance, parseLocation, userImage, userStatusClass } from '../../../shared/utils';
|
||||
import { useGameStore, useLaunchStore, useLocationStore, useUserStore } from '../../../stores';
|
||||
import { instanceRequest, notificationRequest, worldRequest } from '../../../api';
|
||||
import { instanceRequest, notificationRequest, queryRequest } from '../../../api';
|
||||
import { checkCanInvite, checkCanInviteSelf } from '../../../shared/utils/invite.js';
|
||||
|
||||
import Location from '../../../components/Location.vue';
|
||||
@@ -186,7 +186,7 @@
|
||||
currentLocation = lastLocationDestination.value;
|
||||
}
|
||||
const L = parseLocation(currentLocation);
|
||||
worldRequest.getCachedWorld({ worldId: L.worldId }).then((args) => {
|
||||
queryRequest.fetch('world', { worldId: L.worldId }).then((args) => {
|
||||
notificationRequest
|
||||
.sendInvite(
|
||||
{
|
||||
|
||||
@@ -94,14 +94,12 @@ const {
|
||||
mockSendRequestInvite,
|
||||
mockSendInvite,
|
||||
mockSelfInvite,
|
||||
mockGetCachedWorld
|
||||
mockQueryFetch
|
||||
} = vi.hoisted(() => ({
|
||||
mockSendRequestInvite: vi.fn().mockResolvedValue({}),
|
||||
mockSendInvite: vi.fn().mockResolvedValue({}),
|
||||
mockSelfInvite: vi.fn().mockResolvedValue({}),
|
||||
mockGetCachedWorld: vi
|
||||
.fn()
|
||||
.mockResolvedValue({ ref: { name: 'Test World' } })
|
||||
mockQueryFetch: vi.fn().mockResolvedValue({ ref: { name: 'Test World' } })
|
||||
}));
|
||||
|
||||
vi.mock('../../../../api', () => {
|
||||
@@ -116,9 +114,7 @@ vi.mock('../../../../api', () => {
|
||||
return {
|
||||
request: p(),
|
||||
userRequest: p(),
|
||||
worldRequest: p({
|
||||
getCachedWorld: (...args) => mockGetCachedWorld(...args)
|
||||
}),
|
||||
worldRequest: p(),
|
||||
instanceRequest: p({
|
||||
selfInvite: (...args) => mockSelfInvite(...args)
|
||||
}),
|
||||
@@ -139,7 +135,10 @@ vi.mock('../../../../api', () => {
|
||||
groupRequest: p(),
|
||||
inventoryRequest: p(),
|
||||
propRequest: p(),
|
||||
imageRequest: p()
|
||||
imageRequest: p(),
|
||||
queryRequest: p({
|
||||
fetch: (...args) => mockQueryFetch(...args)
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@
|
||||
} from '../../../stores';
|
||||
import { buildFriendRow, buildInstanceHeaderRow, buildToggleRow, estimateRowSize } from '../friendsSidebarUtils';
|
||||
import { getFriendsSortFunction, isRealInstance, userImage, userStatusClass } from '../../../shared/utils';
|
||||
import { instanceRequest, notificationRequest, userRequest, worldRequest } from '../../../api';
|
||||
import { instanceRequest, notificationRequest, queryRequest, userRequest } from '../../../api';
|
||||
import { checkCanInvite, checkCanInviteSelf } from '../../../shared/utils/invite.js';
|
||||
import { getFriendsLocations } from '../../../shared/utils/location.js';
|
||||
import { parseLocation } from '../../../shared/utils';
|
||||
@@ -753,7 +753,7 @@
|
||||
currentLocation = lastLocationDestination.value;
|
||||
}
|
||||
const L = parseLocation(currentLocation);
|
||||
worldRequest.getCachedWorld({ worldId: L.worldId }).then((args) => {
|
||||
queryRequest.fetch('world', { worldId: L.worldId }).then((args) => {
|
||||
notificationRequest
|
||||
.sendInvite(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user