Add support for delayed notification blocking

This commit is contained in:
Jonas Lochmann
2021-12-06 01:00:00 +01:00
parent 6bf6cce720
commit bc80ccc731
8 changed files with 114 additions and 15 deletions
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2020 Jonas Lochmann
* Copyright (C) 2019 - 2021 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -80,7 +80,8 @@ export async function dispatchCreateCategory ({ action, cache, fromChildSelfLimi
taskListVersion: generateVersionId(),
minBatteryCharging: 0,
minBatteryMobile: 0,
flags: '0'
flags: '0',
blockNotificationDelay: '0'
}, { transaction: cache.transaction })
// update the cache
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2020 Jonas Lochmann
* Copyright (C) 2019 - 2021 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -31,13 +31,18 @@ export async function dispatchUpdateCategoryBlockAllNotifications ({ action, cac
categoryId: action.categoryId
},
transaction: cache.transaction,
attributes: ['childId']
attributes: ['childId', 'blockAllNotifications']
})
if (!categoryEntryUnsafe) {
throw new MissingCategoryException()
}
const categoryEntry = {
childId: categoryEntryUnsafe.childId,
blockAllNotifications: categoryEntryUnsafe.blockAllNotifications
}
if (fromChildSelfLimitAddChildUserId !== null) {
if (fromChildSelfLimitAddChildUserId !== categoryEntryUnsafe.childId) {
throw new CanNotModifyOtherUsersBySelfLimitationException()
@@ -46,10 +51,17 @@ export async function dispatchUpdateCategoryBlockAllNotifications ({ action, cac
if (!action.blocked) {
throw new SelfLimitationException({ staticMessage: 'can not disable notification filter as child' })
}
if (categoryEntry.blockAllNotifications && action.blockDelay !== undefined) {
throw new SelfLimitationException({ staticMessage: 'can not update the block delay as child' })
}
}
const [affectedRows] = await cache.database.category.update({
const [affectedRows] = await cache.database.category.update(action.blockDelay === undefined ? {
blockAllNotifications: action.blocked
} : {
blockAllNotifications: action.blocked,
blockNotificationDelay: action.blockDelay.toString(10)
}, {
where: {
familyId: cache.familyId,
@@ -52,7 +52,8 @@ export async function getCategoryBaseDatas ({
'temporarilyBlockedEndTime',
'sort',
'disableLimitsUntil',
'flags'
'flags',
'blockNotificationDelay'
],
transaction
})).map((item) => ({
@@ -72,7 +73,8 @@ export async function getCategoryBaseDatas ({
temporarilyBlockedEndTime: item.temporarilyBlockedEndTime,
sort: item.sort,
disableLimitsUntil: item.disableLimitsUntil,
flags: item.flags
flags: item.flags,
blockNotificationDelay: item.blockNotificationDelay
}))
const networkIdsForSyncing = (await database.categoryNetworkId.findAll({
@@ -117,6 +119,7 @@ export async function getCategoryBaseDatas ({
hashedNetworkId: network.hashedNetworkId
})),
dlu: parseInt(item.disableLimitsUntil, 10),
flags: parseInt(item.flags, 10)
flags: parseInt(item.flags, 10),
blockNotificationDelay: parseInt(item.blockNotificationDelay, 10)
}))
}