diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx index eff7efcf1..ecc9223c3 100644 --- a/ui/src/components/inbox.tsx +++ b/ui/src/components/inbox.tsx @@ -275,21 +275,21 @@ export class Inbox extends Component { ); } - all() { - let combined: Array = []; - - 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 { + return [ + ...this.state.replies, + ...this.state.mentions, + ...this.state.messages, + ].sort((a, b) => b.published.localeCompare(a.published)); + } + all() { return (
- {combined.map(i => + {this.combined().map(i => isCommentType(i) ? ( { enableDownvotes={this.state.site.enable_downvotes} /> ) : ( - + ) )}
@@ -325,6 +325,7 @@ export class Inbox extends Component {
{this.state.mentions.map(mention => ( { return (
{this.state.messages.map(message => ( - + ))}
); @@ -565,7 +566,6 @@ export class Inbox extends Component { } 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) { @@ -597,7 +597,10 @@ export class Inbox extends Component { 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 ); } diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx index 6418bb222..1eb173193 100644 --- a/ui/src/components/navbar.tsx +++ b/ui/src/components/navbar.tsx @@ -431,6 +431,7 @@ export class Navbar extends Component { // The login if (data.my_user) { UserService.Instance.user = data.my_user; + WebSocketService.Instance.userJoin(); // On the first load, check the unreads if (this.state.isLoggedIn == false) { this.requestNotificationPermission(); diff --git a/ui/src/components/private-message.tsx b/ui/src/components/private-message.tsx index c3e0c2c25..4fa30a818 100644 --- a/ui/src/components/private-message.tsx +++ b/ui/src/components/private-message.tsx @@ -45,7 +45,10 @@ export class PrivateMessage extends Component< } 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() { @@ -113,6 +116,7 @@ export class PrivateMessage extends Component< )} @@ -280,9 +284,14 @@ export class PrivateMessage extends Component< 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')); + } } } diff --git a/ui/src/components/search.tsx b/ui/src/components/search.tsx index 11429fb2e..2162edeba 100644 --- a/ui/src/components/search.tsx +++ b/ui/src/components/search.tsx @@ -289,6 +289,7 @@ export class Search extends Component {
{i.type_ == 'posts' && ( { )} {i.type_ == 'comments' && ( {
{i.type === 'posts' ? ( { /> ) : ( { console.log(`Connected to ${wsUri}`); - if (UserService.Instance.user) { - this.userJoin(); - } - if (!firstConnect) { let res: WebSocketJsonResponse = { reconnect: true,