Added quick alert button to actor bio.
This commit is contained in:
@@ -120,6 +120,7 @@ export async function createAlert(alert, reqUser) {
|
||||
all_entities: alert.allEntities,
|
||||
all_tags: alert.allTags,
|
||||
all_matches: alert.allMatches,
|
||||
from_preset: alert.preset,
|
||||
})
|
||||
.returning('id');
|
||||
|
||||
@@ -149,14 +150,43 @@ export async function createAlert(alert, reqUser) {
|
||||
})).slice(0, alert.allEntities ? 1 : Infinity)), // one scene can never match multiple entities in AND mode
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
alert.actors?.length > 0 && knex.schema.refreshMaterializedView('alerts_users_actors'),
|
||||
alert.tags?.length > 0 && knex.schema.refreshMaterializedView('alerts_users_tags'),
|
||||
alert.entities?.length > 0 && knex.schema.refreshMaterializedView('alerts_users_entities'),
|
||||
]);
|
||||
|
||||
return alertId;
|
||||
}
|
||||
|
||||
export async function removeAlert(alertId, reqUser) {
|
||||
const alert = await knex('alerts')
|
||||
.where('alerts.id', alertId)
|
||||
.select(
|
||||
'alerts.id',
|
||||
knex.raw('coalesce(array_agg(distinct alerts_actors.actor_id) filter (where alerts_actors.actor_id is not null), \'{}\') as actor_ids'),
|
||||
knex.raw('coalesce(array_agg(distinct alerts_entities.entity_id) filter (where alerts_entities.entity_id is not null), \'{}\') as entity_ids'),
|
||||
knex.raw('coalesce(array_agg(distinct alerts_tags.tag_id) filter (where alerts_tags.tag_id is not null), \'{}\') as tag_ids'),
|
||||
)
|
||||
.leftJoin('alerts_actors', 'alerts_actors.alert_id', 'alerts.id')
|
||||
.leftJoin('alerts_entities', 'alerts_entities.alert_id', 'alerts.id')
|
||||
.leftJoin('alerts_tags', 'alerts_tags.alert_id', 'alerts.id')
|
||||
.leftJoin('alerts_matches', 'alerts_matches.alert_id', 'alerts.id')
|
||||
.groupBy('alerts.id')
|
||||
.first();
|
||||
|
||||
console.log(alertId, alert);
|
||||
|
||||
await knex('alerts')
|
||||
.where('id', alertId)
|
||||
.where('user_id', reqUser.id)
|
||||
.delete();
|
||||
|
||||
await Promise.all([
|
||||
alert.actor_ids.length > 0 && knex.schema.refreshMaterializedView('alerts_users_actors'),
|
||||
alert.tag_ids.length > 0 && knex.schema.refreshMaterializedView('alerts_users_tags'),
|
||||
alert.entity_ids?.length > 0 && knex.schema.refreshMaterializedView('alerts_users_entities'),
|
||||
]);
|
||||
}
|
||||
|
||||
export async function fetchUnseenNotificationsCount(reqUser) {
|
||||
|
||||
Reference in New Issue
Block a user