Completed notification functionality

Minor code cleanup
This commit is contained in:
Isaac Abadi
2022-11-25 17:47:30 -05:00
parent 4583e3e5d4
commit b51f45c704
17 changed files with 232 additions and 99 deletions

View File

@@ -14,6 +14,7 @@ const { create } = require('xmlbuilder2');
const categories_api = require('./categories');
const utils = require('./utils');
const db_api = require('./db');
const notifications_api = require('./notifications');
const mutex = new Mutex();
let should_check_downloads = true;
@@ -341,6 +342,8 @@ async function downloadQueuedFile(download_uid) {
// registers file in DB
const file_obj = await db_api.registerFileDB(full_file_path, type, download['user_uid'], category, download['sub_id'] ? download['sub_id'] : null, options.cropFileSettings);
notifications_api.sendDownloadNotification(file_obj, download['user_uid']);
file_objs.push(file_obj);
}

View File

@@ -1,13 +1,32 @@
const utils = require('./utils');
const logger = require('./logger');
const { uuid } = require('uuidv4');
const db_api = require('./db');
exports.sendNotification = async () => {
exports.sendNotification = async (notification) => {
// TODO: hook into third party service
const notification = {}
await db_api.insertRecordIntoTable('notifications', notification);
return 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);
return await exports.sendNotification(notification);
}
exports.sendDownloadErrorNotification = async (download, user_uid) => {
const data = {download_uid: download.uid, download_url: download.url};
const notification = exports.createNotification('download_error', ['view_download_error', 'retry_download'], data, user_uid);
return await exports.sendNotification(notification);
}
exports.createNotification = (type, actions, data, user_uid) => {
const notification = {
type: type,
actions: actions,
data: data,
user_uid: user_uid,
uid: uuid(),
read: false
}
return notification;
}