Skip to content

Commit

Permalink
fix: activity with deleted assets / users
Browse files Browse the repository at this point in the history
  • Loading branch information
martabal committed Apr 25, 2024
1 parent dc9b51a commit 93f7f16
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 10 deletions.
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

0 comments on commit 93f7f16

Please sign in to comment.