Version guard, and stop using Date parameter type

pull/28628/head
Victor Chang 2026-03-18 07:06:44 +00:00
parent f96444ae83
commit 23121331dd
2 changed files with 44 additions and 4 deletions

View File

@ -1,10 +1,15 @@
import 'package:collection/collection.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/models/activities/activity.model.dart';
import 'package:immich_mobile/models/server_info/server_version.model.dart';
import 'package:immich_mobile/providers/activity_service.provider.dart';
import 'package:immich_mobile/providers/server_info.provider.dart';
const _pageSize = 50;
/// Minimum server version that supports paginated activity loading (take + before params).
const _paginationMinVersion = ServerVersion(major: 2, minor: 6, patch: 0);
// ignore: unintended_html_in_doc_comment
/// Maintains the current list of all activities for <share-album-id, asset>
@ -21,18 +26,22 @@ class AlbumActivity extends AutoDisposeFamilyAsyncNotifier<List<Activity>, (Stri
bool get hasMore => _hasMore;
bool get isLoadingMore => _isLoadingMore;
bool get _paginationSupported =>
ref.read(serverInfoProvider).serverVersion >= _paginationMinVersion;
@override
Future<List<Activity>> build((String albumId, String? assetId) args) async {
albumId = args.$1;
assetId = args.$2;
_hasMore = true;
_isLoadingMore = false;
final paginationSupported = _paginationSupported;
final activities = await ref.watch(activityServiceProvider).getAllActivities(
albumId,
assetId: assetId,
take: _pageSize,
take: paginationSupported ? _pageSize : null,
);
_hasMore = activities.length >= _pageSize;
_hasMore = paginationSupported && activities.length >= _pageSize;
return activities;
}

View File

@ -1,3 +1,4 @@
import { websocketStore } from '$lib/stores/websocket';
import {
createActivity,
deleteActivity,
@ -14,6 +15,30 @@ import { authManager } from '$lib/managers/auth-manager.svelte';
import { handlePromiseError } from '$lib/utils';
import { handleError } from '$lib/utils/handle-error';
/** Minimum server version that supports paginated activity loading (take + before params). */
const PAGINATION_MIN_VERSION = { major: 2, minor: 6, patch: 0 };
function waitForServerVersion(): Promise<{ major: number; minor: number; patch: number }> {
return new Promise((resolve) => {
const unsubscribe = websocketStore.serverVersion.subscribe((version) => {
if (version) {
unsubscribe();
resolve(version);
}
});
});
}
function versionSupportsPagination(version: { major: number; minor: number; patch: number }): boolean {
if (version.major !== PAGINATION_MIN_VERSION.major) {
return version.major > PAGINATION_MIN_VERSION.major;
}
if (version.minor !== PAGINATION_MIN_VERSION.minor) {
return version.minor > PAGINATION_MIN_VERSION.minor;
}
return version.patch >= PAGINATION_MIN_VERSION.patch;
}
type CacheKey = string;
type ActivityCache = {
activities: ActivityResponseDto[];
@ -160,8 +185,14 @@ class ActivityManager {
return;
}
this.#activities = await getActivities({ albumId, assetId, take: ActivityManager.PAGE_SIZE });
this.#hasMore = this.#activities.length >= ActivityManager.PAGE_SIZE;
const serverVersion = await waitForServerVersion();
const paginationSupported = versionSupportsPagination(serverVersion);
this.#activities = await getActivities({
albumId,
assetId,
take: paginationSupported ? ActivityManager.PAGE_SIZE : undefined,
});
this.#hasMore = paginationSupported && this.#activities.length >= ActivityManager.PAGE_SIZE;
const [liked] = await getActivities({
albumId,