Skip to content

Commit c3a9d0a

Browse files
committed
Issues-593: Further watch changes
1 parent d1716ec commit c3a9d0a

File tree

3 files changed

+58
-22
lines changed

3 files changed

+58
-22
lines changed

vanilla/applications/vanilla/models/class.commentmodel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ public function recordAdvancedNotications($activityModel, $activity, $discussion
14351435

14361436
$userID = $row['UserID'];
14371437

1438-
if (in_array($userID, $removeUserIDs)) {
1438+
if ($row['Value'] == '2' && in_array($userID, $removeUserIDs)) {
14391439
continue;
14401440
}
14411441

vanilla/applications/vanilla/models/class.discussionmodel.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,6 +2890,40 @@ public function bookmark($discussionID, $userID, $bookmarked = null) {
28902890
return (int)$bookmarked;
28912891
}
28922892

2893+
/**
2894+
* Bookmarks (or unbookmarks) all discussions in a category for the specified user.
2895+
*
2896+
* @param int|array $CategoryID The id of the category.
2897+
* @param int $userID The unique id of the user.
2898+
* @param bool|null $bookmarked Whether or not to bookmark or unbookmark. Pass null to toggle the bookmark.
2899+
*/
2900+
public function bookmarkAll($categoryID, $userID, $bookmarked) {
2901+
2902+
if(is_numeric($categoryID)) {
2903+
$categoryID = [$categoryID];
2904+
}
2905+
$discussions = $this->SQL
2906+
->select('ud.DiscussionID')
2907+
->from('UserDiscussion ud')
2908+
->join('Discussion d', 'ud.DiscussionID = d.DiscussionID ')
2909+
->join('Category c', 'd.CategoryID = c.CategoryID')
2910+
->where('ud.UserID', $userID)
2911+
->where('c.CategoryID', $categoryID)
2912+
->get()->resultArray();
2913+
$discussionIDs = array_column($discussions, 'DiscussionID');
2914+
if(count($discussionIDs) > 0 ) {
2915+
// Update the bookmarked value.
2916+
$this->SQL
2917+
->update('UserDiscussion')
2918+
->set('Bookmarked', $bookmarked)
2919+
->where('UserID', $userID)
2920+
->where('DiscussionID', $discussionIDs)
2921+
->put();
2922+
2923+
$this->setUserBookmarkCount($userID);
2924+
}
2925+
}
2926+
28932927
/**
28942928
* Bookmarks (or unbookmarks) a discussion for specified user.
28952929
*

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,33 +91,35 @@ function bookmarkButton($discussion) {
9191
);
9292
} else {
9393
$notificationPreferences = $categoryModel->getCategoryNotificationPreferences($discussion->CategoryID, Gdn::session()->UserID);
94-
9594
$categoryNotificationPreferences = $notificationPreferences[$discussion->CategoryID];
96-
$newEmailDiscussionKey = 'Preferences.Email.NewDiscussion.' . $discussion->CategoryID;
95+
$newEmailDiscussionKey = 'Preferences.Email.NewComment.' . $discussion->CategoryID;
96+
//$newPopupDiscussionKey = 'Preferences.Popup.NewComment.' . $discussion->CategoryID;
9797
$hasWatchedCategory = val($newEmailDiscussionKey, $categoryNotificationPreferences);
9898

99-
$hasWatched = false;
100-
// Author is added by default with Bookmarked = 0, Participated = 1
101-
$isAuthor = ($discussion->InsertUserID == Gdn::session()->UserID);
102-
103-
// If Watched Category: unwatched discussion
104-
if ($discussion->Bookmarked === null) {
105-
$hasWatched = $hasWatchedCategory == '1' || $hasWatchedCategory == '2' ? true: false;
106-
$newValue = $hasWatched ? 0 : 1;
107-
} else if ($discussion->Bookmarked == 0) {
108-
$hasWatched = false;
109-
if ($isAuthor) {
110-
$hasWatched = $hasWatchedCategory == '1' || $hasWatchedCategory == '2'? true: false;
111-
$newValue = 2;
112-
} else {
99+
if($hasWatchedCategory == '1') { // The watched category
100+
$hasWatched = true;
101+
$newValue = 0;
102+
} else if($hasWatchedCategory == '2') {// The watched category except some discussions
103+
if ($discussion->Bookmarked === null) {
104+
$hasWatched = true;
105+
$newValue = 0;
106+
} else if ($discussion->Bookmarked == 0) {
107+
$hasWatched = false;
113108
$newValue = 1;
109+
} else if ($discussion->Bookmarked == 1) {
110+
$hasWatched = true;
111+
$newValue = 0;
114112
}
115-
} else if ($discussion->Bookmarked == 1) {
116-
$hasWatched = true;
117-
$newValue = $isAuthor ? 2 : 0;
118-
} else if ($discussion->Bookmarked == 2) {
113+
} else {
119114
$hasWatched = false;
120-
$newValue = 1;
115+
if ($discussion->Bookmarked === null) {
116+
$newValue = 1;
117+
} else if ($discussion->Bookmarked == 0) {
118+
$newValue = 1;
119+
} else if ($discussion->Bookmarked == 1) {
120+
$hasWatched = true;
121+
$newValue = 0;
122+
}
121123
}
122124

123125
$title = t($hasWatched ? 'Stop watching the discussion' : 'Watch the discussion');

0 commit comments

Comments
 (0)