Skip to content

High performance self-hosted photo and video management solution.

feat(album): show per-user contributions in shared albums (#21740)

Chaoscontrol02beb8564298
diff --git a/e2e/src/api/specs/album.e2e-spec.ts b/e2e/src/api/specs/album.e2e-spec.ts
index 5615a312f2..c4f06edd93 100644
--- a/e2e/src/api/specs/album.e2e-spec.ts
+++ b/e2e/src/api/specs/album.e2e-spec.ts
@@ -136,6 +136,7 @@ describe('/albums', () => {
expect(body).toEqual({
...user1Albums[0],
assets: [expect.objectContaining({ isFavorite: false })],
+ contributorCounts: [{ userId: user1.userId, assetCount: 1 }],
lastModifiedAssetTimestamp: expect.any(String),
startDate: expect.any(String),
endDate: expect.any(String),
@@ -310,6 +311,7 @@ describe('/albums', () => {
expect(body).toEqual({
...user1Albums[0],
assets: [expect.objectContaining({ id: user1Albums[0].assets[0].id })],
+ contributorCounts: [{ userId: user1.userId, assetCount: 1 }],
lastModifiedAssetTimestamp: expect.any(String),
startDate: expect.any(String),
endDate: expect.any(String),
@@ -345,6 +347,7 @@ describe('/albums', () => {
expect(body).toEqual({
...user1Albums[0],
assets: [expect.objectContaining({ id: user1Albums[0].assets[0].id })],
+ contributorCounts: [{ userId: user1.userId, assetCount: 1 }],
lastModifiedAssetTimestamp: expect.any(String),
startDate: expect.any(String),
endDate: expect.any(String),
@@ -362,6 +365,7 @@ describe('/albums', () => {
expect(body).toEqual({
...user1Albums[0],
assets: [],
+ contributorCounts: [{ userId: user1.userId, assetCount: 1 }],
assetCount: 1,
lastModifiedAssetTimestamp: expect.any(String),
endDate: expect.any(String),
@@ -382,6 +386,7 @@ describe('/albums', () => {
expect(body).toEqual({
...user2Albums[0],
assets: [],
+ contributorCounts: [{ userId: user1.userId, assetCount: 1 }],
assetCount: 1,
lastModifiedAssetTimestamp: expect.any(String),
endDate: expect.any(String),
diff --git a/mobile/openapi/README.md b/mobile/openapi/README.md
index 4933c2c2b5..698b9774da 100644
--- a/mobile/openapi/README.md
+++ b/mobile/openapi/README.md
@@ -359,6 +359,7 @@ Class | Method | HTTP request | Description
- [CheckExistingAssetsDto](doc//CheckExistingAssetsDto.md)
- [CheckExistingAssetsResponseDto](doc//CheckExistingAssetsResponseDto.md)
- [Colorspace](doc//Colorspace.md)
+ - [ContributorCountResponseDto](doc//ContributorCountResponseDto.md)
- [CreateAlbumDto](doc//CreateAlbumDto.md)
- [CreateLibraryDto](doc//CreateLibraryDto.md)
- [CreateProfileImageResponseDto](doc//CreateProfileImageResponseDto.md)
diff --git a/mobile/openapi/lib/api.dart b/mobile/openapi/lib/api.dart
index df2c2226b1..a3117ede86 100644
--- a/mobile/openapi/lib/api.dart
+++ b/mobile/openapi/lib/api.dart
@@ -130,6 +130,7 @@ part 'model/change_password_dto.dart';
part 'model/check_existing_assets_dto.dart';
part 'model/check_existing_assets_response_dto.dart';
part 'model/colorspace.dart';
+part 'model/contributor_count_response_dto.dart';
part 'model/create_album_dto.dart';
part 'model/create_library_dto.dart';
part 'model/create_profile_image_response_dto.dart';
diff --git a/mobile/openapi/lib/api_client.dart b/mobile/openapi/lib/api_client.dart
index 06d27593c9..33056cf14e 100644
--- a/mobile/openapi/lib/api_client.dart
+++ b/mobile/openapi/lib/api_client.dart
@@ -314,6 +314,8 @@ class ApiClient {
return CheckExistingAssetsResponseDto.fromJson(value);
case 'Colorspace':
return ColorspaceTypeTransformer().decode(value);
+ case 'ContributorCountResponseDto':
+ return ContributorCountResponseDto.fromJson(value);
case 'CreateAlbumDto':
return CreateAlbumDto.fromJson(value);
case 'CreateLibraryDto':
diff --git a/mobile/openapi/lib/model/album_response_dto.dart b/mobile/openapi/lib/model/album_response_dto.dart
index 547a6a70fd..2f53706e7a 100644
--- a/mobile/openapi/lib/model/album_response_dto.dart
+++ b/mobile/openapi/lib/model/album_response_dto.dart
@@ -18,6 +18,7 @@ class AlbumResponseDto {
this.albumUsers = const [],
required this.assetCount,
this.assets = const [],
+ this.contributorCounts = const [],
required this.createdAt,
required this.description,
this.endDate,
@@ -43,6 +44,8 @@ class AlbumResponseDto {
List<AssetResponseDto> assets;
+ List<ContributorCountResponseDto> contributorCounts;
+
DateTime createdAt;
String description;
@@ -100,6 +103,7 @@ class AlbumResponseDto {
_deepEquality.equals(other.albumUsers, albumUsers) &&
other.assetCount == assetCount &&
_deepEquality.equals(other.assets, assets) &&
+ _deepEquality.equals(other.contributorCounts, contributorCounts) &&
other.createdAt == createdAt &&
other.description == description &&
other.endDate == endDate &&
@@ -122,6 +126,7 @@ class AlbumResponseDto {
(albumUsers.hashCode) +
(assetCount.hashCode) +
(assets.hashCode) +
+ (contributorCounts.hashCode) +
(createdAt.hashCode) +
(description.hashCode) +
(endDate == null ? 0 : endDate!.hashCode) +
@@ -137,7 +142,7 @@ class AlbumResponseDto {
(updatedAt.hashCode);
@override
- String toString() => 'AlbumResponseDto[albumName=$albumName, albumThumbnailAssetId=$albumThumbnailAssetId, albumUsers=$albumUsers, assetCount=$assetCount, assets=$assets, createdAt=$createdAt, description=$description, endDate=$endDate, hasSharedLink=$hasSharedLink, id=$id, isActivityEnabled=$isActivityEnabled, lastModifiedAssetTimestamp=$lastModifiedAssetTimestamp, order=$order, owner=$owner, ownerId=$ownerId, shared=$shared, startDate=$startDate, updatedAt=$updatedAt]';
+ String toString() => 'AlbumResponseDto[albumName=$albumName, albumThumbnailAssetId=$albumThumbnailAssetId, albumUsers=$albumUsers, assetCount=$assetCount, assets=$assets, contributorCounts=$contributorCounts, createdAt=$createdAt, description=$description, endDate=$endDate, hasSharedLink=$hasSharedLink, id=$id, isActivityEnabled=$isActivityEnabled, lastModifiedAssetTimestamp=$lastModifiedAssetTimestamp, order=$order, owner=$owner, ownerId=$ownerId, shared=$shared, startDate=$startDate, updatedAt=$updatedAt]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
@@ -150,6 +155,7 @@ class AlbumResponseDto {
json[r'albumUsers'] = this.albumUsers;
json[r'assetCount'] = this.assetCount;
json[r'assets'] = this.assets;
+ json[r'contributorCounts'] = this.contributorCounts;
json[r'createdAt'] = this.createdAt.toUtc().toIso8601String();
json[r'description'] = this.description;
if (this.endDate != null) {
@@ -196,6 +202,7 @@ class AlbumResponseDto {
albumUsers: AlbumUserResponseDto.listFromJson(json[r'albumUsers']),
assetCount: mapValueOfType<int>(json, r'assetCount')!,
assets: AssetResponseDto.listFromJson(json[r'assets']),
+ contributorCounts: ContributorCountResponseDto.listFromJson(json[r'contributorCounts']),
createdAt: mapDateTime(json, r'createdAt', r'')!,
description: mapValueOfType<String>(json, r'description')!,
endDate: mapDateTime(json, r'endDate', r''),
diff --git a/mobile/openapi/lib/model/contributor_count_response_dto.dart b/mobile/openapi/lib/model/contributor_count_response_dto.dart
new file mode 100644
index 0000000000..e0e16ee427
--- /dev/null
+++ b/mobile/openapi/lib/model/contributor_count_response_dto.dart
@@ -0,0 +1,107 @@
+//
+// AUTO-GENERATED FILE, DO NOT MODIFY!
+//
+// @dart=2.18
+
+// ignore_for_file: unused_element, unused_import
+// ignore_for_file: always_put_required_named_parameters_first
+// ignore_for_file: constant_identifier_names
+// ignore_for_file: lines_longer_than_80_chars
+
+part of openapi.api;
+
+class ContributorCountResponseDto {
+ /// Returns a new [ContributorCountResponseDto] instance.
+ ContributorCountResponseDto({
+ required this.assetCount,
+ required this.userId,
+ });
+
+ int assetCount;
+
+ String userId;
+
+ @override
+ bool operator ==(Object other) => identical(this, other) || other is ContributorCountResponseDto &&
+ other.assetCount == assetCount &&
+ other.userId == userId;
+
+ @override
+ int get hashCode =>
+ // ignore: unnecessary_parenthesis
+ (assetCount.hashCode) +
+ (userId.hashCode);
+
+ @override
+ String toString() => 'ContributorCountResponseDto[assetCount=$assetCount, userId=$userId]';
+
+ Map<String, dynamic> toJson() {
+ final json = <String, dynamic>{};
+ json[r'assetCount'] = this.assetCount;
+ json[r'userId'] = this.userId;
+ return json;
+ }
+
+ /// Returns a new [ContributorCountResponseDto] instance and imports its values from
+ /// [value] if it's a [Map], null otherwise.
+ // ignore: prefer_constructors_over_static_methods
+ static ContributorCountResponseDto? fromJson(dynamic value) {
+ upgradeDto(value, "ContributorCountResponseDto");
+ if (value is Map) {
+ final json = value.cast<String, dynamic>();
+
+ return ContributorCountResponseDto(
+ assetCount: mapValueOfType<int>(json, r'assetCount')!,
+ userId: mapValueOfType<String>(json, r'userId')!,
+ );
+ }
+ return null;
+ }
+
+ static List<ContributorCountResponseDto> listFromJson(dynamic json, {bool growable = false,}) {
+ final result = <ContributorCountResponseDto>[];
+ if (json is List && json.isNotEmpty) {
+ for (final row in json) {
+ final value = ContributorCountResponseDto.fromJson(row);
+ if (value != null) {
+ result.add(value);
+ }
+ }
+ }
+ return result.toList(growable: growable);
+ }
+
+ static Map<String, ContributorCountResponseDto> mapFromJson(dynamic json) {
+ final map = <String, ContributorCountResponseDto>{};
+ if (json is Map && json.isNotEmpty) {
+ json = json.cast<String, dynamic>(); // ignore: parameter_assignments
+ for (final entry in json.entries) {
+ final value = ContributorCountResponseDto.fromJson(entry.value);
+ if (value != null) {
+ map[entry.key] = value;
+ }
+ }
+ }
+ return map;
+ }
+
+ // maps a json object with a list of ContributorCountResponseDto-objects as value to a dart map
+ static Map<String, List<ContributorCountResponseDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
+ final map = <String, List<ContributorCountResponseDto>>{};
+ if (json is Map && json.isNotEmpty) {
+ // ignore: parameter_assignments
+ json = json.cast<String, dynamic>();
+ for (final entry in json.entries) {
+ map[entry.key] = ContributorCountResponseDto.listFromJson(entry.value, growable: growable,);
+ }
+ }
+ return map;
+ }
+
+ /// The list of required keys that must be present in a JSON.
+ static const requiredKeys = <String>{
+ 'assetCount',
+ 'userId',
+ };
+}
+
diff --git a/open-api/immich-openapi-specs.json b/open-api/immich-openapi-specs.json
index 2c045a73f0..b9da330ee5 100644
--- a/open-api/immich-openapi-specs.json
+++ b/open-api/immich-openapi-specs.json
@@ -10096,6 +10096,12 @@
},
"type": "array"
},
+ "contributorCounts": {
+ "items": {
+ "$ref": "#/components/schemas/ContributorCountResponseDto"
+ },
+ "type": "array"
+ },
"createdAt": {
"format": "date-time",
"type": "string"
@@ -11471,6 +11477,21 @@
],
"type": "string"
},
+ "ContributorCountResponseDto": {
+ "properties": {
+ "assetCount": {
+ "type": "integer"
+ },
+ "userId": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "assetCount",
+ "userId"
+ ],
+ "type": "object"
+ },
"CreateAlbumDto": {
"properties": {
"albumName": {
diff --git a/open-api/typescript-sdk/src/fetch-client.ts b/open-api/typescript-sdk/src/fetch-client.ts
index 38a57e4b5d..60d72fb32b 100644
--- a/open-api/typescript-sdk/src/fetch-client.ts
+++ b/open-api/typescript-sdk/src/fetch-client.ts
@@ -356,12 +356,17 @@ export type AssetResponseDto = {
updatedAt: string;
visibility: AssetVisibility;
};
+export type ContributorCountResponseDto = {
+ assetCount: number;
+ userId: string;
+};
export type AlbumResponseDto = {
albumName: string;
albumThumbnailAssetId: string | null;
albumUsers: AlbumUserResponseDto[];
assetCount: number;
assets: AssetResponseDto[];
+ contributorCounts?: ContributorCountResponseDto[];
createdAt: string;
description: string;
endDate?: string;
diff --git a/server/src/dtos/album.dto.ts b/server/src/dtos/album.dto.ts
index 00f5759aac..2f3f22099a 100644
--- a/server/src/dtos/album.dto.ts
+++ b/server/src/dtos/album.dto.ts
@@ -128,6 +128,14 @@ export class AlbumUserResponseDto {
role!: AlbumUserRole;
}
+export class ContributorCountResponseDto {
+ @ApiProperty()
+ userId!: string;
+
+ @ApiProperty({ type: 'integer' })
+ assetCount!: number;
+}
+
export class AlbumResponseDto {
id!: string;
ownerId!: string;
@@ -149,6 +157,11 @@ export class AlbumResponseDto {
isActivityEnabled!: boolean;
@ValidateEnum({ enum: AssetOrder, name: 'AssetOrder', optional: true })
order?: AssetOrder;
+
+ // Optional per-user contribution counts for shared albums
+ @Type(() => ContributorCountResponseDto)
+ @ApiProperty({ type: [ContributorCountResponseDto], required: false })
+ contributorCounts?: ContributorCountResponseDto[];
}
export type MapAlbumDto = {
diff --git a/server/src/queries/album.repository.sql b/server/src/queries/album.repository.sql
index 36c44414db..0087217738 100644
--- a/server/src/queries/album.repository.sql
+++ b/server/src/queries/album.repository.sql
@@ -407,3 +407,18 @@ from
where
"album_asset"."albumsId" = $1
and "album_asset"."assetsId" in ($2)
+
+-- AlbumRepository.getContributorCounts
+select
+ "asset"."ownerId" as "userId",
+ count(*) as "assetCount"
+from
+ "album_asset"
+ inner join "asset" on "asset"."id" = "assetsId"
+where
+ "asset"."deletedAt" is null
+ and "album_asset"."albumsId" = $1
+group by
+ "asset"."ownerId"
+order by
+ "assetCount" desc
diff --git a/server/src/repositories/album.repository.ts b/server/src/repositories/album.repository.ts
index b023068f16..00c1dfda7f 100644
--- a/server/src/repositories/album.repository.ts
+++ b/server/src/repositories/album.repository.ts
@@ -379,4 +379,22 @@ export class AlbumRepository {
)
.whereRef('album_asset.albumsId', '=', 'album.id');
}
+
+ /**
+ * Get per-user asset contribution counts for a single album.
+ * Excludes deleted assets, orders by count desc.
+ */
+ @GenerateSql({ params: [DummyValue.UUID] })
+ getContributorCounts(id: string) {
+ return this.db
+ .selectFrom('album_asset')
+ .innerJoin('asset', 'asset.id', 'assetsId')
+ .where('asset.deletedAt', 'is', sql.lit(null))
+ .where('album_asset.albumsId', '=', id)
+ .select('asset.ownerId as userId')
+ .select((eb) => eb.fn.countAll<number>().as('assetCount'))
+ .groupBy('asset.ownerId')
+ .orderBy('assetCount', 'desc')
+ .execute();
+ }
}
diff --git a/server/src/services/album.service.ts b/server/src/services/album.service.ts
index d7b857d666..dd12e31892 100644
--- a/server/src/services/album.service.ts
+++ b/server/src/services/album.service.ts
@@ -79,12 +79,17 @@ export class AlbumService extends BaseService {
const album = await this.findOrFail(id, { withAssets });
const [albumMetadataForIds] = await this.albumRepository.getMetadataForIds([album.id]);
+ const hasSharedUsers = album.albumUsers && album.albumUsers.length > 0;
+ const hasSharedLink = album.sharedLinks && album.sharedLinks.length > 0;
+ const isShared = hasSharedUsers || hasSharedLink;
+
return {
...mapAlbum(album, withAssets, auth),
startDate: albumMetadataForIds?.startDate ?? undefined,
endDate: albumMetadataForIds?.endDate ?? undefined,
assetCount: albumMetadataForIds?.assetCount ?? 0,
lastModifiedAssetTimestamp: albumMetadataForIds?.lastModifiedAssetTimestamp ?? undefined,
+ contributorCounts: isShared ? await this.albumRepository.getContributorCounts(album.id) : undefined,
};
}
diff --git a/web/src/lib/modals/AlbumUsersModal.svelte b/web/src/lib/modals/AlbumUsersModal.svelte
index 3cc0f03d5e..7dd7442249 100644
--- a/web/src/lib/modals/AlbumUsersModal.svelte
+++ b/web/src/lib/modals/AlbumUsersModal.svelte
@@ -31,6 +31,14 @@
let isOwned = $derived(currentUser?.id == album.ownerId);
+ // Build a map of contributor counts by user id; avoid casts/derived
+ const contributorCounts: Record<string, number> = {};
+ if (album.contributorCounts) {
+ for (const { userId, assetCount } of album.contributorCounts) {
+ contributorCounts[userId] = assetCount;
+ }
+ }
+
onMount(async () => {
try {
currentUser = await getMyUser();
@@ -111,6 +119,10 @@
{:else}
{$t('role_editor')}
{/if}
+ {#if user.id in contributorCounts}
+ <span>-</span>
+ {$t('items_count', { values: { count: contributorCounts[user.id] } })}
+ {/if}
</Text>
</div>
</div>