notifications: clearAlert
This commit is contained in:
@@ -17,6 +17,7 @@ exports = module.exports = {
|
||||
ALERT_MANUAL_APP_UPDATE: 'manualAppUpdate',
|
||||
|
||||
alert,
|
||||
clearAlert,
|
||||
|
||||
// exported for testing
|
||||
_add: add
|
||||
@@ -233,25 +234,29 @@ async function alert(id, title, message) {
|
||||
|
||||
const result = await getByTitle(title);
|
||||
|
||||
if (message) {
|
||||
if (!result) {
|
||||
return await add(null /* eventId */, title, message);
|
||||
} else {
|
||||
await update(result, {
|
||||
eventId: null,
|
||||
title,
|
||||
message,
|
||||
acknowledged: false,
|
||||
creationTime: new Date()
|
||||
});
|
||||
return result.id;
|
||||
}
|
||||
if (!result) {
|
||||
return await add(null /* eventId */, title, message);
|
||||
} else {
|
||||
await database.query('DELETE FROM notifications WHERE title = ?', [ title ]);
|
||||
return null;
|
||||
await update(result, {
|
||||
eventId: null,
|
||||
title,
|
||||
message,
|
||||
acknowledged: false,
|
||||
creationTime: new Date()
|
||||
});
|
||||
return result.id;
|
||||
}
|
||||
}
|
||||
|
||||
// id is unused but nice to search code
|
||||
async function clearAlert(id, title) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert.strictEqual(typeof title, 'string');
|
||||
|
||||
await database.query('DELETE FROM notifications WHERE title = ?', [ title ]);
|
||||
return null;
|
||||
}
|
||||
|
||||
async function onEvent(id, action, source, data) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert.strictEqual(typeof action, 'string');
|
||||
|
||||
Reference in New Issue
Block a user