);
}
- all() {
- let combined: Array<ReplyType> = [];
-
- combined.push(...this.state.replies);
- combined.push(...this.state.mentions);
- combined.push(...this.state.messages);
-
- // Sort it
- combined.sort((a, b) => b.published.localeCompare(a.published));
+ combined(): Array<ReplyType> {
+ return [
+ ...this.state.replies,
+ ...this.state.mentions,
+ ...this.state.messages,
+ ].sort((a, b) => b.published.localeCompare(a.published));
+ }
+ all() {
return (
<div>
- {combined.map(i =>
+ {this.combined().map(i =>
isCommentType(i) ? (
<CommentNodes
+ key={i.id}
nodes={[{ comment: i }]}
noIndent
markable
enableDownvotes={this.state.site.enable_downvotes}
/>
) : (
- <PrivateMessage privateMessage={i} />
+ <PrivateMessage key={i.id} privateMessage={i} />
)
)}
</div>
<div>
{this.state.mentions.map(mention => (
<CommentNodes
+ key={mention.id}
nodes={[{ comment: mention }]}
noIndent
markable
return (
<div>
{this.state.messages.map(message => (
- <PrivateMessage privateMessage={message} />
+ <PrivateMessage key={message.id} privateMessage={message} />
))}
</div>
);
} else if (data.comment.creator_id == UserService.Instance.user.id) {
toast(i18n.t('reply_sent'));
}
- this.setState(this.state);
} else if (res.op == UserOperation.CreatePrivateMessage) {
let data = res.data as PrivateMessageResponse;
if (data.message.recipient_id == UserService.Instance.user.id) {
this.state.replies.filter(r => !r.read).length +
this.state.mentions.filter(r => !r.read).length +
this.state.messages.filter(
- r => !r.read && r.creator_id !== UserService.Instance.user.id
+ r =>
+ UserService.Instance.user &&
+ !r.read &&
+ r.creator_id !== UserService.Instance.user.id
).length
);
}
}
get mine(): boolean {
- return UserService.Instance.user.id == this.props.privateMessage.creator_id;
+ return (
+ UserService.Instance.user &&
+ UserService.Instance.user.id == this.props.privateMessage.creator_id
+ );
}
render() {
<PrivateMessageForm
privateMessage={message}
onEdit={this.handlePrivateMessageEdit}
+ onCreate={this.handlePrivateMessageCreate}
onCancel={this.handleReplyCancel}
/>
)}
this.setState(this.state);
}
- handlePrivateMessageCreate() {
- this.state.showReply = false;
- this.setState(this.state);
- toast(i18n.t('message_sent'));
+ handlePrivateMessageCreate(message: PrivateMessageI) {
+ if (
+ UserService.Instance.user &&
+ message.creator_id == UserService.Instance.user.id
+ ) {
+ this.state.showReply = false;
+ this.setState(this.state);
+ toast(i18n.t('message_sent'));
+ }
}
}