Skip to content

Commit

Permalink
Merge pull request #1681 from FreeFeed/6to5
Browse files Browse the repository at this point in the history
Fix extra comment opening in "show last N"
  • Loading branch information
davidmz authored May 21, 2024
2 parents 27abb86 + ffe24a5 commit d2b0f42
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.132.0] - Not released
### Fixed
- Fixed a bug where the first partial opening of comments ("show last N") would
open one extra comment.

## [1.131.3] - 2024-05-08
### Fixed
Expand Down
18 changes: 14 additions & 4 deletions src/components/post/post-comments/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export default class PostComments extends Component {
commentsAfterFold: foldConf.afterFold,
minFoldedComments: foldConf.minFolded,
minToCollapse: foldConf.minToCollapse,
minToSteppedFold: foldConf.minToSteppedFold,
foldStep: foldConf.foldStep,
preopened: false,
};

Expand Down Expand Up @@ -310,13 +308,25 @@ export default class PostComments extends Component {
};

expandComments = (count = 0) => {
const { post, commentsAfterFold, showMoreComments, comments } = this.props;
if (count > 0) {
if (post.omittedComments > 0) {
// Correction for the case when the server is configured to return less
// than 'commentsAfterFold' after a fold. We should correct the number
// of comments to be opened, otherwise more comments will be opened than
// necessary.
//
// The "comments.length - post.omittedCommentsOffset" is the server's
// number of comments after the fold. The "commentsAfterFold" is the
// client's desired number of comments after the fold.
count += comments.length - post.omittedCommentsOffset - commentsAfterFold;
}
this.setState({ folded: true, addedToTail: this.state.addedToTail + count });
} else {
this.setState({ folded: false, addedToTail: 0 });
}
if (this.props.post.omittedComments > 0) {
this.props.showMoreComments(this.props.post.id);
if (post.omittedComments > 0) {
showMoreComments(this.props.post.id);
}
};

Expand Down

0 comments on commit d2b0f42

Please sign in to comment.