mirror of
https://github.com/immich-app/immich.git
synced 2025-12-20 01:11:46 +03:00
fix(server,web): correctly show album level like (#4916)
* fix: like in global activity * refactor: rename isGlobal to ReactionLevel.Album * chore: open api * chore: e2e test for album vs comment duplicate like checking --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
@@ -9,6 +9,11 @@ export enum ReactionType {
|
||||
LIKE = 'like',
|
||||
}
|
||||
|
||||
export enum ReactionLevel {
|
||||
ALBUM = 'album',
|
||||
ASSET = 'asset',
|
||||
}
|
||||
|
||||
export type MaybeDuplicate<T> = { duplicate: boolean; value: T };
|
||||
|
||||
export class ActivityResponseDto {
|
||||
@@ -39,6 +44,11 @@ export class ActivitySearchDto extends ActivityDto {
|
||||
@ApiProperty({ enumName: 'ReactionType', enum: ReactionType })
|
||||
type?: ReactionType;
|
||||
|
||||
@IsEnum(ReactionLevel)
|
||||
@Optional()
|
||||
@ApiProperty({ enumName: 'ReactionLevel', enum: ReactionLevel })
|
||||
level?: ReactionLevel;
|
||||
|
||||
@ValidateUUID({ optional: true })
|
||||
userId?: string;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
ActivitySearchDto,
|
||||
ActivityStatisticsResponseDto,
|
||||
MaybeDuplicate,
|
||||
ReactionLevel,
|
||||
ReactionType,
|
||||
mapActivity,
|
||||
} from './activity.dto';
|
||||
@@ -30,7 +31,7 @@ export class ActivityService {
|
||||
const activities = await this.repository.search({
|
||||
userId: dto.userId,
|
||||
albumId: dto.albumId,
|
||||
assetId: dto.assetId,
|
||||
assetId: dto.level === ReactionLevel.ALBUM ? null : dto.assetId,
|
||||
isLiked: dto.type && dto.type === ReactionType.LIKE,
|
||||
});
|
||||
|
||||
@@ -54,11 +55,12 @@ export class ActivityService {
|
||||
let activity: ActivityEntity | null = null;
|
||||
let duplicate = false;
|
||||
|
||||
if (dto.type === 'like') {
|
||||
if (dto.type === ReactionType.LIKE) {
|
||||
delete dto.comment;
|
||||
[activity] = await this.repository.search({
|
||||
...common,
|
||||
isGlobal: !dto.assetId,
|
||||
// `null` will search for an album like
|
||||
assetId: dto.assetId ?? null,
|
||||
isLiked: true,
|
||||
});
|
||||
duplicate = !!activity;
|
||||
|
||||
@@ -6,10 +6,9 @@ import { ActivityEntity } from '../entities/activity.entity';
|
||||
|
||||
export interface ActivitySearch {
|
||||
albumId?: string;
|
||||
assetId?: string;
|
||||
assetId?: string | null;
|
||||
userId?: string;
|
||||
isLiked?: boolean;
|
||||
isGlobal?: boolean;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -17,11 +16,11 @@ export class ActivityRepository implements IActivityRepository {
|
||||
constructor(@InjectRepository(ActivityEntity) private repository: Repository<ActivityEntity>) {}
|
||||
|
||||
search(options: ActivitySearch): Promise<ActivityEntity[]> {
|
||||
const { userId, assetId, albumId, isLiked, isGlobal } = options;
|
||||
const { userId, assetId, albumId, isLiked } = options;
|
||||
return this.repository.find({
|
||||
where: {
|
||||
userId,
|
||||
assetId: isGlobal ? IsNull() : assetId,
|
||||
assetId: assetId === null ? IsNull() : assetId,
|
||||
albumId,
|
||||
isLiked,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user