mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-23 07:38:07 -05:00
Use parent_id and commentee_id the right way when posting comments.
The parent_id is the top-level-parent, the commentee_id is the user to whom the comment is directed , the one that is mentioned in @ reply.
This commit is contained in:
parent
a6409bbcce
commit
c289ce72d1
3 changed files with 17 additions and 11 deletions
|
@ -93,6 +93,7 @@ class Comment extends React.Component {
|
|||
content,
|
||||
datetimeCreated,
|
||||
id,
|
||||
parentId,
|
||||
projectId,
|
||||
replyUsername,
|
||||
visibility
|
||||
|
@ -192,7 +193,8 @@ class Comment extends React.Component {
|
|||
{this.state.replying ? (
|
||||
<FlexRow className="comment-reply-row">
|
||||
<ComposeComment
|
||||
parentId={id}
|
||||
commenteeId={author.id}
|
||||
parentId={parentId || id}
|
||||
projectId={projectId}
|
||||
onAddComment={this.handlePostReply}
|
||||
onCancel={this.handleToggleReplying}
|
||||
|
@ -241,6 +243,7 @@ Comment.propTypes = {
|
|||
onDelete: PropTypes.func,
|
||||
onReport: PropTypes.func,
|
||||
onRestore: PropTypes.func,
|
||||
parentId: PropTypes.number,
|
||||
projectId: PropTypes.string,
|
||||
replyUsername: PropTypes.string,
|
||||
visibility: PropTypes.string
|
||||
|
|
|
@ -58,7 +58,7 @@ class ComposeComment extends React.Component {
|
|||
json: {
|
||||
content: this.state.message,
|
||||
parent_id: this.props.parentId || '',
|
||||
comentee_id: this.props.comenteeId || ''
|
||||
commentee_id: this.props.commenteeId || ''
|
||||
}
|
||||
}, (err, body, res) => {
|
||||
if (err || res.statusCode !== 200) {
|
||||
|
@ -158,7 +158,7 @@ class ComposeComment extends React.Component {
|
|||
}
|
||||
|
||||
ComposeComment.propTypes = {
|
||||
comenteeId: PropTypes.number,
|
||||
commenteeId: PropTypes.number,
|
||||
onAddComment: PropTypes.func,
|
||||
onCancel: PropTypes.func,
|
||||
parentId: PropTypes.number,
|
||||
|
|
|
@ -23,8 +23,8 @@ class TopLevelComment extends React.Component {
|
|||
expanded: false
|
||||
};
|
||||
|
||||
// A cache of {commentId: username, ...} in order to show reply usernames
|
||||
this.commentUsernameCache = {};
|
||||
// A cache of {userId: username, ...} in order to show reply usernames
|
||||
this.authorUsernameCache = {};
|
||||
}
|
||||
|
||||
handleExpandThread () {
|
||||
|
@ -53,17 +53,19 @@ class TopLevelComment extends React.Component {
|
|||
this.props.onAddComment(comment, this.props.id);
|
||||
}
|
||||
|
||||
commentUsername (parentId) {
|
||||
if (this.commentUsernameCache[parentId]) return this.commentUsernameCache[parentId];
|
||||
authorUsername (authorId) {
|
||||
if (this.authorUsernameCache[authorId]) return this.authorUsernameCache[authorId];
|
||||
|
||||
// If the cache misses, rebuild it. Every reply has a parent id that is
|
||||
// either a reply to this top level comment or to one of the replies.
|
||||
this.commentUsernameCache[this.props.id] = this.props.author.username;
|
||||
this.authorUsernameCache[this.props.author.id] = this.props.author.username;
|
||||
const replies = this.props.replies;
|
||||
for (let i = 0; i < replies.length; i++) {
|
||||
this.commentUsernameCache[replies[i].id] = replies[i].author.username;
|
||||
this.authorUsernameCache[replies[i].author.id] = replies[i].author.username;
|
||||
}
|
||||
return this.commentUsernameCache[parentId];
|
||||
// Default to top level author if no author is found from authorId
|
||||
// This can happen if there is no commentee_id stored with the comment
|
||||
return this.authorUsernameCache[authorId] || this.props.author.username;
|
||||
}
|
||||
|
||||
render () {
|
||||
|
@ -126,8 +128,9 @@ class TopLevelComment extends React.Component {
|
|||
datetimeCreated={reply.datetime_created}
|
||||
id={reply.id}
|
||||
key={reply.id}
|
||||
parentId={id}
|
||||
projectId={projectId}
|
||||
replyUsername={this.commentUsername(reply.parent_id)}
|
||||
replyUsername={this.authorUsername(reply.commentee_id)}
|
||||
visibility={reply.visibility}
|
||||
onAddComment={this.handleAddComment}
|
||||
onDelete={this.handleDeleteReply}
|
||||
|
|
Loading…
Reference in a new issue