From 2e84441e6635b42065ef646238a6c95aea207548 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 27 Jan 2020 21:04:30 -0500 Subject: Strictly typing websocket forms. --- ui/src/services/WebSocketService.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'ui/src/services/WebSocketService.ts') diff --git a/ui/src/services/WebSocketService.ts b/ui/src/services/WebSocketService.ts index e72a2871..9f09e56a 100644 --- a/ui/src/services/WebSocketService.ts +++ b/ui/src/services/WebSocketService.ts @@ -9,9 +9,12 @@ import { CommentForm, SaveCommentForm, CommentLikeForm, + GetPostForm, GetPostsForm, CreatePostLikeForm, + GetCommunityForm, FollowCommunityForm, + GetFollowedCommunitiesForm, GetUserDetailsForm, ListCommunitiesForm, GetModlogForm, @@ -35,6 +38,7 @@ import { PrivateMessageForm, EditPrivateMessageForm, GetPrivateMessagesForm, + MessageType, } from '../interfaces'; import { webSocket } from 'rxjs/webSocket'; import { Subject } from 'rxjs'; @@ -108,9 +112,9 @@ export class WebSocketService { } public getFollowedCommunities() { - let data = { auth: UserService.Instance.auth }; + let form: GetFollowedCommunitiesForm = { auth: UserService.Instance.auth }; this.subject.next( - this.wsSendWrapper(UserOperation.GetFollowedCommunities, data) + this.wsSendWrapper(UserOperation.GetFollowedCommunities, form) ); } @@ -125,19 +129,14 @@ export class WebSocketService { this.subject.next(this.wsSendWrapper(UserOperation.CreatePost, postForm)); } - public getPost(postId: number) { - let data = { id: postId, auth: UserService.Instance.auth }; - this.subject.next(this.wsSendWrapper(UserOperation.GetPost, data)); - } - - public getCommunity(communityId: number) { - let data = { id: communityId, auth: UserService.Instance.auth }; - this.subject.next(this.wsSendWrapper(UserOperation.GetCommunity, data)); + public getPost(form: GetPostForm) { + this.setAuth(form); + this.subject.next(this.wsSendWrapper(UserOperation.GetPost, form)); } - public getCommunityByName(name: string) { - let data = { name: name, auth: UserService.Instance.auth }; - this.subject.next(this.wsSendWrapper(UserOperation.GetCommunity, data)); + public getCommunity(form: GetCommunityForm) { + this.setAuth(form); + this.subject.next(this.wsSendWrapper(UserOperation.GetCommunity, form)); } public createComment(commentForm: CommentForm) { @@ -310,7 +309,7 @@ export class WebSocketService { ); } - private wsSendWrapper(op: UserOperation, data: any) { + private wsSendWrapper(op: UserOperation, data: MessageType) { let send = { op: UserOperation[op], data: data }; console.log(send); return send; -- cgit v1.2.3 From 451dfe679a6d9cc882b949c7a48b466b0fd71c8c Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 28 Jan 2020 08:47:37 -0500 Subject: Add not throwing error on auth check for getPost and getCommunity. Fixes #475 --- ui/src/services/WebSocketService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ui/src/services/WebSocketService.ts') diff --git a/ui/src/services/WebSocketService.ts b/ui/src/services/WebSocketService.ts index 9f09e56a..83e9ef1e 100644 --- a/ui/src/services/WebSocketService.ts +++ b/ui/src/services/WebSocketService.ts @@ -130,12 +130,12 @@ export class WebSocketService { } public getPost(form: GetPostForm) { - this.setAuth(form); + this.setAuth(form, false); this.subject.next(this.wsSendWrapper(UserOperation.GetPost, form)); } public getCommunity(form: GetCommunityForm) { - this.setAuth(form); + this.setAuth(form, false); this.subject.next(this.wsSendWrapper(UserOperation.GetCommunity, form)); } -- cgit v1.2.3