Skip to content

Commit 7c08db0

Browse files
authored
Merge pull request #591 from topcoder-platform/issues-577
Issues-577: Watching feature
2 parents 4ece750 + 6f768b2 commit 7c08db0

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

vanilla/applications/vanilla/controllers/class.discussioncontroller.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,24 @@ public function bookmark($DiscussionID = null, $bookmarked=null, $tkey=null ) {
523523
]);
524524
setValue('Bookmarked', $Discussion, (int)$Bookmark);
525525

526+
$category = CategoryModel::categories($categoryID);
527+
$groupID = val('GroupID', $category);
528+
// FIX: https://github.com/topcoder-platform/forums/issues/577
529+
// No changes for Challenge Forums
530+
if (!$groupID) {
531+
$categoryModel = new CategoryModel();
532+
$hasWatchedCategory = $categoryModel->hasWatched($categoryID, Gdn::session()->UserID);
533+
// Category watch to be turned off but don't delete it to get notifications for new discussions
534+
if($hasWatchedCategory && ($Bookmark == 0 || $Bookmark == 2)) {
535+
// Set Preferences to '2' - watching all except unwatched discussions
536+
$categoryModel->setCategoryMetaData($categoryID, Gdn::session()->UserID, 2);
537+
// Category Title: vanilla/applications/vanilla/views/discussions/index.php
538+
$title = val('Name', $category).watchButton($categoryID, false);
539+
$updatedHeaderHtml = '<h1 class="H HomepageTitle">'.$title.'</h1>';
540+
$this->jsonTarget('h1.H.HomepageTitle', $updatedHeaderHtml, 'ReplaceWith');
541+
}
542+
}
543+
526544
// Update the user's bookmark count
527545
$CountBookmarks = $this->DiscussionModel->setUserBookmarkCount($UserID);
528546
$CountBookmarksHtml = myBookmarksMenuItem($CountBookmarks);

vanilla/applications/vanilla/views/discussions/helper_functions.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,31 +90,36 @@ function bookmarkButton($discussion) {
9090
['title' => $title]
9191
);
9292
} else {
93-
$hasWatchedCategory = $categoryModel->hasWatched($discussion->CategoryID, Gdn::session()->UserID);
94-
$hasWatched = false;
93+
$notificationPreferences = $categoryModel->getCategoryNotificationPreferences($discussion->CategoryID, Gdn::session()->UserID);
94+
95+
$categoryNotificationPreferences = $notificationPreferences[$discussion->CategoryID];
96+
$newEmailDiscussionKey = 'Preferences.Email.NewDiscussion.' . $discussion->CategoryID;
97+
$hasWatchedCategory = val($newEmailDiscussionKey, $categoryNotificationPreferences);
9598

99+
$hasWatched = false;
96100
// Author is added by default with Bookmarked = 0, Participated = 1
97101
$isAuthor = ($discussion->InsertUserID == Gdn::session()->UserID);
98102

99103
// If Watched Category: unwatched discussion
100104
if ($discussion->Bookmarked === null) {
101-
$hasWatched = $hasWatchedCategory;
102-
$newValue = $hasWatched === true ? 0 : 1;
105+
$hasWatched = $hasWatchedCategory == '1' || $hasWatchedCategory == '2' ? true: false;
106+
$newValue = $hasWatched ? 0 : 1;
103107
} else if ($discussion->Bookmarked == 0) {
104108
$hasWatched = false;
105109
if ($isAuthor) {
106-
$hasWatched = $hasWatchedCategory;
110+
$hasWatched = $hasWatchedCategory == '1' || $hasWatchedCategory == '2'? true: false;
107111
$newValue = 2;
108112
} else {
109113
$newValue = 1;
110114
}
111115
} else if ($discussion->Bookmarked == 1) {
112116
$hasWatched = true;
113-
$newValue = $isAuthor? 2 : 0;
117+
$newValue = $isAuthor ? 2 : 0;
114118
} else if ($discussion->Bookmarked == 2) {
115119
$hasWatched = false;
116120
$newValue = 1;
117121
}
122+
118123
$title = t($hasWatched ? 'Stop watching the discussion' : 'Watch the discussion');
119124
$icon = watchIcon($hasWatched, $title);
120125
return anchor(
@@ -390,8 +395,7 @@ function newComments($discussion) {
390395
return ' <span class="MItem"><strong class="HasNew JustNew NewCommentCount" title="'.$title.'">'.t('new discussion', 'new').'</strong></span>';
391396
} elseif ($discussion->CountUnreadComments > 0) {
392397
$title = htmlspecialchars(plural($discussion->CountUnreadComments, "%s new comment since you last read this.", "%s new comments since you last read this."));
393-
394-
return ' <span class="MItem"><strong class="HasNew NewCommentCount" title="'.$title.'">'.plural($discussion->CountUnreadComments, '%s new', '%s new plural', bigPlural($discussion->CountUnreadComments, '%s new', '%s new plural')).'</strong><span>';
398+
return ' <span class="MItem"><strong class="HasNew NewCommentCount" title="'.$title.'">'.plural($discussion->CountUnreadComments, '%s new', '%s new plural', bigPlural($discussion->CountUnreadComments, '%s new', '%s new plural')).'</strong></span>';
395399
}
396400
return '';
397401
}

0 commit comments

Comments
 (0)