diff --git a/src/backend/model/jobs/jobs/TopPickSendJob.ts b/src/backend/model/jobs/jobs/TopPickSendJob.ts index 8393ee3c..47a0d4b1 100644 --- a/src/backend/model/jobs/jobs/TopPickSendJob.ts +++ b/src/backend/model/jobs/jobs/TopPickSendJob.ts @@ -7,6 +7,7 @@ import {ObjectManagers} from '../../ObjectManagers'; import {PhotoEntity} from '../../database/enitites/PhotoEntity'; import {EmailMediaMessenger} from '../../mediamessengers/EmailMediaMessenger'; import {MediaPickDTO} from '../../../../common/entities/MediaPickDTO'; +import {MediaDTOUtils} from '../../../../common/entities/MediaDTO'; export class TopPickSendJob extends Job<{ @@ -83,11 +84,17 @@ export class TopPickSendJob extends Job<{ this.Progress.log('Collecting Photos and videos to Send.'); this.mediaList = []; for (let i = 0; i < this.config.mediaPick.length; ++i) { - const media = await ObjectManagers.getInstance().SearchManager.getNMedia(this.config.mediaPick[i].searchQuery, this.config.mediaPick[i].sortBy, this.config.mediaPick[i].pick); + const media = await ObjectManagers.getInstance().SearchManager + .getNMedia(this.config.mediaPick[i].searchQuery, this.config.mediaPick[i].sortBy, this.config.mediaPick[i].pick); this.Progress.log('Find ' + media.length + ' photos and videos from ' + (i + 1) + '. load'); this.mediaList = this.mediaList.concat(media); } + // make the list unique + this.mediaList = this.mediaList + .filter((value, index, arr) => + arr.findIndex(m => MediaDTOUtils.equals(m, value)) === index); + this.Progress.Processed++; // console.log(this.mediaList); return false; diff --git a/src/common/entities/MediaDTO.ts b/src/common/entities/MediaDTO.ts index b00030cc..2b6dbc21 100644 --- a/src/common/entities/MediaDTO.ts +++ b/src/common/entities/MediaDTO.ts @@ -73,4 +73,10 @@ export const MediaDTOUtils = { calcAspectRatio: (photo: MediaDTO): number => { return (photo.metadata.size.width / photo.metadata.size.height) || 1; // NaN should be treated as square photo }, + + equals: (a: MediaDTO, b: MediaDTO): boolean => { + return a.directory.path === b.directory.path && + a.directory.name === b.directory.name && + a.name === b.name; + } }; diff --git a/src/frontend/app/ui/settings/workflow/workflow.component.ts b/src/frontend/app/ui/settings/workflow/workflow.component.ts index 746f1600..7ae3a997 100644 --- a/src/frontend/app/ui/settings/workflow/workflow.component.ts +++ b/src/frontend/app/ui/settings/workflow/workflow.component.ts @@ -310,7 +310,8 @@ export class WorkflowComponent implements ControlValueAccessor, Validator, OnIni AddNewMediaPickDTO(configElement: string | number | string[] | number[] | MediaPickDTO[]): void { (configElement as MediaPickDTO[]).push({ searchQuery: {type: SearchQueryTypes.any_text, text: ''} as TextSearch, - sortBy: [{method: SortByTypes.Rating, ascending: true}], + sortBy: [{method: SortByTypes.Rating, ascending: true}, + {method: SortByTypes.PersonCount, ascending: true}], pick: 5 }); }