Skip to content

Commit

Permalink
Only offer on/off setting when a board is not shared
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Nov 6, 2020
1 parent 40cfed4 commit 6b4d4d9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
27 changes: 19 additions & 8 deletions lib/Notification/NotificationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,27 @@ public function sendCardDuedate($card) {
return;
}

// TODO: Once assigning users is possible, those should be notified instead of all users of the board
$boardId = $this->cardMapper->findBoardId($card->getId());
$board = $this->getBoard($boardId);
$board = $this->getBoard($boardId, false, true);
/** @var User $user */
foreach ($this->permissionService->findUsers($boardId) as $user) {
$notificationSetting = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'board:' . $boardId . ':notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_DEFAULT);
if (
$notificationSetting === ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL ||
($notificationSetting === ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED && $this->assignedUsersMapper->isUserAssigned($card->getId(), $user->getUID()))
) {

if ($notificationSetting === ConfigService::SETTING_BOARD_NOTIFICATION_DUE_OFF) {
continue;
}

$shouldNotify = $notificationSetting === ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL;

if ($user->getUID() === $board->getOwner() && count($board->getAcl()) === 0) {
// Notify if all or assigned is configured for unshared boards
$shouldNotify = true;
} else if ($notificationSetting === ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED && $this->assignedUsersMapper->isUserAssigned($card->getId(), $user->getUID())) {
// Notify if the user is assigned and has the assigned setting selected
$shouldNotify = true;
}

if ($shouldNotify) {
$notification = $this->notificationManager->createNotification();
$notification
->setApp('deck')
Expand Down Expand Up @@ -187,9 +198,9 @@ public function sendMention(IComment $comment) {
* @return Board
* @throws \OCP\AppFramework\Db\DoesNotExistException
*/
private function getBoard($boardId) {
private function getBoard($boardId, bool $withLabels = false, bool $withAcl = false) {
if (!array_key_exists($boardId, $this->boards)) {
$this->boards[$boardId] = $this->boardMapper->find($boardId);
$this->boards[$boardId] = $this->boardMapper->find($boardId, $withLabels, $withAcl);
}
return $this->boards[$boardId];
}
Expand Down
43 changes: 42 additions & 1 deletion src/components/navigation/AppNavigationBoard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,44 @@
{{ t('deck', 'Archive board') }}
</ActionButton>

<ActionButton :icon="!showDueSettings ? 'icon-notifications-dark' : 'icon-view-previous' " @click="showDueSettings=!showDueSettings">
<!-- Due date reminder settings -->

<ActionButton v-if="showDueSettings"
:icon="updateDueSetting ? 'icon-loading-small' : 'icon-view-previous'"
:disabled="updateDueSetting"
@click="showDueSettings=false">
{{ t('deck', 'Due date reminders') }}
</ActionButton>
<ActionButton v-else-if="board.acl.length > 0"
:title="t('deck', 'Due date reminders')"
:icon="dueDateReminderIcon"
@click="showDueSettings=true">
{{ dueDateReminderText }}
</ActionButton>
<ActionButton v-else :icon="board.settings['notify-due'] === 'off' ? 'icon-sound' : 'icon-sound-off'" @click="board.settings['notify-due'] === 'off' ? updateSetting('notify-due', 'all') : updateSetting('notify-due', 'off')">
{{ board.settings['notify-due'] === 'off' ? t('deck', 'Turn on due date reminders') : t('deck', 'Turn off due date reminders') }}
</ActionButton>

<ActionButton v-if="showDueSettings"
name="notification"
icon="icon-sound"
:disabled="updateDueSetting"
:class="{ 'forced-active': board.settings['notify-due'] === 'all' }"
@click="updateSetting('notify-due', 'all')">
{{ t('deck', 'All cards') }}
</ActionButton>
<ActionButton v-if="showDueSettings"
name="notification"
icon="icon-user"
:disabled="updateDueSetting"
:class="{ 'forced-active': board.settings['notify-due'] === 'assigned' }"
@click="updateSetting('notify-due', 'assigned')">
{{ t('deck', 'Assigned cards') }}
</ActionButton>
<ActionButton v-if="showDueSettings"
name="notification"
icon="icon-sound-off"
:disabled="updateDueSetting"
:class="{ 'forced-active': board.settings['notify-due'] === 'off' }"
@click="updateSetting('notify-due', 'off')">
{{ t('deck', 'No notifications') }}
Expand Down Expand Up @@ -145,6 +162,7 @@ export default {
editTitle: '',
editColor: '',
showDueSettings: false,
updateDueSetting: null,
}
},
computed: {
Expand All @@ -166,6 +184,26 @@ export default {
canManage() {
return this.board.permissions.PERMISSION_MANAGE
},
dueDateReminderIcon() {
if (this.board.settings['notify-due'] === 'all') {
return 'icon-sound'
} else if (this.board.settings['notify-due'] === 'assigned') {
return 'icon-user'
} else if (this.board.settings['notify-due'] === 'off') {
return 'icon-sound-off'
}
return ''
},
dueDateReminderText() {
if (this.board.settings['notify-due'] === 'all') {
return t('deck', 'All cards')
} else if (this.board.settings['notify-due'] === 'assigned') {
return t('deck', 'Only assigned cards')
} else if (this.board.settings['notify-due'] === 'off') {
return t('deck', 'No reminder')
}
return ''
},
},
watch: {},
mounted() {
Expand Down Expand Up @@ -262,9 +300,12 @@ export default {
this.$router.push(route)
},
async updateSetting(key, value) {
this.updateDueSetting = value
const setting = {}
setting['board:' + this.board.id + ':' + key] = value
await this.$store.dispatch('setConfig', setting)
this.showDueSettings = false
this.updateDueSetting = null
},
},
inject: [
Expand Down

0 comments on commit 6b4d4d9

Please sign in to comment.