Adding support for join messages. Fixes #8

This commit is contained in:
Dessalines 2020-09-13 10:37:23 -05:00
parent 2295bd4d88
commit fd43a890a7
6 changed files with 24 additions and 6 deletions

View file

@ -72,7 +72,7 @@
"eslint": "^7.8.1", "eslint": "^7.8.1",
"eslint-plugin-jane": "^9.0.0", "eslint-plugin-jane": "^9.0.0",
"husky": "^4.3.0", "husky": "^4.3.0",
"lemmy-js-client": "^1.0.11", "lemmy-js-client": "^1.0.13",
"lint-staged": "^10.3.0", "lint-staged": "^10.3.0",
"mini-css-extract-plugin": "^0.11.1", "mini-css-extract-plugin": "^0.11.1",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",

View file

@ -425,6 +425,9 @@ export class Community extends Component<any, State> {
this.state.loading = false; this.state.loading = false;
} }
this.setState(this.state); this.setState(this.state);
WebSocketService.Instance.communityJoin({
community_id: data.community.id,
});
} else if ( } else if (
res.op == UserOperation.EditCommunity || res.op == UserOperation.EditCommunity ||
res.op == UserOperation.DeleteCommunity || res.op == UserOperation.DeleteCommunity ||

View file

@ -151,6 +151,10 @@ export class Main extends Component<any, MainState> {
WebSocketService.Instance.listCommunities(listCommunitiesForm); WebSocketService.Instance.listCommunities(listCommunitiesForm);
} }
componentDidMount() {
WebSocketService.Instance.communityJoin({ community_id: 0 });
}
componentWillUnmount() { componentWillUnmount() {
if (isBrowser()) { if (isBrowser()) {
this.subscription.unsubscribe(); this.subscription.unsubscribe();

View file

@ -134,6 +134,7 @@ export class Post extends Component<any, PostState> {
} }
componentDidMount() { componentDidMount() {
WebSocketService.Instance.postJoin({ post_id: this.state.postId });
autosize(document.querySelectorAll('textarea')); autosize(document.querySelectorAll('textarea'));
} }

View file

@ -55,6 +55,8 @@ import {
SiteConfigForm, SiteConfigForm,
MarkAllAsReadForm, MarkAllAsReadForm,
WebSocketJsonResponse, WebSocketJsonResponse,
CommunityJoinForm,
PostJoinForm,
} from 'lemmy-js-client'; } from 'lemmy-js-client';
import { UserService } from './'; import { UserService } from './';
import { i18n } from '../i18next'; import { i18n } from '../i18next';
@ -85,7 +87,7 @@ export class WebSocketService {
this.ws = new ReconnectingWebSocket(wsUri, [], this.wsOptions); this.ws = new ReconnectingWebSocket(wsUri, [], this.wsOptions);
let firstConnect = true; let firstConnect = true;
this.subject = Observable.create((obs: any) => { this.subject = new Observable((obs: any) => {
this.ws.onmessage = e => { this.ws.onmessage = e => {
obs.next(JSON.parse(e.data)); obs.next(JSON.parse(e.data));
}; };
@ -113,6 +115,14 @@ export class WebSocketService {
this.ws.send(this.client.userJoin(form)); this.ws.send(this.client.userJoin(form));
} }
public postJoin(form: PostJoinForm) {
this.ws.send(this.client.postJoin(form));
}
public communityJoin(form: CommunityJoinForm) {
this.ws.send(this.client.communityJoin(form));
}
public login(form: LoginForm) { public login(form: LoginForm) {
this.ws.send(this.client.login(form)); this.ws.send(this.client.login(form));
} }

View file

@ -5827,10 +5827,10 @@ lcid@^1.0.0:
dependencies: dependencies:
invert-kv "^1.0.0" invert-kv "^1.0.0"
lemmy-js-client@^1.0.11: lemmy-js-client@^1.0.13:
version "1.0.11" version "1.0.13"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.11.tgz#f6ccdd5f4bf60c9ec49a4337c92d91933c0d00c2" resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.13.tgz#d0e1246129ade295faeec1fb4b2c7397d6947a19"
integrity sha512-bMvCKcP76YpSYhVSX0hGnhf9DQWpu7j4UQG2ektbpsmTi+yA4JiZKsLQXwgQH7hty42EHV0ZJVBNUpqlKnGFrA== integrity sha512-Xz87cCswi/2pbDdApw9JIy8bDWRFGiGWO6IhehTytOAzf36dr4GYgsjTQTLjBX+s+BNYr8hE0+Sz4g9c+ynoJg==
leven@^3.1.0: leven@^3.1.0:
version "3.1.0" version "3.1.0"