Skip to content

Issues-533: Added Posts Count/Comments Count, Issues-535 #603

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 3 commits into from
Apr 26, 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
20 changes: 18 additions & 2 deletions config/vanilla/bootstrap.before.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function dateUpdated($row, $wrap = null) {

if ($dateUpdated) {
$updateUser = Gdn::userModel()->getID($updateUserID);
$dateUpdatedFormatted = Gdn::getContainer()->get(DateTimeFormatter::class)->formatDate($dateUpdated, false, DateTimeFormatter::FORCE_FULL_FORMAT);
$dateUpdatedFormatted = formatDateCustom($dateUpdated, false);
if ($updateUser && $insertUserID != $updateUserID) {
$title = sprintf(t('Edited %s by %s.'), $dateUpdatedFormatted, val('Name', $updateUser));
$link = userAnchor($updateUser);
Expand Down Expand Up @@ -987,4 +987,20 @@ function discussionUrl($discussion, $page = '', $withDomain = true) {

return url($result, $withDomain);
}
}
}

if (!function_exists('formatDateCustom')) {
function formatDateCustom($timestamp, $showDayOfWeek=true) {
$dateFormat = $showDayOfWeek? '%a, %b %e, %Y': '%b %e, %Y';
$dateFormatted = Gdn::getContainer()->get(DateTimeFormatter::class)->formatDate($timestamp, false, $dateFormat);
$timeFormatted = Gdn::getContainer()->get(DateTimeFormatter::class)->formatDate($timestamp, false, '%I:%M %p');
return sprintf('%1$s at %2$s', $dateFormatted, $timeFormatted);
}
}
if (!function_exists('authorProfileStats')) {
function authorProfileStats($user) {
$countDiscussions = plural( $user->CountDiscussions, '%s Post', '%s Posts');
$countComments = plural( $user->CountComments, '%s Comment', '%s Comments');
return '<span class="MItem AuthorProfileStats AuthorProfileStats_'.$user->UserID.'">'.sprintf('%1s %2s', $countDiscussions,$countComments).'</span>';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,11 @@ public function delete($discussionID, $target = '') {
}

$this->jsonTarget(".Section-DiscussionList #Discussion_$discussionID", null, 'SlideUp');
// FIX: https://github.com/topcoder-platform/forums/issues/533
$insertUserID = val('InsertUserID',$discussion);
$author = Gdn::userModel()->getID($insertUserID, DATASET_TYPE_OBJECT);
$this->jsonTarget(".AuthorProfileStats_{$insertUserID}", authorProfileStats($author), 'ReplaceWith');

}
}

Expand All @@ -820,10 +825,11 @@ public function deleteComment($commentID = '', $transientKey = '') {
$defaultTarget = '/discussions/';
$validCommentID = is_numeric($commentID) && $commentID > 0;
$validUser = $session->UserID > 0 && $session->validateTransientKey($transientKey);

$insertUserID = false;
if ($validCommentID && $validUser) {
// Get comment and discussion data
$comment = $this->CommentModel->getID($commentID);
$insertUserID = $comment->InsertUserID;
$discussionID = val('DiscussionID', $comment);
$discussion = $this->DiscussionModel->getID($discussionID);

Expand Down Expand Up @@ -868,6 +874,9 @@ public function deleteComment($commentID = '', $transientKey = '') {
$this->setJson('ErrorMessage', $this->Form->errors());
} else {
$this->jsonTarget("#Comment_$commentID", '', 'SlideUp');
// FIX: https://github.com/topcoder-platform/forums/issues/533
$author = Gdn::userModel()->getID($insertUserID, DATASET_TYPE_OBJECT);
$this->jsonTarget(".AuthorProfileStats_{$insertUserID}", authorProfileStats($author), 'ReplaceWith');
}

$this->render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,13 @@ public function comment($DiscussionID = '') {
$this->ClassName = 'DiscussionController';
$this->ControllerName = 'discussion';
$this->View = 'comments';

// FIX: https://github.com/topcoder-platform/forums/issues/533
$comment = $this->CommentModel->getID($CommentID);
$insertUserID = val('InsertUserID',$comment);
$author = Gdn::userModel()->getID($insertUserID, DATASET_TYPE_OBJECT);
$this->jsonTarget(".AuthorProfileStats_{$insertUserID}", authorProfileStats($author), 'ReplaceWith');

// }

// Make sure to set the user's discussion watch records
Expand Down
35 changes: 35 additions & 0 deletions vanilla/applications/vanilla/js/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,41 @@ jQuery(document).ready(function($) {

// Handler before submitting
$(frm).triggerHandler('BeforeDiscussionSubmit', [frm, btn]);
var maxCommentLength = $(frm).find('input:hidden[name$=MaxCommentLength]');
var defaultValues = [
undefined,
null,
'',
'[{\"insert\":\"\\n\"}]'
];

var editorContainer = $(frm).find('.EasyMDEContainer');
var messageContainer = $(frm).find('.editor-statusbar .message');
var textbox = $(frm).find('textarea#Form_Body');
var currentVal = $(textbox).val();
currentVal = gdn.normalizeText(currentVal);
if(defaultValues.includes(currentVal) || currentVal.trim().length == 0) {
$(editorContainer).addClass('error');
$(messageContainer).text('Cannot post an empty message');
$(frm).find(':submit').attr('disabled', 'disabled');
$(frm).find('.Buttons a.Button:not(.Cancel)').addClass('Disabled');
return false;
}

if(currentVal.length > maxCommentLength.val()) {
$(editorContainer).addClass('error');
var count = currentVal.length - maxCommentLength.val();
$(messageContainer).text('Discussion is '+ count +' characters too long');
$(frm).find(':submit').attr('disabled', 'disabled');
$(frm).find('.Buttons a.Button:not(.Cancel)').addClass('Disabled');
return false;
}

$(editorContainer).removeClass('error');
$(messageContainer).text('');
$(frm).find(':submit').removeAttr("disabled");
$(frm).find('.Buttons a.Button').removeClass('Disabled');


var inpDiscussionID = $(frm).find(':hidden[name$=DiscussionID]');
var inpDraftID = $(frm).find(':hidden[name$=DraftID]');
Expand Down
7 changes: 6 additions & 1 deletion vanilla/applications/vanilla/models/class.commentmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,10 @@ public function save($formPostValues, $settings = false) {
$commentID = $this->SQL->insert($this->Name, $fields);
}
if ($commentID) {
// FIX: https://github.com/topcoder-platform/forums/issues/533
// if this comment is added by the discussion author.
$this->updateUser($fields['InsertUserID'], false);

$bodyValue = $fields["Body"] ?? null;
if ($bodyValue) {
$this->calculateMediaAttachments($commentID, !$insert);
Expand Down Expand Up @@ -1356,7 +1360,8 @@ public function save2($CommentID, $Insert, $CheckExisting = true, $IncUser = fal
// the number of discussions created by the user that s/he has
// unread messages in) if this comment was not added by the
// discussion author.
$this->updateUser($Fields['InsertUserID'], $IncUser && $Insert);
// Move it to save() due to https://github.com/topcoder-platform/forums/issues/533
// $this->updateUser($Fields['InsertUserID'], $IncUser && $Insert);

// Mark the user as participated.
$this->SQL->replace(
Expand Down
10 changes: 6 additions & 4 deletions vanilla/applications/vanilla/views/discussion/discussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@
</span>
</div>
<div class="Meta DiscussionMeta">
<span class="MItem DateCreated">
<?php echo Gdn::getContainer()->get(DateTimeFormatter::class)->formatDate($Discussion->DateInserted, true,
DateTimeFormatter::FORCE_FULL_FORMAT); ?>
</span>
<?php echo authorProfileStats($Author);?>
<span class="MItem DateCreated">
<?php
echo formatDateCustom($Discussion->DateInserted);
?>
</span>
<?php
echo dateUpdated($Discussion, ['<span class="MItem">', '</span>']);
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ function writeComment($comment, $sender, $session, $currentOffset) {
</span>
</div>
<div class="Meta CommentMeta CommentInfo">
<?php echo authorProfileStats($author);?>
<span class="MItem DateCreated">
<?php echo Gdn::getContainer()->get(DateTimeFormatter::class)->formatDate($comment->DateInserted, true,
DateTimeFormatter::FORCE_FULL_FORMAT); ?>
<?php echo formatDateCustom($comment->DateInserted); ?>
</span>
<?php
echo dateUpdated($comment, ['<span class="MItem">', '</span>']);
Expand Down