mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00: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:
parent
986bbfa831
commit
92ec1ce77f
21 changed files with 262 additions and 26 deletions
|
|
@ -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,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue