From b73f7fe16f19d730aa7523973bf69743d09c5c6a Mon Sep 17 00:00:00 2001 From: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> Date: Wed, 31 Jul 2024 19:08:31 +0200 Subject: [PATCH] refactor: deduplicate MemoryType and ReactionType enums (#11479) * refactor: deduplicate memorytype and reactiontype enums * fix mobile --- .../lib/models/activities/activity.model.dart | 2 +- .../lib/model/activity_response_dto.dart | Bin 6848 -> 4150 bytes .../lib/model/memory_response_dto.dart | Bin 8654 -> 6121 bytes open-api/immich-openapi-specs.json | 11 ++--------- open-api/typescript-sdk/src/fetch-client.ts | 11 ++--------- server/src/dtos/activity.dto.ts | 3 ++- server/src/dtos/memory.dto.ts | 1 + .../asset-viewer/activity-viewer.svelte | 13 ++++++------- 8 files changed, 14 insertions(+), 27 deletions(-) diff --git a/mobile/lib/models/activities/activity.model.dart b/mobile/lib/models/activities/activity.model.dart index 9cb3d0790c..6adb80dca9 100644 --- a/mobile/lib/models/activities/activity.model.dart +++ b/mobile/lib/models/activities/activity.model.dart @@ -43,7 +43,7 @@ class Activity { assetId = dto.assetId, comment = dto.comment, createdAt = dto.createdAt, - type = dto.type == ActivityResponseDtoTypeEnum.comment + type = dto.type == ReactionType.comment ? ActivityType.comment : ActivityType.like, user = User.fromSimpleUserDto(dto.user); diff --git a/mobile/openapi/lib/model/activity_response_dto.dart b/mobile/openapi/lib/model/activity_response_dto.dart index cd7a4f482fe8c66d008c7c7dbf15226138fc15f0..bfffd8485b0a982f561d799926d365fa1fbec655 100644 GIT binary patch delta 43 mcmX?Lx=mq2J`+z+YGQIpW`15sWkKrZE+#>CRFQ3*^Vk4n01zMm delta 2135 zcmb7FTZh8>pn!!AT?&@>>zH`3%5B`7juf9~-&dsX_Bg12d$E%<>B?7Vr&?Kj;&f~9>DoWPRM1&lG$(Kz0c>t=!oIRjC?|zO5TI}lND*N! z-2~hOVQTbDCYZo*Cb9xYee#Pbyn_|_`tN&gB5mKhtZzqku7k-ALZK2gSt->a_|KqI zN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T&0Ovg)BxGT4C5Z6DBWQcE@t%Q}_ZqXau5FFstp zSOY*s>ZXzdPCkf4-kcZuD5mbHE|DZKQO3l>1buJ=vGnEk7^Qx1DFzOwg)&^}rZ}~B z>3T)N?H+XsP#3sKul;tTcy<2T%j!%QMp~t=$tag1rM5h--0{-%e0xs|X+}z?sDq7G zgrSNs@ORtAr`7e-Rf^*4>dX1d<+bVj<=xuH+1o~gg;IwjXqAL85ylV}!a^t{5FQ-A z5A+;6NrlK5{sSSfsw8;RB@mKC=F99u)oUc0R=`k%ule{tqO}&}eWZV<_K^rJ3HCog zV~7WJH{EXMB;`AG)j*Mw2Z5K>2@`Xq-1=H6a*u7Wlx>KF6+8kn_v8n!p1U2#yrJpt zRj4`@^m}}*&$x=^pztsf{r(?ziBTF0HGPsLNgrr#tW?Ev@f(L4f2dFn8{ww!LBxatRa?cJ8NZDQ){DcyG za@O$+8K;v3Q4EOcb@J-NK5-j91u{4 zT-Ncx?TUykR%z-xRRLgGbpS)(ig4_9*GYx^Ve!9E5Ic(| zyIuS`e|7G`wez*>OA(Glme}oj!KYrY3p<>F^H^pE?&$rDIdhB!%@^{uB) = { duplicate: boolean; value: T }; export class ActivityResponseDto { id!: string; createdAt!: Date; + @ApiProperty({ enumName: 'ReactionType', enum: ReactionType }) type!: ReactionType; user!: UserResponseDto; assetId!: string | null; @@ -53,7 +54,7 @@ export class ActivitySearchDto extends ActivityDto { userId?: string; } -const isComment = (dto: ActivityCreateDto) => dto.type === 'comment'; +const isComment = (dto: ActivityCreateDto) => dto.type === ReactionType.COMMENT; export class ActivityCreateDto extends ActivityDto { @IsEnum(ReactionType) diff --git a/server/src/dtos/memory.dto.ts b/server/src/dtos/memory.dto.ts index ecd62785f8..c9db4b04e0 100644 --- a/server/src/dtos/memory.dto.ts +++ b/server/src/dtos/memory.dto.ts @@ -61,6 +61,7 @@ export class MemoryResponseDto { memoryAt!: Date; seenAt?: Date; ownerId!: string; + @ApiProperty({ enumName: 'MemoryType', enum: MemoryType }) type!: MemoryType; data!: MemoryData; isSaved!: boolean; diff --git a/web/src/lib/components/asset-viewer/activity-viewer.svelte b/web/src/lib/components/asset-viewer/activity-viewer.svelte index 4664dcc3c5..050802e1d0 100644 --- a/web/src/lib/components/asset-viewer/activity-viewer.svelte +++ b/web/src/lib/components/asset-viewer/activity-viewer.svelte @@ -8,7 +8,6 @@ import { isTenMinutesApart } from '$lib/utils/timesince'; import { ReactionType, - Type, createActivity, deleteActivity, getActivities, @@ -111,15 +110,15 @@ await deleteActivity({ id: reaction.id }); reactions.splice(index, 1); reactions = reactions; - if (isLiked && reaction.type === 'like' && reaction.id == isLiked.id) { + if (isLiked && reaction.type === ReactionType.Like && reaction.id == isLiked.id) { dispatch('deleteLike'); } else { dispatch('deleteComment'); } - const deleteMessages: Record = { - [Type.Comment]: $t('comment_deleted'), - [Type.Like]: $t('like_deleted'), + const deleteMessages: Record = { + [ReactionType.Comment]: $t('comment_deleted'), + [ReactionType.Like]: $t('like_deleted'), }; notificationController.show({ message: deleteMessages[reaction.type], @@ -172,7 +171,7 @@ style="height: {divHeight}px;padding-bottom: {chatHeight}px" > {#each reactions as reaction, index (reaction.id)} - {#if reaction.type === 'comment'} + {#if reaction.type === ReactionType.Comment}
@@ -216,7 +215,7 @@ {timeSince(luxon.DateTime.fromISO(reaction.createdAt, { locale: $locale }))}
{/if} - {:else if reaction.type === 'like'} + {:else if reaction.type === ReactionType.Like}