mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-23 15:47:53 -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,
|
content,
|
||||||
datetimeCreated,
|
datetimeCreated,
|
||||||
id,
|
id,
|
||||||
|
parentId,
|
||||||
projectId,
|
projectId,
|
||||||
replyUsername,
|
replyUsername,
|
||||||
visibility
|
visibility
|
||||||
|
@ -192,7 +193,8 @@ class Comment extends React.Component {
|
||||||
{this.state.replying ? (
|
{this.state.replying ? (
|
||||||
<FlexRow className="comment-reply-row">
|
<FlexRow className="comment-reply-row">
|
||||||
<ComposeComment
|
<ComposeComment
|
||||||
parentId={id}
|
commenteeId={author.id}
|
||||||
|
parentId={parentId || id}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
onAddComment={this.handlePostReply}
|
onAddComment={this.handlePostReply}
|
||||||
onCancel={this.handleToggleReplying}
|
onCancel={this.handleToggleReplying}
|
||||||
|
@ -241,6 +243,7 @@ Comment.propTypes = {
|
||||||
onDelete: PropTypes.func,
|
onDelete: PropTypes.func,
|
||||||
onReport: PropTypes.func,
|
onReport: PropTypes.func,
|
||||||
onRestore: PropTypes.func,
|
onRestore: PropTypes.func,
|
||||||
|
parentId: PropTypes.number,
|
||||||
projectId: PropTypes.string,
|
projectId: PropTypes.string,
|
||||||
replyUsername: PropTypes.string,
|
replyUsername: PropTypes.string,
|
||||||
visibility: PropTypes.string
|
visibility: PropTypes.string
|
||||||
|
|
|
@ -58,7 +58,7 @@ class ComposeComment extends React.Component {
|
||||||
json: {
|
json: {
|
||||||
content: this.state.message,
|
content: this.state.message,
|
||||||
parent_id: this.props.parentId || '',
|
parent_id: this.props.parentId || '',
|
||||||
comentee_id: this.props.comenteeId || ''
|
commentee_id: this.props.commenteeId || ''
|
||||||
}
|
}
|
||||||
}, (err, body, res) => {
|
}, (err, body, res) => {
|
||||||
if (err || res.statusCode !== 200) {
|
if (err || res.statusCode !== 200) {
|
||||||
|
@ -158,7 +158,7 @@ class ComposeComment extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
ComposeComment.propTypes = {
|
ComposeComment.propTypes = {
|
||||||
comenteeId: PropTypes.number,
|
commenteeId: PropTypes.number,
|
||||||
onAddComment: PropTypes.func,
|
onAddComment: PropTypes.func,
|
||||||
onCancel: PropTypes.func,
|
onCancel: PropTypes.func,
|
||||||
parentId: PropTypes.number,
|
parentId: PropTypes.number,
|
||||||
|
|
|
@ -23,8 +23,8 @@ class TopLevelComment extends React.Component {
|
||||||
expanded: false
|
expanded: false
|
||||||
};
|
};
|
||||||
|
|
||||||
// A cache of {commentId: username, ...} in order to show reply usernames
|
// A cache of {userId: username, ...} in order to show reply usernames
|
||||||
this.commentUsernameCache = {};
|
this.authorUsernameCache = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
handleExpandThread () {
|
handleExpandThread () {
|
||||||
|
@ -53,17 +53,19 @@ class TopLevelComment extends React.Component {
|
||||||
this.props.onAddComment(comment, this.props.id);
|
this.props.onAddComment(comment, this.props.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
commentUsername (parentId) {
|
authorUsername (authorId) {
|
||||||
if (this.commentUsernameCache[parentId]) return this.commentUsernameCache[parentId];
|
if (this.authorUsernameCache[authorId]) return this.authorUsernameCache[authorId];
|
||||||
|
|
||||||
// If the cache misses, rebuild it. Every reply has a parent id that is
|
// 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.
|
// 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;
|
const replies = this.props.replies;
|
||||||
for (let i = 0; i < replies.length; i++) {
|
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 () {
|
render () {
|
||||||
|
@ -126,8 +128,9 @@ class TopLevelComment extends React.Component {
|
||||||
datetimeCreated={reply.datetime_created}
|
datetimeCreated={reply.datetime_created}
|
||||||
id={reply.id}
|
id={reply.id}
|
||||||
key={reply.id}
|
key={reply.id}
|
||||||
|
parentId={id}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
replyUsername={this.commentUsername(reply.parent_id)}
|
replyUsername={this.authorUsername(reply.commentee_id)}
|
||||||
visibility={reply.visibility}
|
visibility={reply.visibility}
|
||||||
onAddComment={this.handleAddComment}
|
onAddComment={this.handleAddComment}
|
||||||
onDelete={this.handleDeleteReply}
|
onDelete={this.handleDeleteReply}
|
||||||
|
|
Loading…
Reference in a new issue