Add action to configure blocking all notifications

This commit is contained in:
Jonas L 2019-03-04 00:00:00 +00:00
parent 9dc8a6caab
commit 7ae4c30e3e
3 changed files with 33 additions and 0 deletions

View file

@ -877,6 +877,28 @@ data class UpdateCategoryBlockedTimesAction(val categoryId: String, val blockedT
} }
} }
data class UpdateCategoryBlockAllNotificationsAction(val categoryId: String, val blocked: Boolean): ParentAction() {
companion object {
private const val TYPE_VALUE = "UPDATE_CATEGORY_BLOCK_ALL_NOTIFICATIONS"
private const val CATEGORY_ID = "categoryId"
private const val BLOCK = "blocked"
}
init {
IdGenerator.assertIdValid(categoryId)
}
override fun serialize(writer: JsonWriter) {
writer.beginObject()
writer.name(TYPE).value(TYPE_VALUE)
writer.name(CATEGORY_ID).value(categoryId)
writer.name(BLOCK).value(blocked)
writer.endObject()
}
}
data class CreateTimeLimitRuleAction(val rule: TimeLimitRule): ParentAction() { data class CreateTimeLimitRuleAction(val rule: TimeLimitRule): ParentAction() {
companion object { companion object {
const val TYPE_VALUE = "CREATE_TIMELIMIT_RULE" const val TYPE_VALUE = "CREATE_TIMELIMIT_RULE"

View file

@ -60,6 +60,7 @@ object ActionParser {
// SetConsiderRebootManipulationAction // SetConsiderRebootManipulationAction
// RenameChildAction // RenameChildAction
// UpdateParentNotificationFlagsAction // UpdateParentNotificationFlagsAction
// UpdateCategoryBlockAllNotificationsAction
else -> throw IllegalStateException() else -> throw IllegalStateException()
} }
} }

View file

@ -454,6 +454,16 @@ object LocalDatabaseParentActionDispatcher {
) )
) )
} }
is UpdateCategoryBlockAllNotificationsAction -> {
val categoryEntry = database.category().getCategoryByIdSync(action.categoryId)
?: throw IllegalArgumentException("can not update notification blocking for non exsistent category")
database.category().updateCategorySync(
categoryEntry.copy(
blockAllNotifications = action.blocked
)
)
}
}.let { } }.let { }
database.setTransactionSuccessful() database.setTransactionSuccessful()