Skip to content

Issues-490: Add reply link in comment/discussion options #73

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 2 commits into from
Mar 27, 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
89 changes: 42 additions & 47 deletions ReplyTo/class.replyto.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,39 +91,6 @@ public function base_InlineDiscussionOptionsLeft_handler($sender, $args){
echo '</span>';
}

public function base_inlineCommentOptionsRight_handler($sender, $args) {
ReplyToPlugin::log('base_inlineCommentOptionsRight_handler', []);

if (!Gdn::Session()->isValid()) {
return;
}

$discussion = $sender->data('Discussion');
$isClosed = ((int)$discussion->Closed) == 1;
if ($isClosed) {
return;
}

//Check permission
$CategoryID = val('PermissionCategoryID', $discussion) ? val('PermissionCategoryID', $discussion) : val('CategoryID', $discussion);

// Can the user comment on this category, and is the discussion open for comments?
if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) {
return;
}

$viewMode = self::getViewMode();
$comment = &$args['Comment'];
$items = & $args['Items'];
$commentID = val('CommentID', $comment);
if(empty($items)) {
$items = [];
}
array_push( $items, anchor(
t('Reply'),
url("/?ParentCommentID=".$commentID."&view=".$viewMode, false), 'ReplyComment'));
}

/**
* Set the tree order of all comments in the model as soon as it is instantiated.
* It is not clear if there are other plugins that may also wish to change the ordering.
Expand Down Expand Up @@ -225,26 +192,23 @@ public function base_commentOptions_handler($sender, $args) {
return;
}
$discussion = $sender->data('Discussion');
$isClosed = ((int)$discussion->Closed) == 1;
if ($isClosed) {
return;
}

//Check permission
if (isset($discussion->PermissionCategoryID)) {
$CategoryID = val('PermissionCategoryID', $discussion);
} else {
$CategoryID = $discussion->CategoryID;
}
$CategoryID = val('PermissionCategoryID', $discussion)? val('PermissionCategoryID', $discussion):val('CategoryID', $discussion);
$userCanClose = CategoryModel::checkPermission($CategoryID, 'Vanilla.Discussions.Close');
$userCanComment = CategoryModel::checkPermission($CategoryID, 'Vanilla.Comments.Add');

// Can the user comment on this category, and is the discussion open for comments?
if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) {
$canAddComment = ($discussion->Closed == '1' && $userCanClose) || ($discussion->Closed == '0' && $userCanComment);
if (!$canAddComment) {
return;
}
// Can the user comment on this category, and is the discussion open for comments?
// if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) {
// return;
// }

/*
$options = &$args['CommentOptions'];
$comment = &$args['Comment'];
$comment = $args['Comment'];
$options['ReplyToComment'] = [
'Label' => t('Reply'),
'Url' => '/?ParentCommentID='.$comment->CommentID,
Expand All @@ -264,7 +228,38 @@ public function base_commentOptions_handler($sender, $args) {
$options[$key]['Url'] = $currentUrl.'?view='.$viewMode;
}
}
*/
}

/**
* Add 'Reply' option to discussion.
*
* @param Gdn_Controller $sender
* @param array $args
*/
public function base_inlineDiscussionOptions_handler($sender, $args) {
$discussion = $args['Discussion'];
if (!$discussion) {
return;
}

if (!Gdn::session()->UserID) {
return;
}

//Check permission
$CategoryID = val('PermissionCategoryID', $discussion)? val('PermissionCategoryID', $discussion):val('CategoryID', $discussion);
$userCanClose = CategoryModel::checkPermission($CategoryID, 'Vanilla.Discussions.Close');
$userCanComment = CategoryModel::checkPermission($CategoryID, 'Vanilla.Comments.Add');

// See the 'writeCommentForm' method vanilla/applications/vanilla/views/discussion/helper_functions.php
$canAddComment = ($discussion->Closed == '1' && $userCanClose) || ($discussion->Closed == '0' && $userCanComment);
if (!$canAddComment) {
return;
}

// DropdownModule options
$options = & $args['DiscussionOptions'];
$options->addLink('Reply', url("/", true), 'reply', 'ReplyComment');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions ReplyTo/design/replyto.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

.ReplyViewOptions {
font-family: roboto, Segoe UI, Helvetica Neue, Helvetica, Raleway, Arial, sans-serif;
display: inline-block;
line-height: 1.5;
}
Expand All @@ -8,8 +9,7 @@
}

.MessageList .ItemDiscussion .Item-Body .Controls a.ReplyViewOptionLink.Active, .ReplyViewOptions .ReplyViewOptionLink.Active {
color: #696969;
font-weight: 800;
color: #555555;
}
/*
Indent comments according to their depth.
Expand Down