Merge branch 'websocket_reconnect_reload' into dev
This commit is contained in:
commit
dcad63fe2a
9 changed files with 27 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
ansible/inventory
|
ansible/inventory
|
||||||
|
ansible/inventory_dev
|
||||||
ansible/passwords/
|
ansible/passwords/
|
||||||
docker/lemmy_mine.hjson
|
docker/lemmy_mine.hjson
|
||||||
docker/dev/env_deploy.sh
|
docker/dev/env_deploy.sh
|
||||||
|
|
2
ui/src/components/community.tsx
vendored
2
ui/src/components/community.tsx
vendored
|
@ -254,6 +254,8 @@ export class Community extends Component<any, State> {
|
||||||
toast(i18n.t(msg.error), 'danger');
|
toast(i18n.t(msg.error), 'danger');
|
||||||
this.context.router.history.push('/');
|
this.context.router.history.push('/');
|
||||||
return;
|
return;
|
||||||
|
} else if (msg.reconnect) {
|
||||||
|
this.fetchPosts();
|
||||||
} else if (res.op == UserOperation.GetCommunity) {
|
} else if (res.op == UserOperation.GetCommunity) {
|
||||||
let data = res.data as GetCommunityResponse;
|
let data = res.data as GetCommunityResponse;
|
||||||
this.state.community = data.community;
|
this.state.community = data.community;
|
||||||
|
|
2
ui/src/components/inbox.tsx
vendored
2
ui/src/components/inbox.tsx
vendored
|
@ -313,6 +313,8 @@ export class Inbox extends Component<any, InboxState> {
|
||||||
if (msg.error) {
|
if (msg.error) {
|
||||||
toast(i18n.t(msg.error), 'danger');
|
toast(i18n.t(msg.error), 'danger');
|
||||||
return;
|
return;
|
||||||
|
} else if (msg.reconnect) {
|
||||||
|
this.refetch();
|
||||||
} else if (res.op == UserOperation.GetReplies) {
|
} else if (res.op == UserOperation.GetReplies) {
|
||||||
let data = res.data as GetRepliesResponse;
|
let data = res.data as GetRepliesResponse;
|
||||||
this.state.replies = data.replies;
|
this.state.replies = data.replies;
|
||||||
|
|
2
ui/src/components/main.tsx
vendored
2
ui/src/components/main.tsx
vendored
|
@ -537,6 +537,8 @@ export class Main extends Component<any, MainState> {
|
||||||
if (msg.error) {
|
if (msg.error) {
|
||||||
toast(i18n.t(msg.error), 'danger');
|
toast(i18n.t(msg.error), 'danger');
|
||||||
return;
|
return;
|
||||||
|
} else if (msg.reconnect) {
|
||||||
|
this.fetchPosts();
|
||||||
} else if (res.op == UserOperation.GetFollowedCommunities) {
|
} else if (res.op == UserOperation.GetFollowedCommunities) {
|
||||||
let data = res.data as GetFollowedCommunitiesResponse;
|
let data = res.data as GetFollowedCommunitiesResponse;
|
||||||
this.state.subscribedCommunities = data.communities;
|
this.state.subscribedCommunities = data.communities;
|
||||||
|
|
2
ui/src/components/navbar.tsx
vendored
2
ui/src/components/navbar.tsx
vendored
|
@ -208,6 +208,8 @@ export class Navbar extends Component<any, NavbarState> {
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
} else if (msg.reconnect) {
|
||||||
|
this.fetchUnreads();
|
||||||
} else if (res.op == UserOperation.GetReplies) {
|
} else if (res.op == UserOperation.GetReplies) {
|
||||||
let data = res.data as GetRepliesResponse;
|
let data = res.data as GetRepliesResponse;
|
||||||
let unreadReplies = data.replies.filter(r => !r.read);
|
let unreadReplies = data.replies.filter(r => !r.read);
|
||||||
|
|
4
ui/src/components/post.tsx
vendored
4
ui/src/components/post.tsx
vendored
|
@ -370,6 +370,10 @@ export class Post extends Component<any, PostState> {
|
||||||
if (msg.error) {
|
if (msg.error) {
|
||||||
toast(i18n.t(msg.error), 'danger');
|
toast(i18n.t(msg.error), 'danger');
|
||||||
return;
|
return;
|
||||||
|
} else if (msg.reconnect) {
|
||||||
|
WebSocketService.Instance.getPost({
|
||||||
|
id: Number(this.props.match.params.id),
|
||||||
|
});
|
||||||
} else if (res.op == UserOperation.GetPost) {
|
} else if (res.op == UserOperation.GetPost) {
|
||||||
let data = res.data as GetPostResponse;
|
let data = res.data as GetPostResponse;
|
||||||
this.state.post = data.post;
|
this.state.post = data.post;
|
||||||
|
|
2
ui/src/components/user.tsx
vendored
2
ui/src/components/user.tsx
vendored
|
@ -998,6 +998,8 @@ export class User extends Component<any, UserState> {
|
||||||
}
|
}
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
return;
|
return;
|
||||||
|
} else if (msg.reconnect) {
|
||||||
|
this.refetch();
|
||||||
} else if (res.op == UserOperation.GetUserDetails) {
|
} else if (res.op == UserOperation.GetUserDetails) {
|
||||||
let data = res.data as UserDetailsResponse;
|
let data = res.data as UserDetailsResponse;
|
||||||
this.state.user = data.user;
|
this.state.user = data.user;
|
||||||
|
|
1
ui/src/interfaces.ts
vendored
1
ui/src/interfaces.ts
vendored
|
@ -854,4 +854,5 @@ export interface WebSocketJsonResponse {
|
||||||
op?: string;
|
op?: string;
|
||||||
data?: ResponseType;
|
data?: ResponseType;
|
||||||
error?: string;
|
error?: string;
|
||||||
|
reconnect?: boolean;
|
||||||
}
|
}
|
||||||
|
|
13
ui/src/services/WebSocketService.ts
vendored
13
ui/src/services/WebSocketService.ts
vendored
|
@ -40,6 +40,7 @@ import {
|
||||||
GetPrivateMessagesForm,
|
GetPrivateMessagesForm,
|
||||||
UserJoinForm,
|
UserJoinForm,
|
||||||
MessageType,
|
MessageType,
|
||||||
|
WebSocketJsonResponse,
|
||||||
} from '../interfaces';
|
} from '../interfaces';
|
||||||
import { UserService } from './';
|
import { UserService } from './';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
|
@ -59,16 +60,20 @@ export class WebSocketService {
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
this.ws = new ReconnectingWebSocket(wsUri);
|
this.ws = new ReconnectingWebSocket(wsUri);
|
||||||
|
|
||||||
|
this.subject = Observable.create((obs: any) => {
|
||||||
|
this.ws.onmessage = e => {
|
||||||
|
obs.next(JSON.parse(e.data));
|
||||||
|
};
|
||||||
this.ws.onopen = () => {
|
this.ws.onopen = () => {
|
||||||
console.log(`Connected to ${wsUri}`);
|
console.log(`Connected to ${wsUri}`);
|
||||||
if (UserService.Instance.user) {
|
if (UserService.Instance.user) {
|
||||||
this.userJoin();
|
this.userJoin();
|
||||||
}
|
}
|
||||||
|
let res: WebSocketJsonResponse = {
|
||||||
|
reconnect: true,
|
||||||
};
|
};
|
||||||
|
obs.next(res);
|
||||||
this.subject = Observable.create((obs: any) => {
|
|
||||||
this.ws.onmessage = e => {
|
|
||||||
obs.next(JSON.parse(e.data));
|
|
||||||
};
|
};
|
||||||
}).pipe(share());
|
}).pipe(share());
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue