SortType,
Post,
GetPostsForm,
+ GetCommunityForm,
ListingType,
GetPostsResponse,
CreatePostLikeResponse,
() => console.log('complete')
);
- if (this.state.communityId) {
- WebSocketService.Instance.getCommunity(this.state.communityId);
- } else if (this.state.communityName) {
- WebSocketService.Instance.getCommunityByName(this.state.communityName);
- }
+ let form: GetCommunityForm = {
+ id: this.state.communityId ? this.state.communityId : null,
+ name: this.state.communityName ? this.state.communityName : null,
+ };
+ WebSocketService.Instance.getCommunity(form);
}
componentWillUnmount() {
Messages,
}
+type ReplyType = Comment | PrivateMessageI;
+
interface InboxState {
unreadOrAll: UnreadOrAll;
unreadType: UnreadType;
}
all() {
- let combined: Array<Comment | PrivateMessageI> = [];
+ let combined: Array<ReplyType> = [];
combined.push(...this.state.replies);
combined.push(...this.state.mentions);
SearchType,
SortType,
SearchForm,
+ GetPostForm,
SearchResponse,
GetSiteResponse,
GetCommunityResponse,
() => console.log('complete')
);
- WebSocketService.Instance.getPost(postId);
+ let form: GetPostForm = {
+ id: postId,
+ };
+ WebSocketService.Instance.getPost(form);
}
componentWillUnmount() {
auth?: string;
}
+export interface GetFollowedCommunitiesForm {
+ auth: string;
+}
+
export interface GetFollowedCommunitiesResponse {
communities: Array<CommunityUser>;
}
auth?: string;
}
+export interface GetCommunityForm {
+ id?: number;
+ name?: string;
+ auth?: string;
+}
+
export interface GetCommunityResponse {
community: Community;
moderators: Array<CommunityUser>;
community?: string;
}
+export interface GetPostForm {
+ id: number;
+ auth?: string;
+}
+
export interface GetPostResponse {
post: Post;
comments: Array<Comment>;
message: PrivateMessage;
}
+export type MessageType =
+ | EditPrivateMessageForm
+ | LoginForm
+ | RegisterForm
+ | CommunityForm
+ | FollowCommunityForm
+ | ListCommunitiesForm
+ | GetFollowedCommunitiesForm
+ | PostForm
+ | GetPostForm
+ | GetPostsForm
+ | GetCommunityForm
+ | CommentForm
+ | CommentLikeForm
+ | SaveCommentForm
+ | CreatePostLikeForm
+ | BanFromCommunityForm
+ | AddAdminForm
+ | AddModToCommunityForm
+ | TransferCommunityForm
+ | TransferSiteForm
+ | SaveCommentForm
+ | BanUserForm
+ | AddAdminForm
+ | GetUserDetailsForm
+ | GetRepliesForm
+ | GetUserMentionsForm
+ | EditUserMentionForm
+ | GetModlogForm
+ | SiteForm
+ | SearchForm
+ | UserSettingsForm
+ | DeleteAccountForm
+ | PasswordResetForm
+ | PasswordChangeForm
+ | PrivateMessageForm
+ | EditPrivateMessageForm
+ | GetPrivateMessagesForm;
+
type ResponseType =
| SiteResponse
| GetFollowedCommunitiesResponse
CommentForm,
SaveCommentForm,
CommentLikeForm,
+ GetPostForm,
GetPostsForm,
CreatePostLikeForm,
+ GetCommunityForm,
FollowCommunityForm,
+ GetFollowedCommunitiesForm,
GetUserDetailsForm,
ListCommunitiesForm,
GetModlogForm,
PrivateMessageForm,
EditPrivateMessageForm,
GetPrivateMessagesForm,
+ MessageType,
} from '../interfaces';
import { webSocket } from 'rxjs/webSocket';
import { Subject } from 'rxjs';
}
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)
);
}
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) {
);
}
- private wsSendWrapper(op: UserOperation, data: any) {
+ private wsSendWrapper(op: UserOperation, data: MessageType) {
let send = { op: UserOperation[op], data: data };
console.log(send);
return send;