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
This commit is contained in:
Yuriy Bakhtin 2025-04-08 19:12:30 +02:00 committed by GitHub
parent 6b04a6a83e
commit 9a21276770
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 3 deletions

View File

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

View File

@ -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;
}
}