diff --git a/config/vanilla/bootstrap.before.php b/config/vanilla/bootstrap.before.php index 3f617fe..b208501 100644 --- a/config/vanilla/bootstrap.before.php +++ b/config/vanilla/bootstrap.before.php @@ -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); @@ -987,4 +987,20 @@ function discussionUrl($discussion, $page = '', $withDomain = true) { return url($result, $withDomain); } -} \ No newline at end of file +} + +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 ''.sprintf('%1s %2s', $countDiscussions,$countComments).''; + } +} diff --git a/vanilla/applications/vanilla/controllers/class.discussioncontroller.php b/vanilla/applications/vanilla/controllers/class.discussioncontroller.php index 971882b..faaedcb 100644 --- a/vanilla/applications/vanilla/controllers/class.discussioncontroller.php +++ b/vanilla/applications/vanilla/controllers/class.discussioncontroller.php @@ -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'); + } } @@ -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); @@ -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(); diff --git a/vanilla/applications/vanilla/controllers/class.postcontroller.php b/vanilla/applications/vanilla/controllers/class.postcontroller.php index ab91deb..b7983a7 100644 --- a/vanilla/applications/vanilla/controllers/class.postcontroller.php +++ b/vanilla/applications/vanilla/controllers/class.postcontroller.php @@ -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 diff --git a/vanilla/applications/vanilla/js/post.js b/vanilla/applications/vanilla/js/post.js index 7777991..fa271f8 100644 --- a/vanilla/applications/vanilla/js/post.js +++ b/vanilla/applications/vanilla/js/post.js @@ -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]'); diff --git a/vanilla/applications/vanilla/models/class.commentmodel.php b/vanilla/applications/vanilla/models/class.commentmodel.php index 8b1fdbf..ad052f0 100644 --- a/vanilla/applications/vanilla/models/class.commentmodel.php +++ b/vanilla/applications/vanilla/models/class.commentmodel.php @@ -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); @@ -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( diff --git a/vanilla/applications/vanilla/views/discussion/discussion.php b/vanilla/applications/vanilla/views/discussion/discussion.php index 9ece006..e06366c 100644 --- a/vanilla/applications/vanilla/views/discussion/discussion.php +++ b/vanilla/applications/vanilla/views/discussion/discussion.php @@ -52,10 +52,12 @@
- - get(DateTimeFormatter::class)->formatDate($Discussion->DateInserted, true, - DateTimeFormatter::FORCE_FULL_FORMAT); ?> - + + + DateInserted); + ?> + ', '']); ?> diff --git a/vanilla/applications/vanilla/views/discussion/helper_functions.php b/vanilla/applications/vanilla/views/discussion/helper_functions.php index 05e19e8..7b622a7 100644 --- a/vanilla/applications/vanilla/views/discussion/helper_functions.php +++ b/vanilla/applications/vanilla/views/discussion/helper_functions.php @@ -176,9 +176,9 @@ function writeComment($comment, $sender, $session, $currentOffset) {
+ - get(DateTimeFormatter::class)->formatDate($comment->DateInserted, true, - DateTimeFormatter::FORCE_FULL_FORMAT); ?> + DateInserted); ?> ', '']);