Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions server/src/queries/activity.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
)
)
)
)
19 changes: 18 additions & 1 deletion server/src/repositories/activity.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
});
}

Expand Down
13 changes: 8 additions & 5 deletions web/src/lib/components/asset-viewer/activity-viewer.svelte
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down
Loading