Skip to content

Commit

Permalink
feat(notif): include requested season numbers in notifications (#1211)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCatLady committed Mar 19, 2021
1 parent 4a5a9cc commit 4ee78ab
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 161 deletions.
19 changes: 5 additions & 14 deletions server/entity/MediaRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class MediaRequest {
subject: movie.title,
message: movie.overview,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${movie.poster_path}`,
notifyUser: this.requestedBy,
notifyUser: autoApproved ? undefined : this.requestedBy,
media,
request: this,
}
Expand Down Expand Up @@ -444,15 +444,10 @@ export class MediaRequest {
label: 'Media Request',
}
);
const userRepository = getRepository(User);
const admin = await userRepository.findOneOrFail({
select: ['id', 'plexToken'],
order: { id: 'ASC' },
});

notificationManager.sendNotification(Notification.MEDIA_FAILED, {
subject: movie.title,
message: 'Movie failed to add to Radarr',
notifyUser: admin,
message: movie.overview,
media,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${movie.poster_path}`,
request: this,
Expand Down Expand Up @@ -641,14 +636,10 @@ export class MediaRequest {
label: 'Media Request',
}
);
const userRepository = getRepository(User);
const admin = await userRepository.findOneOrFail({
order: { id: 'ASC' },
});

notificationManager.sendNotification(Notification.MEDIA_FAILED, {
subject: series.name,
message: 'Series failed to add to Sonarr',
notifyUser: admin,
message: series.overview,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${series.poster_path}`,
media,
extra: [
Expand Down
10 changes: 2 additions & 8 deletions server/lib/notifications/agents/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { NotificationAgentConfig } from '../../settings';

export interface NotificationPayload {
subject: string;
notifyUser: User;
notifyUser?: User;
media?: Media;
image?: string;
message?: string;
Expand All @@ -21,15 +21,9 @@ export abstract class BaseAgent<T extends NotificationAgentConfig> {
}

protected abstract getSettings(): T;

protected userNotificationTypes: Notification[] = [
Notification.MEDIA_APPROVED,
Notification.MEDIA_DECLINED,
Notification.MEDIA_AVAILABLE,
];
}

export interface NotificationAgent {
shouldSend(type: Notification, payload: NotificationPayload): boolean;
shouldSend(type: Notification): boolean;
send(type: Notification, payload: NotificationPayload): Promise<boolean>;
}
4 changes: 2 additions & 2 deletions server/lib/notifications/agents/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class DiscordAgent
if (payload.request) {
fields.push({
name: 'Requested By',
value: payload.notifyUser.displayName ?? '',
value: payload.request?.requestedBy.displayName ?? '',
inline: true,
});
}
Expand Down Expand Up @@ -217,7 +217,7 @@ class DiscordAgent
let content = undefined;

if (
this.userNotificationTypes.includes(type) &&
payload.notifyUser &&
payload.notifyUser.settings?.enableNotifications &&
payload.notifyUser.settings?.discordId
) {
Expand Down

0 comments on commit 4ee78ab

Please sign in to comment.