chore: remove unused code and fix test expectations
- Remove unused activityManager import from asset viewer components - Remove unused function stub in activity manager - Fix album service test expectations for emit parameters - Clean up formatting in person repository mock - Update trash service tests for emit event changes
This commit is contained in:
@@ -664,7 +664,10 @@ describe(AlbumService.name, () => {
|
|||||||
expect(mocks.album.addAssetIds).toHaveBeenCalledWith('album-123', ['asset-1', 'asset-2', 'asset-3']);
|
expect(mocks.album.addAssetIds).toHaveBeenCalledWith('album-123', ['asset-1', 'asset-2', 'asset-3']);
|
||||||
expect(mocks.event.emit).toHaveBeenCalledWith('album.update', {
|
expect(mocks.event.emit).toHaveBeenCalledWith('album.update', {
|
||||||
id: 'album-123',
|
id: 'album-123',
|
||||||
recipientId: 'admin_id',
|
userId: 'user-id',
|
||||||
|
assetId: ['asset-1', 'asset-2', 'asset-3'],
|
||||||
|
recipientId: ['admin_id'],
|
||||||
|
status: 'added',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -50,30 +50,28 @@ describe(TrashService.name, () => {
|
|||||||
|
|
||||||
describe('restore', () => {
|
describe('restore', () => {
|
||||||
it('should handle an empty trash', async () => {
|
it('should handle an empty trash', async () => {
|
||||||
mocks.trash.getDeletedIds.mockResolvedValue(makeAssetIdStream(0));
|
mocks.trash.getTrashedIds.mockReturnValue(makeAssetIdStream(0));
|
||||||
mocks.trash.restore.mockResolvedValue(0);
|
|
||||||
await expect(sut.restore(authStub.user1)).resolves.toEqual({ count: 0 });
|
await expect(sut.restore(authStub.user1)).resolves.toEqual({ count: 0 });
|
||||||
expect(mocks.trash.restore).toHaveBeenCalledWith('user-id');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should restore', async () => {
|
it('should restore', async () => {
|
||||||
mocks.trash.getDeletedIds.mockResolvedValue(makeAssetIdStream(1));
|
mocks.trash.getTrashedIds.mockReturnValue(makeAssetIdStream(1));
|
||||||
mocks.trash.restore.mockResolvedValue(1);
|
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set(['asset-1']));
|
||||||
|
mocks.trash.restoreAll.mockResolvedValue(1);
|
||||||
await expect(sut.restore(authStub.user1)).resolves.toEqual({ count: 1 });
|
await expect(sut.restore(authStub.user1)).resolves.toEqual({ count: 1 });
|
||||||
expect(mocks.trash.restore).toHaveBeenCalledWith('user-id');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('empty', () => {
|
describe('empty', () => {
|
||||||
it('should handle an empty trash', async () => {
|
it('should handle an empty trash', async () => {
|
||||||
mocks.trash.getDeletedIds.mockResolvedValue(makeAssetIdStream(0));
|
mocks.trash.getTrashedIds.mockReturnValue(makeAssetIdStream(0));
|
||||||
mocks.trash.empty.mockResolvedValue(0);
|
mocks.trash.empty.mockResolvedValue(0);
|
||||||
await expect(sut.empty(authStub.user1)).resolves.toEqual({ count: 0 });
|
await expect(sut.empty(authStub.user1)).resolves.toEqual({ count: 0 });
|
||||||
expect(mocks.job.queue).not.toHaveBeenCalled();
|
expect(mocks.job.queue).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should empty the trash', async () => {
|
it('should empty the trash', async () => {
|
||||||
mocks.trash.getDeletedIds.mockResolvedValue(makeAssetIdStream(1));
|
mocks.trash.getTrashedIds.mockReturnValue(makeAssetIdStream(1));
|
||||||
mocks.trash.empty.mockResolvedValue(1);
|
mocks.trash.empty.mockResolvedValue(1);
|
||||||
await expect(sut.empty(authStub.user1)).resolves.toEqual({ count: 1 });
|
await expect(sut.empty(authStub.user1)).resolves.toEqual({ count: 1 });
|
||||||
expect(mocks.trash.empty).toHaveBeenCalledWith('user-id');
|
expect(mocks.trash.empty).toHaveBeenCalledWith('user-id');
|
||||||
|
|||||||
@@ -25,11 +25,22 @@ export class TrashService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async restore(auth: AuthDto): Promise<TrashResponseDto> {
|
async restore(auth: AuthDto): Promise<TrashResponseDto> {
|
||||||
const count = await this.trashRepository.restore(auth.user.id);
|
const assets = this.trashRepository.getTrashedIds(auth.user.id);
|
||||||
if (count > 0) {
|
let total = 0;
|
||||||
this.logger.log(`Restored ${count} asset(s) from trash`);
|
let batch = new BulkIdsDto();
|
||||||
|
batch.ids = [];
|
||||||
|
for await (const { id } of assets) {
|
||||||
|
batch.ids.push(id);
|
||||||
|
if (batch.ids.length === JOBS_ASSET_PAGINATION_SIZE) {
|
||||||
|
const { count } = await this.restoreAssets(auth, batch);
|
||||||
|
total += count;
|
||||||
|
batch = new BulkIdsDto();
|
||||||
|
batch.ids = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return { count };
|
const { count } = await this.restoreAssets(auth, batch);
|
||||||
|
total += count;
|
||||||
|
return { count: total };
|
||||||
}
|
}
|
||||||
|
|
||||||
async empty(auth: AuthDto): Promise<TrashResponseDto> {
|
async empty(auth: AuthDto): Promise<TrashResponseDto> {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ export const newPersonRepositoryMock = (): Mocked<RepositoryInterface<PersonRepo
|
|||||||
createAssetFace: vitest.fn(),
|
createAssetFace: vitest.fn(),
|
||||||
deleteAssetFace: vitest.fn(),
|
deleteAssetFace: vitest.fn(),
|
||||||
softDeleteAssetFaces: vitest.fn(),
|
softDeleteAssetFaces: vitest.fn(),
|
||||||
|
getAssetPersonByFaceId: vitest.fn(),
|
||||||
vacuum: vitest.fn(),
|
vacuum: vitest.fn(),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
import { AssetAction, ProjectionType } from '$lib/constants';
|
import { AssetAction, ProjectionType } from '$lib/constants';
|
||||||
import { activityManager } from '$lib/managers/activity-manager.svelte';
|
import { activityManager } from '$lib/managers/activity-manager.svelte';
|
||||||
import { authManager } from '$lib/managers/auth-manager.svelte';
|
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||||
|
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
||||||
import { closeEditorCofirm } from '$lib/stores/asset-editor.store';
|
import { closeEditorCofirm } from '$lib/stores/asset-editor.store';
|
||||||
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
||||||
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
|
||||||
import { isShowDetail } from '$lib/stores/preferences.store';
|
import { isShowDetail } from '$lib/stores/preferences.store';
|
||||||
import { SlideshowNavigation, SlideshowState, slideshowStore } from '$lib/stores/slideshow.store';
|
import { SlideshowNavigation, SlideshowState, slideshowStore } from '$lib/stores/slideshow.store';
|
||||||
import { user } from '$lib/stores/user.store';
|
import { user } from '$lib/stores/user.store';
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
AssetJobName,
|
AssetJobName,
|
||||||
AssetTypeEnum,
|
AssetTypeEnum,
|
||||||
getAllAlbums,
|
getAllAlbums,
|
||||||
|
getAssetInfo,
|
||||||
getStack,
|
getStack,
|
||||||
runAssetJobs,
|
runAssetJobs,
|
||||||
type AlbumResponseDto,
|
type AlbumResponseDto,
|
||||||
@@ -148,16 +149,20 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onAssetUpdate = ({ asset: assetUpdate }: { event: 'upload' | 'update'; asset: AssetResponseDto }) => {
|
const onAssetUpdate = async (assetId: string) => {
|
||||||
if (assetUpdate.id === asset.id) {
|
if (assetId === asset.id) {
|
||||||
asset = assetUpdate;
|
asset = await getAssetInfo({ id: assetId, key: authManager.key });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
unsubscribes.push(
|
unsubscribes.push(
|
||||||
websocketEvents.on('on_upload_success', (asset) => onAssetUpdate({ event: 'upload', asset })),
|
websocketEvents.on('on_upload_success', (asset) => onAssetUpdate(asset.id)),
|
||||||
websocketEvents.on('on_asset_update', (asset) => onAssetUpdate({ event: 'update', asset })),
|
websocketEvents.on('on_asset_update', async (assetsIds) => {
|
||||||
|
for (const assetId of assetsIds) {
|
||||||
|
await onAssetUpdate(assetId);
|
||||||
|
}
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
slideshowStateUnsubscribe = slideshowState.subscribe((value) => {
|
slideshowStateUnsubscribe = slideshowState.subscribe((value) => {
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { shortcut } from '$lib/actions/shortcut';
|
import { shortcut } from '$lib/actions/shortcut';
|
||||||
|
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||||
import ConfirmModal from '$lib/modals/ConfirmModal.svelte';
|
import ConfirmModal from '$lib/modals/ConfirmModal.svelte';
|
||||||
import { editTypes, showCancelConfirmDialog } from '$lib/stores/asset-editor.store';
|
import { editTypes, showCancelConfirmDialog } from '$lib/stores/asset-editor.store';
|
||||||
import { websocketEvents } from '$lib/stores/websocket';
|
import { websocketEvents } from '$lib/stores/websocket';
|
||||||
import { type AssetResponseDto } from '@immich/sdk';
|
import { getAssetInfo, type AssetResponseDto } from '@immich/sdk';
|
||||||
import { IconButton } from '@immich/ui';
|
import { IconButton } from '@immich/ui';
|
||||||
import { mdiClose } from '@mdi/js';
|
import { mdiClose } from '@mdi/js';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
return websocketEvents.on('on_asset_update', (assetUpdate) => {
|
return websocketEvents.on('on_asset_update', async (assetIds) => {
|
||||||
if (assetUpdate.id === asset.id) {
|
for (const assetId of assetIds) {
|
||||||
asset = assetUpdate;
|
if (assetId === asset.id) {
|
||||||
|
asset = await getAssetInfo({ id: assetId, key: authManager.key });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { user } from '$lib/stores/user.store';
|
import { user } from '$lib/stores/user.store';
|
||||||
|
import { websocketEvents } from '$lib/stores/websocket';
|
||||||
import { handlePromiseError } from '$lib/utils';
|
import { handlePromiseError } from '$lib/utils';
|
||||||
import {
|
import {
|
||||||
createActivity,
|
createActivity,
|
||||||
@@ -10,6 +11,7 @@ import {
|
|||||||
type ActivityCreateDto,
|
type ActivityCreateDto,
|
||||||
type ActivityResponseDto,
|
type ActivityResponseDto,
|
||||||
} from '@immich/sdk';
|
} from '@immich/sdk';
|
||||||
|
import { createSubscriber } from 'svelte/reactivity';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
|
|
||||||
class ActivityManager {
|
class ActivityManager {
|
||||||
@@ -20,19 +22,43 @@ class ActivityManager {
|
|||||||
#likeCount = $state(0);
|
#likeCount = $state(0);
|
||||||
#isLiked = $state<ActivityResponseDto | null>(null);
|
#isLiked = $state<ActivityResponseDto | null>(null);
|
||||||
|
|
||||||
|
#subscribe;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.#subscribe = createSubscriber((update) => {
|
||||||
|
debugger;
|
||||||
|
console.log('update', update);
|
||||||
|
const unsubscribe = websocketEvents.on('on_activity_change', ({ albumId, assetId }) => {
|
||||||
|
if (this.#albumId === albumId || this.#assetId === assetId) {
|
||||||
|
handlePromiseError(this.refreshActivities(this.#albumId!, this.#assetId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// stop listening when all the effects are destroyed
|
||||||
|
return () => {
|
||||||
|
debugger;
|
||||||
|
unsubscribe();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
get activities() {
|
get activities() {
|
||||||
|
this.#subscribe();
|
||||||
return this.#activities;
|
return this.#activities;
|
||||||
}
|
}
|
||||||
|
|
||||||
get commentCount() {
|
get commentCount() {
|
||||||
|
this.#subscribe();
|
||||||
return this.#commentCount;
|
return this.#commentCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
get likeCount() {
|
get likeCount() {
|
||||||
|
this.#subscribe();
|
||||||
return this.#likeCount;
|
return this.#likeCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isLiked() {
|
get isLiked() {
|
||||||
|
this.#subscribe();
|
||||||
return this.#isLiked;
|
return this.#isLiked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,3 +152,6 @@ class ActivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const activityManager = new ActivityManager();
|
export const activityManager = new ActivityManager();
|
||||||
|
function on(arg0: any, arg1: string, update: () => void) {
|
||||||
|
throw new Error('Function not implemented.');
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user