Skip to content

Commit c990398

Browse files
authored
Merge pull request #531 from topcoder-platform/issues-511
Issues-511: Replay placement, Issues-523, Issues-518
2 parents f8664f0 + 87468c5 commit c990398

File tree

7 files changed

+70
-16
lines changed

7 files changed

+70
-16
lines changed

config/vanilla/bootstrap.early.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,13 @@
162162
// Set count of WatchedCategories for users
163163
Gdn::sql()->query('update GDN_User u set u.CountWatchedCategories = (
164164
select count(c.CategoryID) from GDN_Category c, (select distinct CAST(SUBSTRING_INDEX(um.Name, ".", -1) as UNSIGNED) as CategoryID from GDN_UserMeta um
165-
where um.Name LIKE "Preferences.%" AND UserID = u.UserID and Value = 1) ws where ws.CategoryID = c.CategoryID)');
165+
where um.Name LIKE "Preferences.%" AND UserID = u.UserID and Value = 1) ws where ws.CategoryID = c.CategoryID)', 'update');
166166

167167
}
168+
169+
// FIX: https://github.com/topcoder-platform/forums/issues/479
170+
// Re-calculate count of WatchedCategories if WatchedCategories is null
171+
Gdn::sql()->query('update GDN_User u set u.CountWatchedCategories = (
172+
select count(c.CategoryID) from GDN_Category c, (select distinct CAST(SUBSTRING_INDEX(um.Name, ".", -1) as UNSIGNED) as CategoryID from GDN_UserMeta um
173+
where um.Name LIKE "Preferences.%" AND UserID = u.UserID and Value = 1) ws where ws.CategoryID = c.CategoryID) where CountWatchedCategories is null', 'update');
168174
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ public function deleteComment($commentID = '', $transientKey = '') {
796796

797797
if ($comment && $discussion) {
798798
$defaultTarget = discussionUrl($discussion);
799-
799+
$this->json('DiscussionID', $discussionID);
800800
// Make sure comment is this user's or they have Delete permission.
801801
if ($comment->InsertUserID != $session->UserID || !c('Vanilla.Comments.AllowSelfDelete')) {
802802
$this->categoryPermission($discussion->CategoryID, 'Vanilla.Comments.Delete');
@@ -811,6 +811,12 @@ public function deleteComment($commentID = '', $transientKey = '') {
811811
// Delete the comment.
812812
if (!$this->CommentModel->deleteID($commentID)) {
813813
$this->Form->addError('Failed to delete comment');
814+
} else {
815+
// FIX: https://github.com/topcoder-platform/forums/issues/511
816+
// Allow plugins to handle it
817+
$this->EventArguments['DiscussionID'] = $discussionID;
818+
$this->EventArguments['CommentID'] = $commentID;
819+
$this->fireEvent('AfterCommentDeleted');
814820
}
815821
} else {
816822
$this->Form->addError('Invalid comment');

vanilla/applications/vanilla/controllers/class.postcontroller.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,12 @@ public function discussion($categoryUrlCode = '', $announce = '') {
395395
$this->EventArguments['Discussion'] = $discussion;
396396
$this->fireEvent('AfterDiscussionSave');
397397

398+
// FIX: https://github.com/topcoder-platform/forums/issues/511
399+
// if /discussion/{discussionID}/p{Page} is used then view mode is flat
398400
if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
399-
redirectTo(discussionUrl($discussion, 1).'?new=1');
401+
redirectTo(discussionUrl($discussion).'?new=1');
400402
} else {
401-
$this->setRedirectTo(discussionUrl($discussion, 1, true).'?new=1');
403+
$this->setRedirectTo(discussionUrl($discussion).'?new=1');
402404
}
403405
} else {
404406
// If this was a draft save, notify the user about the save

vanilla/applications/vanilla/js/discussion.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ jQuery(document).ready(function($) {
135135
$('div.Popup,.Overlay').remove();
136136

137137
var commentID = json.CommentID;
138+
var parentCommentID = json.ParentCommentID;
138139

139140
// Assign the comment id to the form if it was defined
140141
if (commentID != null && commentID != '') {
@@ -194,11 +195,19 @@ jQuery(document).ready(function($) {
194195
$(json.Data).prependTo('ul.Comments,.DiscussionTable');
195196
$('ul.Comments li:first').effect("highlight", {}, "slow");
196197
} else {
197-
$(json.Data)
198-
.appendTo('ul.Comments,.DiscussionTable')
199-
.effect("highlight", {}, "slow")
200-
.trigger('contentLoad');
201-
// $('ul.Comments li:last,.DiscussionTable li:last').effect("highlight", {}, "slow");
198+
var viewMode = json['ReplyTo.ViewMode'];
199+
if(viewMode === 'threaded') {
200+
item = $('ul.Comments');
201+
$('ul.Comments li').remove();
202+
$(item).append(json.Data)
203+
//.effect("highlight", {}, "slow")
204+
.trigger('contentLoad');
205+
} else {
206+
$(json.Data)
207+
.appendTo('ul.Comments,.DiscussionTable')
208+
//.effect("highlight", {}, "slow")
209+
.trigger('contentLoad');
210+
}
202211
}
203212
}
204213
// Remove any "More" pager links (because it is typically replaced with the latest comment by this function)
@@ -367,7 +376,7 @@ jQuery(document).ready(function($) {
367376
confirmHeading: gdn.definition('ConfirmDeleteCommentHeading', 'Delete Comment'),
368377
confirmText: gdn.definition('ConfirmDeleteCommentText', 'Are you sure you want to delete this comment?'),
369378
followConfirm: false,
370-
deliveryType: 'BOOL', // DELIVERY_TYPE_BOOL
379+
deliveryType: gdn.urlQueryParam( $('a.DeleteComment').attr('href'), 'deliveryType'), //'VIEW' - threaded, 'BOOL' - flat
371380
afterConfirm: function(json, sender) {
372381
var row = $(sender).parents('li.ItemComment');
373382
if (json.ErrorMessage) {
@@ -378,6 +387,15 @@ jQuery(document).ready(function($) {
378387
$(this).remove();
379388
});
380389
gdn.processTargets(json.Targets);
390+
391+
var viewMode = json['ReplyTo.ViewMode'];
392+
if(viewMode === 'threaded') {
393+
item = $('ul.Comments');
394+
$('ul.Comments li').remove();
395+
$(item).append(json.Data);
396+
//.effect("highlight", {}, "slow");
397+
}
398+
381399
// Let listeners know that the comment was deleted.
382400
$(document).trigger('CommentDeleted');
383401
}

vanilla/applications/vanilla/views/discussion/helper_functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function writeComment($comment, $sender, $session, $currentOffset) {
114114

115115
// FIX: https://github.com/topcoder-platform/forums/issues/488:
116116
// ViewMode should be set before displaying comment
117-
$viewMode = $sender->data('ViewMode');
117+
$viewMode = $sender->data('ReplyTo.ViewMode');
118118
?>
119119
<li class="<?php echo $cssClass; ?>" id="<?php echo 'Comment_'.$comment->CommentID; ?>">
120120
<div class="Comment">

vanilla/applications/vanilla/views/modules/discussionfilter.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,28 @@
4040
<ul role="nav" class="FilterMenu">
4141
<?php
4242
$Controller->fireEvent('BeforeDiscussionFilters');
43-
// if (c('Vanilla.Categories.ShowTabs')) {
4443
if (c('Vanilla.Categories.Use')) {
44+
$menuOptions = [];
45+
4546
$CssClass = 'AllCategories';
46-
if ((strtolower($Controller->ControllerName) == 'categoriescontroller' && in_array(strtolower($Controller->RequestMethod),['index', 'all']))
47-
|| strpos(strtolower($Controller->Request->path()) , 'categories') === 0) {
48-
$CssClass .= ' Active';
47+
$isActive = false;
48+
if($Controller instanceof CategoriesController || $Controller instanceof DiscussionController
49+
|| $Controller instanceof PostController) {
50+
$isActive = true;
51+
}
52+
53+
$menuOptions['AllCategories']['Url'] = anchor('Public Forums', '/categories');
54+
$menuOptions['AllCategories']['IsActive'] = $isActive;
55+
$menuOptions['AllCategories']['CssClass'] = $CssClass;
56+
57+
$Controller->EventArguments['Menu'] = &$menuOptions;
58+
$Controller->fireEvent('BeforeRenderDiscussionFilters');
59+
foreach($menuOptions as $key => $value) {
60+
if($menuOptions[$key]['IsActive'] === true) {
61+
$menuOptions[$key]['CssClass'] .= ' Active';
62+
}
63+
echo '<li class="' . $menuOptions[$key]['CssClass'] . '">' . $menuOptions[$key]['Url'] . '</li> ';
4964
}
50-
echo '<li class="'.$CssClass.'">'.anchor('Public Forums', '/categories').'</li> ';
5165
}
5266
/*
5367
<li id="RecentDiscussions" class="Discussions<?php echo strtolower($Controller->ControllerName) == 'discussionscontroller' && strtolower($Controller->RequestMethod) == 'index' && strpos(strtolower($Controller->Request->path()) , 'discussions') === 0? ' Active' : ''; ?>">

vanilla/js/global.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,14 @@ jQuery(document).ready(function($) {
740740
return urlFormat.replace("{Path}", path);
741741
};
742742

743+
// Get query param from url
744+
gdn.urlQueryParam = function (url, name) {
745+
var results = new RegExp('[\?&]' + name + '=([^&#]*)')
746+
.exec(url);
747+
748+
return (results !== null) ? results[1] || 0 : false;
749+
};
750+
743751
// Fill in placeholders.
744752
if (!gdn.elementSupports('input', 'placeholder')) {
745753
$('input:text,textarea').not('.NoIE').each(function() {

0 commit comments

Comments
 (0)