Added notification clear, improved notification styling.
This commit is contained in:
@@ -13,6 +13,7 @@ const { associateActors, associateDirectors, scrapeActors, toBaseActors } = requ
|
||||
const { associateReleaseTags } = require('./tags');
|
||||
const { curateEntity } = require('./entities');
|
||||
const { associateReleaseMedia } = require('./media');
|
||||
const { notify } = require('./alerts');
|
||||
|
||||
async function curateReleaseEntry(release, batchId, existingRelease, type = 'scene') {
|
||||
const slugBase = release.title
|
||||
@@ -211,62 +212,6 @@ async function filterDuplicateReleases(releases) {
|
||||
};
|
||||
}
|
||||
|
||||
async function notifyAlerts(scenes) {
|
||||
const releases = await knex.raw(`
|
||||
SELECT alerts.id as alert_id, alerts.notify, alerts.email, releases.id as scene_id, users.id as user_id
|
||||
FROM releases
|
||||
CROSS JOIN alerts
|
||||
LEFT JOIN users ON users.id = alerts.user_id
|
||||
LEFT JOIN releases_tags ON releases_tags.release_id = releases.id
|
||||
/* match updated IDs from input */
|
||||
WHERE (releases.id = ANY(:sceneIds))
|
||||
/* match tags */
|
||||
AND (NOT EXISTS (SELECT alerts_tags.alert_id
|
||||
FROM alerts_tags
|
||||
WHERE alerts_tags.alert_id = alerts.id)
|
||||
OR (SELECT array_agg(releases_tags.tag_id)
|
||||
FROM releases_tags
|
||||
WHERE releases_tags.release_id = releases.id
|
||||
GROUP BY releases_tags.release_id)
|
||||
@> (SELECT array_agg(alerts_tags.tag_id)
|
||||
FROM alerts_tags
|
||||
WHERE alerts_tags.alert_id = alerts.id
|
||||
GROUP BY alerts_tags.alert_id))
|
||||
/* match actors */
|
||||
AND (NOT EXISTS (SELECT alerts_actors.alert_id
|
||||
FROM alerts_actors
|
||||
WHERE alerts_actors.alert_id = alerts.id)
|
||||
OR (SELECT array_agg(releases_actors.actor_id)
|
||||
FROM releases_actors
|
||||
WHERE releases_actors.release_id = releases.id
|
||||
GROUP BY releases_actors.release_id)
|
||||
@> (SELECT array_agg(alerts_actors.actor_id)
|
||||
FROM alerts_actors
|
||||
WHERE alerts_actors.alert_id = alerts.id
|
||||
GROUP BY alerts_actors.alert_id))
|
||||
/* match entity */
|
||||
AND ((NOT EXISTS (SELECT alerts_entities.entity_id
|
||||
FROM alerts_entities
|
||||
WHERE alerts_entities.alert_id = alerts.id))
|
||||
OR (releases.entity_id
|
||||
= ANY(array(SELECT alerts_entities.entity_id
|
||||
FROM alerts_entities
|
||||
WHERE alerts_entities.alert_id = alerts.id))))
|
||||
GROUP BY releases.id, users.id, alerts.id;
|
||||
`, { sceneIds: scenes.map(scene => scene.id) });
|
||||
|
||||
const notify = releases.rows.filter(alert => alert.notify);
|
||||
|
||||
await knex('notifications')
|
||||
.insert(notify.map(notification => ({
|
||||
user_id: notification.user_id,
|
||||
alert_id: notification.alert_id,
|
||||
scene_id: notification.scene_id,
|
||||
})));
|
||||
|
||||
return releases.rows;
|
||||
}
|
||||
|
||||
async function updateReleasesSearch(releaseIds) {
|
||||
logger.info(`Updating search documents for ${releaseIds ? releaseIds.length : 'all' } releases`);
|
||||
|
||||
@@ -394,7 +339,7 @@ async function storeScenes(releases) {
|
||||
|
||||
logger.info(`Stored ${storedReleaseEntries.length} releases`);
|
||||
|
||||
await notifyAlerts(releasesWithId);
|
||||
await notify(releasesWithId);
|
||||
|
||||
return releasesWithId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user