mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat(web): email notification preference settings (#9934)
* feat(web): email notification preference settings * Update * remove failed api generation file * fix handle album invite return value * Update web/src/lib/components/user-settings-page/notifications-settings.svelte Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> * wording * test --------- Co-authored-by: Daniel Dietzler <mail@ddietzler.dev> Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>
This commit is contained in:
parent
15474e81b2
commit
b3ee394fdc
15 changed files with 478 additions and 4 deletions
|
|
@ -16,6 +16,17 @@ class MemoryUpdate {
|
|||
enabled?: boolean;
|
||||
}
|
||||
|
||||
class EmailNotificationsUpdate {
|
||||
@ValidateBoolean({ optional: true })
|
||||
enabled?: boolean;
|
||||
|
||||
@ValidateBoolean({ optional: true })
|
||||
albumInvite?: boolean;
|
||||
|
||||
@ValidateBoolean({ optional: true })
|
||||
albumUpdate?: boolean;
|
||||
}
|
||||
|
||||
export class UserPreferencesUpdateDto {
|
||||
@Optional()
|
||||
@ValidateNested()
|
||||
|
|
@ -26,6 +37,11 @@ export class UserPreferencesUpdateDto {
|
|||
@ValidateNested()
|
||||
@Type(() => MemoryUpdate)
|
||||
memories?: MemoryUpdate;
|
||||
|
||||
@Optional()
|
||||
@ValidateNested()
|
||||
@Type(() => EmailNotificationsUpdate)
|
||||
emailNotifications?: EmailNotificationsUpdate;
|
||||
}
|
||||
|
||||
class AvatarResponse {
|
||||
|
|
@ -37,9 +53,16 @@ class MemoryResponse {
|
|||
enabled!: boolean;
|
||||
}
|
||||
|
||||
class EmailNotificationsResponse {
|
||||
enabled!: boolean;
|
||||
albumInvite!: boolean;
|
||||
albumUpdate!: boolean;
|
||||
}
|
||||
|
||||
export class UserPreferencesResponseDto implements UserPreferences {
|
||||
memories!: MemoryResponse;
|
||||
avatar!: AvatarResponse;
|
||||
emailNotifications!: EmailNotificationsResponse;
|
||||
}
|
||||
|
||||
export const mapPreferences = (preferences: UserPreferences): UserPreferencesResponseDto => {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,11 @@ export interface UserPreferences {
|
|||
avatar: {
|
||||
color: UserAvatarColor;
|
||||
};
|
||||
emailNotifications: {
|
||||
enabled: boolean;
|
||||
albumInvite: boolean;
|
||||
albumUpdate: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
export const getDefaultPreferences = (user: { email: string }): UserPreferences => {
|
||||
|
|
@ -51,6 +56,11 @@ export const getDefaultPreferences = (user: { email: string }): UserPreferences
|
|||
avatar: {
|
||||
color: values[randomIndex],
|
||||
},
|
||||
emailNotifications: {
|
||||
enabled: true,
|
||||
albumInvite: true,
|
||||
albumUpdate: true,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
|||
import { EmailImageAttachment, EmailTemplate, INotificationRepository } from 'src/interfaces/notification.interface';
|
||||
import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface';
|
||||
import { IUserRepository } from 'src/interfaces/user.interface';
|
||||
import { getPreferences } from 'src/utils/preferences';
|
||||
|
||||
@Injectable()
|
||||
export class NotificationService {
|
||||
|
|
@ -95,6 +96,12 @@ export class NotificationService {
|
|||
return JobStatus.SKIPPED;
|
||||
}
|
||||
|
||||
const { emailNotifications } = getPreferences(recipient);
|
||||
|
||||
if (!emailNotifications.enabled || !emailNotifications.albumInvite) {
|
||||
return JobStatus.SKIPPED;
|
||||
}
|
||||
|
||||
const attachment = await this.getAlbumThumbnailAttachment(album);
|
||||
|
||||
const { server } = await this.configCore.getConfig();
|
||||
|
|
@ -142,6 +149,12 @@ export class NotificationService {
|
|||
const { server } = await this.configCore.getConfig();
|
||||
|
||||
for (const recipient of recipients) {
|
||||
const { emailNotifications } = getPreferences(recipient);
|
||||
|
||||
if (!emailNotifications.enabled || !emailNotifications.albumUpdate) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const { html, text } = this.notificationRepository.renderEmail({
|
||||
template: EmailTemplate.ALBUM_UPDATE,
|
||||
data: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue