Added rudimentary notifications for set alerts.
This commit is contained in:
parent
0773a8019c
commit
95f3b1c03a
|
@ -1,6 +1,25 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="details">
|
<div class="details">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
|
<div class="tidbits">
|
||||||
|
<a
|
||||||
|
:title="release.url && `View scene on ${release.entity.name}`"
|
||||||
|
:href="release.url"
|
||||||
|
:class="{ link: release.url }"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
class="tidbit date nolink"
|
||||||
|
>
|
||||||
|
<span class="date-compact">{{ release.date ? formatDate(release.date, 'MMM D, YYYY', release.datePrecision) : 'Date N/A' }}</span>
|
||||||
|
<span class="date-full">{{ release.date ? formatDate(release.date, 'MMMM D, YYYY', release.datePrecision) : 'Date unknown' }}</span>
|
||||||
|
|
||||||
|
<Icon
|
||||||
|
v-if="release.url"
|
||||||
|
icon="share2"
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="site">
|
<div class="site">
|
||||||
<template v-if="release.entity.type === 'channel' && release.entity.parent && !release.entity.independent">
|
<template v-if="release.entity.type === 'channel' && release.entity.parent && !release.entity.independent">
|
||||||
<a
|
<a
|
||||||
|
@ -62,14 +81,6 @@
|
||||||
>
|
>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a
|
|
||||||
class="banner"
|
|
||||||
href="https://enter.julesjordan.com/track/Mzk3MS4yLjMuNi4wLjE1MDQyLjAuMC4w"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
<img src="/img/banners/julesjordan/728x90_jill_kassidy1.jpg">
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -49,6 +49,7 @@ export default {
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.menu-item {
|
.menu-item {
|
||||||
|
color: var(--text);
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,10 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="alert-section alert-trigger">
|
<div
|
||||||
|
v-if="alert.entity"
|
||||||
|
class="alert-section alert-trigger"
|
||||||
|
>
|
||||||
<h4 class="alert-heading">Channel</h4>
|
<h4 class="alert-heading">Channel</h4>
|
||||||
|
|
||||||
<Entity
|
<Entity
|
||||||
|
|
|
@ -1241,6 +1241,33 @@ exports.up = knex => Promise.resolve()
|
||||||
|
|
||||||
table.unique(['alert_id', 'stash_id']);
|
table.unique(['alert_id', 'stash_id']);
|
||||||
}))
|
}))
|
||||||
|
.then(() => knex.schema.createTable('notifications', (table) => {
|
||||||
|
table.increments('id');
|
||||||
|
|
||||||
|
table.integer('user_id')
|
||||||
|
.notNullable()
|
||||||
|
.references('id')
|
||||||
|
.inTable('users')
|
||||||
|
.onDelete('cascade');
|
||||||
|
|
||||||
|
table.integer('scene_id')
|
||||||
|
.references('id')
|
||||||
|
.inTable('releases')
|
||||||
|
.onDelete('cascade');
|
||||||
|
|
||||||
|
table.integer('alert_id')
|
||||||
|
.references('id')
|
||||||
|
.inTable('alerts')
|
||||||
|
.onDelete('set null');
|
||||||
|
|
||||||
|
table.boolean('seen')
|
||||||
|
.notNullable()
|
||||||
|
.defaultTo(false);
|
||||||
|
|
||||||
|
table.datetime('created_at')
|
||||||
|
.notNullable()
|
||||||
|
.defaultTo(knex.fn.now());
|
||||||
|
}))
|
||||||
// SEARCH
|
// SEARCH
|
||||||
.then(() => { // eslint-disable-line arrow-body-style
|
.then(() => { // eslint-disable-line arrow-body-style
|
||||||
// allow vim fold
|
// allow vim fold
|
||||||
|
@ -1631,6 +1658,8 @@ exports.down = (knex) => { // eslint-disable-line arrow-body-style
|
||||||
DROP TABLE IF EXISTS entities_types CASCADE;
|
DROP TABLE IF EXISTS entities_types CASCADE;
|
||||||
DROP TABLE IF EXISTS entities CASCADE;
|
DROP TABLE IF EXISTS entities CASCADE;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS notifications CASCADE;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS stashes_scenes CASCADE;
|
DROP TABLE IF EXISTS stashes_scenes CASCADE;
|
||||||
DROP TABLE IF EXISTS stashes_movies CASCADE;
|
DROP TABLE IF EXISTS stashes_movies CASCADE;
|
||||||
DROP TABLE IF EXISTS stashes_actors CASCADE;
|
DROP TABLE IF EXISTS stashes_actors CASCADE;
|
||||||
|
|
|
@ -259,7 +259,7 @@ async function fetchLatest(entity, page, options) {
|
||||||
|
|
||||||
release.tags = await knex('tags')
|
release.tags = await knex('tags')
|
||||||
.select('name')
|
.select('name')
|
||||||
.where('priority', '>', 5)
|
.where('priority', '>', 7)
|
||||||
.orderByRaw('random()')
|
.orderByRaw('random()')
|
||||||
.limit(faker.random.number({ min: 2, max: 15 }))
|
.limit(faker.random.number({ min: 2, max: 15 }))
|
||||||
.pluck('name');
|
.pluck('name');
|
||||||
|
|
|
@ -211,6 +211,64 @@ 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,
|
||||||
|
})));
|
||||||
|
|
||||||
|
console.log(releases.rows);
|
||||||
|
|
||||||
|
return releases.rows;
|
||||||
|
}
|
||||||
|
|
||||||
async function updateReleasesSearch(releaseIds) {
|
async function updateReleasesSearch(releaseIds) {
|
||||||
logger.info(`Updating search documents for ${releaseIds ? releaseIds.length : 'all' } releases`);
|
logger.info(`Updating search documents for ${releaseIds ? releaseIds.length : 'all' } releases`);
|
||||||
|
|
||||||
|
@ -338,6 +396,8 @@ async function storeScenes(releases) {
|
||||||
|
|
||||||
logger.info(`Stored ${storedReleaseEntries.length} releases`);
|
logger.info(`Stored ${storedReleaseEntries.length} releases`);
|
||||||
|
|
||||||
|
await notifyAlerts(releasesWithId);
|
||||||
|
|
||||||
return releasesWithId;
|
return releasesWithId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue