|
|
|
@ -14,15 +14,19 @@ import notificationManager, { Notification } from '../lib/notifications';
|
|
|
|
|
|
|
|
|
|
@EventSubscriber()
|
|
|
|
|
export class MediaSubscriber implements EntitySubscriberInterface<Media> {
|
|
|
|
|
private async notifyAvailableMovie(entity: Media, dbEntity?: Media) {
|
|
|
|
|
private async notifyAvailableMovie(
|
|
|
|
|
entity: Media,
|
|
|
|
|
dbEntity: Media,
|
|
|
|
|
is4k: boolean
|
|
|
|
|
) {
|
|
|
|
|
if (
|
|
|
|
|
entity.status === MediaStatus.AVAILABLE &&
|
|
|
|
|
dbEntity?.status !== MediaStatus.AVAILABLE
|
|
|
|
|
entity[is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE &&
|
|
|
|
|
dbEntity[is4k ? 'status4k' : 'status'] !== MediaStatus.AVAILABLE
|
|
|
|
|
) {
|
|
|
|
|
if (entity.mediaType === MediaType.MOVIE) {
|
|
|
|
|
const requestRepository = getRepository(MediaRequest);
|
|
|
|
|
const relatedRequests = await requestRepository.find({
|
|
|
|
|
where: { media: entity, is4k: false },
|
|
|
|
|
where: { media: entity, is4k },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (relatedRequests.length > 0) {
|
|
|
|
@ -31,7 +35,7 @@ export class MediaSubscriber implements EntitySubscriberInterface<Media> {
|
|
|
|
|
|
|
|
|
|
relatedRequests.forEach((request) => {
|
|
|
|
|
notificationManager.sendNotification(Notification.MEDIA_AVAILABLE, {
|
|
|
|
|
event: 'Movie Now Available',
|
|
|
|
|
event: `${is4k ? '4K ' : ''}Movie Request Now Available`,
|
|
|
|
|
notifyAdmin: false,
|
|
|
|
|
notifyUser: request.requestedBy,
|
|
|
|
|
subject: `${movie.title}${
|
|
|
|
@ -52,15 +56,25 @@ export class MediaSubscriber implements EntitySubscriberInterface<Media> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async notifyAvailableSeries(entity: Media, dbEntity: Media) {
|
|
|
|
|
private async notifyAvailableSeries(
|
|
|
|
|
entity: Media,
|
|
|
|
|
dbEntity: Media,
|
|
|
|
|
is4k: boolean
|
|
|
|
|
) {
|
|
|
|
|
const seasonRepository = getRepository(Season);
|
|
|
|
|
const newAvailableSeasons = entity.seasons
|
|
|
|
|
.filter((season) => season.status === MediaStatus.AVAILABLE)
|
|
|
|
|
.filter(
|
|
|
|
|
(season) =>
|
|
|
|
|
season[is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE
|
|
|
|
|
)
|
|
|
|
|
.map((season) => season.seasonNumber);
|
|
|
|
|
const oldSeasonIds = dbEntity.seasons.map((season) => season.id);
|
|
|
|
|
const oldSeasons = await seasonRepository.findByIds(oldSeasonIds);
|
|
|
|
|
const oldAvailableSeasons = oldSeasons
|
|
|
|
|
.filter((season) => season.status === MediaStatus.AVAILABLE)
|
|
|
|
|
.filter(
|
|
|
|
|
(season) =>
|
|
|
|
|
season[is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE
|
|
|
|
|
)
|
|
|
|
|
.map((season) => season.seasonNumber);
|
|
|
|
|
|
|
|
|
|
const changedSeasons = newAvailableSeasons.filter(
|
|
|
|
@ -74,7 +88,7 @@ export class MediaSubscriber implements EntitySubscriberInterface<Media> {
|
|
|
|
|
|
|
|
|
|
for (const changedSeasonNumber of changedSeasons) {
|
|
|
|
|
const requests = await requestRepository.find({
|
|
|
|
|
where: { media: entity, is4k: false },
|
|
|
|
|
where: { media: entity, is4k: true },
|
|
|
|
|
});
|
|
|
|
|
const request = requests.find(
|
|
|
|
|
(request) =>
|
|
|
|
@ -93,7 +107,7 @@ export class MediaSubscriber implements EntitySubscriberInterface<Media> {
|
|
|
|
|
);
|
|
|
|
|
const tv = await tmdb.getTvShow({ tvId: entity.tmdbId });
|
|
|
|
|
notificationManager.sendNotification(Notification.MEDIA_AVAILABLE, {
|
|
|
|
|
event: 'Series Now Available',
|
|
|
|
|
event: `${is4k ? '4K ' : ''}Series Request Now Available`,
|
|
|
|
|
subject: `${tv.name}${
|
|
|
|
|
tv.first_air_date ? ` (${tv.first_air_date.slice(0, 4)})` : ''
|
|
|
|
|
}`,
|
|
|
|
@ -148,7 +162,22 @@ export class MediaSubscriber implements EntitySubscriberInterface<Media> {
|
|
|
|
|
event.entity.mediaType === MediaType.MOVIE &&
|
|
|
|
|
event.entity.status === MediaStatus.AVAILABLE
|
|
|
|
|
) {
|
|
|
|
|
this.notifyAvailableMovie(event.entity as Media, event.databaseEntity);
|
|
|
|
|
this.notifyAvailableMovie(
|
|
|
|
|
event.entity as Media,
|
|
|
|
|
event.databaseEntity,
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
event.entity.mediaType === MediaType.MOVIE &&
|
|
|
|
|
event.entity.status4k === MediaStatus.AVAILABLE
|
|
|
|
|
) {
|
|
|
|
|
this.notifyAvailableMovie(
|
|
|
|
|
event.entity as Media,
|
|
|
|
|
event.databaseEntity,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
@ -156,7 +185,23 @@ export class MediaSubscriber implements EntitySubscriberInterface<Media> {
|
|
|
|
|
(event.entity.status === MediaStatus.AVAILABLE ||
|
|
|
|
|
event.entity.status === MediaStatus.PARTIALLY_AVAILABLE)
|
|
|
|
|
) {
|
|
|
|
|
this.notifyAvailableSeries(event.entity as Media, event.databaseEntity);
|
|
|
|
|
this.notifyAvailableSeries(
|
|
|
|
|
event.entity as Media,
|
|
|
|
|
event.databaseEntity,
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
event.entity.mediaType === MediaType.TV &&
|
|
|
|
|
(event.entity.status4k === MediaStatus.AVAILABLE ||
|
|
|
|
|
event.entity.status4k === MediaStatus.PARTIALLY_AVAILABLE)
|
|
|
|
|
) {
|
|
|
|
|
this.notifyAvailableSeries(
|
|
|
|
|
event.entity as Media,
|
|
|
|
|
event.databaseEntity,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|