From 9a21276770eda294f77a815f2c638e74a3c05b36 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Tue, 8 Apr 2025 19:12:30 +0200 Subject: [PATCH] Fix comments list when comment is active from another parent comment (#7487) * Fix comments list when comment is active from another parent comment * Update CHANGELOG.md --- CHANGELOG.md | 1 + .../modules/comment/widgets/Comments.php | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ec567c0b5..e7397c3f1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ HumHub Changelog 1.17.3 (Unreleased) ---------------------- - Fix #7484: Use password type on the installation DB config form +- Fix #7487: Fix comments list when comment is active from another parent comment 1.17.2 (April 7, 2025) ---------------------- diff --git a/protected/humhub/modules/comment/widgets/Comments.php b/protected/humhub/modules/comment/widgets/Comments.php index 6e94c792df..59d39bc143 100644 --- a/protected/humhub/modules/comment/widgets/Comments.php +++ b/protected/humhub/modules/comment/widgets/Comments.php @@ -65,9 +65,7 @@ class Comments extends Widget { $objectModel = PolymorphicRelation::getObjectModel($this->object); $objectId = $this->object->getPrimaryKey(); - - $streamQuery = Yii::$app->request->getQueryParam('StreamQuery'); - $currentCommentId = empty($streamQuery['commentId']) ? null : $streamQuery['commentId']; + $currentCommentId = $this->getCurrentCommentId(); // Count all Comments $commentCount = CommentModel::GetCommentCount($objectModel, $objectId); @@ -101,4 +99,27 @@ class Comments extends Widget { return $this->isFullViewMode() ? $this->module->commentsBlockLoadSizeViewMode : $this->module->commentsBlockLoadSize; } + + protected function getCurrentCommentId(): ?int + { + $streamQuery = Yii::$app->request->getQueryParam('StreamQuery'); + if (empty($streamQuery['commentId'])) { + return null; + } + + $currentCommentId = (int) $streamQuery['commentId']; + + $currentComment = Yii::$app->runtimeCache->getOrSet('getCurrentComment' . $currentCommentId, function () use ($currentCommentId) { + return CommentModel::findOne(['id' => $currentCommentId]); + }); + + if (!$currentComment || + $currentComment->object_id !== $this->object?->id || + $currentComment->object_model !== get_class($this->object)) { + // The current comment is from another parent object + return null; + } + + return $currentCommentId; + } }