Added filters for notifications

Added notifications for tasks
This commit is contained in:
Isaac Abadi
2022-12-31 03:38:03 -05:00
parent bfcc6a0697
commit 4f26e9ac3a
9 changed files with 83 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
const { uuid } = require('uuidv4');
const db_api = require('./db');
const config_api = require('./config');
exports.sendNotification = async (notification) => {
// TODO: hook into third party service
@@ -7,6 +8,15 @@ exports.sendNotification = async (notification) => {
return notification;
}
exports.sendTaskNotification = async (task_obj, confirmed) => {
// workaround for tasks which are user_uid agnostic
const user_uid = config_api.getConfigItem('ytdl_multi_user_mode') ? 'admin' : null;
await db_api.removeAllRecords('notifications', {"data.task_key": task_obj.key});
const data = {task_key: task_obj.key, task_title: task_obj.title, confirmed: confirmed};
const notification = exports.createNotification('task_finished', ['view_tasks'], data, user_uid);
return await exports.sendNotification(notification);
}
exports.sendDownloadNotification = async (file, user_uid) => {
const data = {file_uid: file.uid, file_title: file.title};
const notification = exports.createNotification('download_complete', ['play'], data, user_uid);