From 4f5d70d5b5e136a5c2f19dc7718eeef432319b70 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 25 Sep 2020 11:47:29 -0500 Subject: [PATCH] Rejoin websocket rooms on reconnect. Fixes #41 --- src/shared/components/community.tsx | 3 +++ src/shared/components/main.tsx | 1 + src/shared/components/navbar.tsx | 1 + src/shared/components/post.tsx | 4 +++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/shared/components/community.tsx b/src/shared/components/community.tsx index e994d0b..2fae830 100644 --- a/src/shared/components/community.tsx +++ b/src/shared/components/community.tsx @@ -417,6 +417,9 @@ export class Community extends Component { this.context.router.history.push('/'); return; } else if (msg.reconnect) { + WebSocketService.Instance.communityJoin({ + community_id: this.state.communityRes.community.id, + }); this.fetchData(); } else if (res.op == UserOperation.GetCommunity) { let data = res.data as GetCommunityResponse; diff --git a/src/shared/components/main.tsx b/src/shared/components/main.tsx index 7a5f814..3489761 100644 --- a/src/shared/components/main.tsx +++ b/src/shared/components/main.tsx @@ -720,6 +720,7 @@ export class Main extends Component { toast(i18n.t(msg.error), 'danger'); return; } else if (msg.reconnect) { + WebSocketService.Instance.communityJoin({ community_id: 0 }); this.fetchData(); } else if (res.op == UserOperation.GetFollowedCommunities) { let data = res.data as GetFollowedCommunitiesResponse; diff --git a/src/shared/components/navbar.tsx b/src/shared/components/navbar.tsx index 5a10b6a..877cdd8 100644 --- a/src/shared/components/navbar.tsx +++ b/src/shared/components/navbar.tsx @@ -392,6 +392,7 @@ export class Navbar extends Component { } return; } else if (msg.reconnect) { + WebSocketService.Instance.userJoin(); this.fetchUnreads(); } else if (res.op == UserOperation.GetReplies) { let data = res.data as GetRepliesResponse; diff --git a/src/shared/components/post.tsx b/src/shared/components/post.tsx index a7c9f79..2010858 100644 --- a/src/shared/components/post.tsx +++ b/src/shared/components/post.tsx @@ -436,8 +436,10 @@ export class Post extends Component { toast(i18n.t(msg.error), 'danger'); return; } else if (msg.reconnect) { + let postId = Number(this.props.match.params.id); + WebSocketService.Instance.postJoin({ post_id: postId }); WebSocketService.Instance.getPost({ - id: Number(this.props.match.params.id), + id: postId, }); } else if (res.op == UserOperation.GetPost) { let data = res.data as GetPostResponse; -- 2.44.1