From: Dessalines Date: Sun, 13 Sep 2020 15:37:23 +0000 (-0500) Subject: Adding support for join messages. Fixes #8 X-Git-Url: http://these/git/%22https:/nerdica.net/README.es.md?a=commitdiff_plain;h=fd43a890a7d5439093c65b6c210b1490d9c4fcf0;p=lemmy-ui.git Adding support for join messages. Fixes #8 --- diff --git a/package.json b/package.json index a74114a..78f2d9c 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "eslint": "^7.8.1", "eslint-plugin-jane": "^9.0.0", "husky": "^4.3.0", - "lemmy-js-client": "^1.0.11", + "lemmy-js-client": "^1.0.13", "lint-staged": "^10.3.0", "mini-css-extract-plugin": "^0.11.1", "node-fetch": "^2.6.1", diff --git a/src/shared/components/community.tsx b/src/shared/components/community.tsx index 7deb62b..b76a216 100644 --- a/src/shared/components/community.tsx +++ b/src/shared/components/community.tsx @@ -425,6 +425,9 @@ export class Community extends Component { this.state.loading = false; } this.setState(this.state); + WebSocketService.Instance.communityJoin({ + community_id: data.community.id, + }); } else if ( res.op == UserOperation.EditCommunity || res.op == UserOperation.DeleteCommunity || diff --git a/src/shared/components/main.tsx b/src/shared/components/main.tsx index 62010f5..33d79ec 100644 --- a/src/shared/components/main.tsx +++ b/src/shared/components/main.tsx @@ -151,6 +151,10 @@ export class Main extends Component { WebSocketService.Instance.listCommunities(listCommunitiesForm); } + componentDidMount() { + WebSocketService.Instance.communityJoin({ community_id: 0 }); + } + componentWillUnmount() { if (isBrowser()) { this.subscription.unsubscribe(); diff --git a/src/shared/components/post.tsx b/src/shared/components/post.tsx index 6f1bf6d..a7c9f79 100644 --- a/src/shared/components/post.tsx +++ b/src/shared/components/post.tsx @@ -134,6 +134,7 @@ export class Post extends Component { } componentDidMount() { + WebSocketService.Instance.postJoin({ post_id: this.state.postId }); autosize(document.querySelectorAll('textarea')); } diff --git a/src/shared/services/WebSocketService.ts b/src/shared/services/WebSocketService.ts index 646f9de..634a9b7 100644 --- a/src/shared/services/WebSocketService.ts +++ b/src/shared/services/WebSocketService.ts @@ -55,6 +55,8 @@ import { SiteConfigForm, MarkAllAsReadForm, WebSocketJsonResponse, + CommunityJoinForm, + PostJoinForm, } from 'lemmy-js-client'; import { UserService } from './'; import { i18n } from '../i18next'; @@ -85,7 +87,7 @@ export class WebSocketService { this.ws = new ReconnectingWebSocket(wsUri, [], this.wsOptions); let firstConnect = true; - this.subject = Observable.create((obs: any) => { + this.subject = new Observable((obs: any) => { this.ws.onmessage = e => { obs.next(JSON.parse(e.data)); }; @@ -113,6 +115,14 @@ export class WebSocketService { 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) { this.ws.send(this.client.login(form)); } diff --git a/yarn.lock b/yarn.lock index 659250a..ddef340 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5827,10 +5827,10 @@ lcid@^1.0.0: dependencies: invert-kv "^1.0.0" -lemmy-js-client@^1.0.11: - version "1.0.11" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.11.tgz#f6ccdd5f4bf60c9ec49a4337c92d91933c0d00c2" - integrity sha512-bMvCKcP76YpSYhVSX0hGnhf9DQWpu7j4UQG2ektbpsmTi+yA4JiZKsLQXwgQH7hty42EHV0ZJVBNUpqlKnGFrA== +lemmy-js-client@^1.0.13: + version "1.0.13" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.13.tgz#d0e1246129ade295faeec1fb4b2c7397d6947a19" + integrity sha512-Xz87cCswi/2pbDdApw9JIy8bDWRFGiGWO6IhehTytOAzf36dr4GYgsjTQTLjBX+s+BNYr8hE0+Sz4g9c+ynoJg== leven@^3.1.0: version "3.1.0"