Skip to content

Issues-577: Watching feature #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<h1 class="H HomepageTitle">'.$title.'</h1>';
$this->jsonTarget('h1.H.HomepageTitle', $updatedHeaderHtml, 'ReplaceWith');
}
}

// Update the user's bookmark count
$CountBookmarks = $this->DiscussionModel->setUserBookmarkCount($UserID);
$CountBookmarksHtml = myBookmarksMenuItem($CountBookmarks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -390,8 +395,7 @@ function newComments($discussion) {
return ' <span class="MItem"><strong class="HasNew JustNew NewCommentCount" title="'.$title.'">'.t('new discussion', 'new').'</strong></span>';
} 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 ' <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>';
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>';
}
return '';
}
Expand Down