diff --git a/lib/models/BlubberThread.php b/lib/models/BlubberThread.php index 1ff28bea999d2823e87686aeb4fbb91779d5f8d5..bc721e0f9b9894311f4b82f97c9c3da071be1407 100644 --- a/lib/models/BlubberThread.php +++ b/lib/models/BlubberThread.php @@ -520,6 +520,7 @@ class BlubberThread extends SimpleORMap implements PrivacyObject $template = $GLOBALS['template_factory']->open('blubber/institute_context'); $template->thread = $this; $template->institute = Institute::find($this['context_id']); + $template->unfollowed = !$this->isFollowedByUser(); return $template; } } @@ -848,7 +849,7 @@ class BlubberThread extends SimpleORMap implements PrivacyObject $this->getLastVisit() ?: object_get_visit_threshold(), $user_id ]), - 'notifications' => $this->id === 'global' || ($this->context_type === 'course' && !$GLOBALS['perm']->have_perm('admin')), + 'notifications' => $this->mayDisableNotifications(), 'followed' => $this->isFollowedByUser(), ]; $context_info = $this->getContextTemplate(); @@ -1041,4 +1042,26 @@ class BlubberThread extends SimpleORMap implements PrivacyObject } return $institut_ids; } + + /** + * Returns whether the notifications for this thread may be disabled. + * + * @return bool + */ + public function mayDisableNotifications(): bool + { + // Notifications may always be disabled for global blubber stream + if ($this->id === 'global') { + return true; + } + + // Notifications may not be disabled outside of course and institute + // streams + if (!in_array($this->context_type, ['course', 'institute'])) { + return false; + } + + // Only users with permission below admin may disable the notifications. + return !$GLOBALS['perm']->have_perm('admin'); + } } diff --git a/resources/vue/components/BlubberThread.vue b/resources/vue/components/BlubberThread.vue index 5feb8bde17acc8f3e9134047a07622b625621999..bb742feaa7d4ed79362a28656fafca516d31e11e 100644 --- a/resources/vue/components/BlubberThread.vue +++ b/resources/vue/components/BlubberThread.vue @@ -10,7 +10,7 @@ :class="{unfollowed: !thread_data.followed}" :title="$gettext('Benachrichtigungen für diese Konversation abstellen.')" :data-thread_id="thread_data.thread_posting.thread_id"> - <StudipIcon shape="remove/notification2" :size="20" class="follow text-bottom"></StudipIcon> + <StudipIcon shape="decline" :size="20" class="follow text-bottom"></StudipIcon> <StudipIcon shape="notification2" :size="20" class="unfollow text-bottom"></StudipIcon> {{ $gettext('Benachrichtigungen aktiviert') }} </a> diff --git a/templates/blubber/course_context.php b/templates/blubber/course_context.php index e4fd91b4b09315e2ef600775f726c497eb1fecaf..206397a4186a43a86b49cca937108e715b446857 100644 --- a/templates/blubber/course_context.php +++ b/templates/blubber/course_context.php @@ -58,16 +58,4 @@ </div> </div> <?= $this->render_partial("blubber/_tagcloud") ?> -<? if (!$GLOBALS['perm']->have_perm("admin")) : ?> - <div class="indented new_section"> - <a href="#" - onClick="STUDIP.Blubber.followunfollow('<?= htmlReady($thread->id) ?>'); return false;" - class="followunfollow<?= $unfollowed ? " unfollowed" : "" ?>" - title="<?= _("Benachrichtigungen für diese Konversation abstellen.") ?>" - data-thread_id="<?= htmlReady($thread->id) ?>"> - <?= Icon::create("decline")->asImg(20, ['class' => "follow text-bottom"]) ?> - <?= Icon::create("notification2")->asImg(20, ['class' => "unfollow text-bottom"]) ?> - <?= _("Benachrichtigungen aktiviert") ?> - </a> - </div> -<? endif ?> +<?= $this->render_partial('blubber/disable-notifications', compact('thread', 'unfollowed')) ?> diff --git a/templates/blubber/disable-notifications.php b/templates/blubber/disable-notifications.php new file mode 100644 index 0000000000000000000000000000000000000000..a3a63c400947f321f152ec56e9c921535fde87d5 --- /dev/null +++ b/templates/blubber/disable-notifications.php @@ -0,0 +1,13 @@ +<? if (!$GLOBALS['perm']->have_perm("admin")) : ?> + <div class="indented new_section"> + <a href="#" + onClick="STUDIP.Blubber.followunfollow('<?= htmlReady($thread->id) ?>'); return false;" + class="followunfollow<?= $unfollowed ? " unfollowed" : "" ?>" + title="<?= _("Benachrichtigungen für diese Konversation abstellen.") ?>" + data-thread_id="<?= htmlReady($thread->id) ?>"> + <?= Icon::create("decline")->asImg(20, ['class' => "follow text-bottom"]) ?> + <?= Icon::create("notification2")->asImg(20, ['class' => "unfollow text-bottom"]) ?> + <?= _("Benachrichtigungen aktiviert") ?> + </a> + </div> +<? endif ?> diff --git a/templates/blubber/institute_context.php b/templates/blubber/institute_context.php index 6e0fa291abcab0d419e91c0ef1be91f7c7329060..130378e15b9f0b4460e3033f812c30c717ffb14b 100644 --- a/templates/blubber/institute_context.php +++ b/templates/blubber/institute_context.php @@ -11,3 +11,4 @@ </div> </div> </div> +<?= $this->render_partial('blubber/disable-notifications', compact('thread', 'unfollowed')) ?>