Skip to content

Commit 898277d

Browse files
committed
Issues-511: Replay placement
1 parent f8664f0 commit 898277d

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

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/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)