diff --git a/vanilla/applications/vanilla/controllers/class.discussioncontroller.php b/vanilla/applications/vanilla/controllers/class.discussioncontroller.php index cbbf9b4..977c7fe 100644 --- a/vanilla/applications/vanilla/controllers/class.discussioncontroller.php +++ b/vanilla/applications/vanilla/controllers/class.discussioncontroller.php @@ -523,6 +523,24 @@ public function bookmark($DiscussionID = null, $bookmarked=null, $tkey=null ) { ]); setValue('Bookmarked', $Discussion, (int)$Bookmark); + $category = CategoryModel::categories($categoryID); + $groupID = val('GroupID', $category); + // FIX: https://github.com/topcoder-platform/forums/issues/577 + // No changes for Challenge Forums + if (!$groupID) { + $categoryModel = new CategoryModel(); + $hasWatchedCategory = $categoryModel->hasWatched($categoryID, Gdn::session()->UserID); + // Category watch to be turned off but don't delete it to get notifications for new discussions + if($hasWatchedCategory && ($Bookmark == 0 || $Bookmark == 2)) { + // Set Preferences to '2' - watching all except unwatched discussions + $categoryModel->setCategoryMetaData($categoryID, Gdn::session()->UserID, 2); + // Category Title: vanilla/applications/vanilla/views/discussions/index.php + $title = val('Name', $category).watchButton($categoryID, false); + $updatedHeaderHtml = '

'.$title.'

'; + $this->jsonTarget('h1.H.HomepageTitle', $updatedHeaderHtml, 'ReplaceWith'); + } + } + // Update the user's bookmark count $CountBookmarks = $this->DiscussionModel->setUserBookmarkCount($UserID); $CountBookmarksHtml = myBookmarksMenuItem($CountBookmarks); diff --git a/vanilla/applications/vanilla/views/discussions/helper_functions.php b/vanilla/applications/vanilla/views/discussions/helper_functions.php index aa43ed6..ebd42fb 100644 --- a/vanilla/applications/vanilla/views/discussions/helper_functions.php +++ b/vanilla/applications/vanilla/views/discussions/helper_functions.php @@ -90,31 +90,36 @@ function bookmarkButton($discussion) { ['title' => $title] ); } else { - $hasWatchedCategory = $categoryModel->hasWatched($discussion->CategoryID, Gdn::session()->UserID); - $hasWatched = false; + $notificationPreferences = $categoryModel->getCategoryNotificationPreferences($discussion->CategoryID, Gdn::session()->UserID); + + $categoryNotificationPreferences = $notificationPreferences[$discussion->CategoryID]; + $newEmailDiscussionKey = 'Preferences.Email.NewDiscussion.' . $discussion->CategoryID; + $hasWatchedCategory = val($newEmailDiscussionKey, $categoryNotificationPreferences); + $hasWatched = false; // Author is added by default with Bookmarked = 0, Participated = 1 $isAuthor = ($discussion->InsertUserID == Gdn::session()->UserID); // If Watched Category: unwatched discussion if ($discussion->Bookmarked === null) { - $hasWatched = $hasWatchedCategory; - $newValue = $hasWatched === true ? 0 : 1; + $hasWatched = $hasWatchedCategory == '1' || $hasWatchedCategory == '2' ? true: false; + $newValue = $hasWatched ? 0 : 1; } else if ($discussion->Bookmarked == 0) { $hasWatched = false; if ($isAuthor) { - $hasWatched = $hasWatchedCategory; + $hasWatched = $hasWatchedCategory == '1' || $hasWatchedCategory == '2'? true: false; $newValue = 2; } else { $newValue = 1; } } else if ($discussion->Bookmarked == 1) { $hasWatched = true; - $newValue = $isAuthor? 2 : 0; + $newValue = $isAuthor ? 2 : 0; } else if ($discussion->Bookmarked == 2) { $hasWatched = false; $newValue = 1; } + $title = t($hasWatched ? 'Stop watching the discussion' : 'Watch the discussion'); $icon = watchIcon($hasWatched, $title); return anchor( @@ -390,8 +395,7 @@ function newComments($discussion) { return ' '.t('new discussion', 'new').''; } elseif ($discussion->CountUnreadComments > 0) { $title = htmlspecialchars(plural($discussion->CountUnreadComments, "%s new comment since you last read this.", "%s new comments since you last read this.")); - - return ' '.plural($discussion->CountUnreadComments, '%s new', '%s new plural', bigPlural($discussion->CountUnreadComments, '%s new', '%s new plural')).''; + return ' '.plural($discussion->CountUnreadComments, '%s new', '%s new plural', bigPlural($discussion->CountUnreadComments, '%s new', '%s new plural')).''; } return ''; }