fix(server): activity with deleted assets / users (#9068)

fix: activity with deleted assets / users
This commit is contained in:
martin 2024-04-25 23:45:15 +02:00 committed by GitHub
parent 40899f6137
commit c9dcb5c624
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 62 additions and 10 deletions

View File

@ -32,8 +32,28 @@ FROM
AND (
"ActivityEntity__ActivityEntity_user"."deletedAt" IS NULL
)
LEFT JOIN "assets" "ActivityEntity__ActivityEntity_asset" ON "ActivityEntity__ActivityEntity_asset"."id" = "ActivityEntity"."assetId"
AND (
"ActivityEntity__ActivityEntity_asset"."deletedAt" IS NULL
)
WHERE
(("ActivityEntity"."albumId" = $1))
(
("ActivityEntity"."albumId" = $1)
AND (
(
(
"ActivityEntity__ActivityEntity_asset"."deletedAt" IS NULL
)
)
)
AND (
(
(
"ActivityEntity__ActivityEntity_user"."deletedAt" IS NULL
)
)
)
)
ORDER BY
"ActivityEntity"."createdAt" ASC
@ -43,12 +63,24 @@ SELECT
FROM
"activity" "ActivityEntity"
LEFT JOIN "users" "ActivityEntity__ActivityEntity_user" ON "ActivityEntity__ActivityEntity_user"."id" = "ActivityEntity"."userId"
AND (
"ActivityEntity__ActivityEntity_user"."deletedAt" IS NULL
)
LEFT JOIN "assets" "ActivityEntity__ActivityEntity_asset" ON "ActivityEntity__ActivityEntity_asset"."id" = "ActivityEntity"."assetId"
WHERE
(
("ActivityEntity"."assetId" = $1)
AND ("ActivityEntity"."albumId" = $2)
AND ("ActivityEntity"."isLiked" = $3)
AND (
(
(
"ActivityEntity__ActivityEntity_asset"."deletedAt" IS NULL
)
)
)
AND (
(
(
"ActivityEntity__ActivityEntity_user"."deletedAt" IS NULL
)
)
)
)

View File

@ -27,6 +27,12 @@ export class ActivityRepository implements IActivityRepository {
assetId: assetId === null ? IsNull() : assetId,
albumId,
isLiked,
asset: {
deletedAt: IsNull(),
},
user: {
deletedAt: IsNull(),
},
},
relations: {
user: true,
@ -48,10 +54,21 @@ export class ActivityRepository implements IActivityRepository {
@GenerateSql({ params: [DummyValue.UUID, DummyValue.UUID] })
getStatistics(assetId: string, albumId: string): Promise<number> {
return this.repository.count({
where: { assetId, albumId, isLiked: false },
where: {
assetId,
albumId,
isLiked: false,
asset: {
deletedAt: IsNull(),
},
user: {
deletedAt: IsNull(),
},
},
relations: {
user: true,
},
withDeleted: true,
});
}

View File

@ -1,6 +1,6 @@
<script lang="ts">
import Icon from '$lib/components/elements/icon.svelte';
import { timeBeforeShowLoadingSpinner } from '$lib/constants';
import { AppRoute, timeBeforeShowLoadingSpinner } from '$lib/constants';
import { getAssetThumbnailUrl, handlePromiseError } from '$lib/utils';
import { getAssetType } from '$lib/utils/asset-utils';
import { autoGrowHeight } from '$lib/utils/autogrow';
@ -184,13 +184,13 @@
<div class="w-full leading-4 overflow-hidden self-center break-words text-sm">{reaction.comment}</div>
{#if assetId === undefined && reaction.assetId}
<div class="aspect-square w-[75px] h-[75px]">
<a class="aspect-square w-[75px] h-[75px]" href="{AppRoute.ALBUMS}/{albumId}/photos/{reaction.assetId}">
<img
class="rounded-lg w-[75px] h-[75px] object-cover"
src={getAssetThumbnailUrl(reaction.assetId, ThumbnailFormat.Webp)}
alt="Profile picture of {reaction.user.name}, who commented on this asset"
/>
</div>
</a>
{/if}
{#if reaction.user.id === user.id || albumOwnerId === user.id}
<div class="flex items-start w-fit pt-[5px]" title="Delete comment">
@ -230,13 +230,16 @@
{`${reaction.user.name} liked ${assetType ? `this ${getAssetType(assetType).toLowerCase()}` : 'it'}`}
</div>
{#if assetId === undefined && reaction.assetId}
<div class="aspect-square w-[75px] h-[75px]">
<a
class="aspect-square w-[75px] h-[75px]"
href="{AppRoute.ALBUMS}/{albumId}/photos/{reaction.assetId}"
>
<img
class="rounded-lg w-[75px] h-[75px] object-cover"
src={getAssetThumbnailUrl(reaction.assetId, ThumbnailFormat.Webp)}
alt="Profile picture of {reaction.user.name}, who liked this asset"
/>
</div>
</a>
{/if}
{#if reaction.user.id === user.id || albumOwnerId === user.id}
<div class="flex items-start w-fit" title="Delete like">