2019-03-22 21:42:57 -04:00
|
|
|
import { wsUri } from '../env';
|
2019-10-18 20:20:27 -04:00
|
|
|
import {
|
|
|
|
LoginForm,
|
|
|
|
RegisterForm,
|
|
|
|
UserOperation,
|
|
|
|
CommunityForm,
|
2020-07-20 13:37:39 -04:00
|
|
|
DeleteCommunityForm,
|
|
|
|
RemoveCommunityForm,
|
2019-10-18 20:20:27 -04:00
|
|
|
PostForm,
|
|
|
|
SavePostForm,
|
|
|
|
CommentForm,
|
2020-07-20 21:37:44 -04:00
|
|
|
DeleteCommentForm,
|
|
|
|
RemoveCommentForm,
|
|
|
|
MarkCommentAsReadForm,
|
2019-10-18 20:20:27 -04:00
|
|
|
SaveCommentForm,
|
|
|
|
CommentLikeForm,
|
2020-01-27 21:04:30 -05:00
|
|
|
GetPostForm,
|
2019-10-18 20:20:27 -04:00
|
|
|
GetPostsForm,
|
|
|
|
CreatePostLikeForm,
|
2020-01-27 21:04:30 -05:00
|
|
|
GetCommunityForm,
|
2019-10-18 20:20:27 -04:00
|
|
|
FollowCommunityForm,
|
2020-01-27 21:04:30 -05:00
|
|
|
GetFollowedCommunitiesForm,
|
2019-10-18 20:20:27 -04:00
|
|
|
GetUserDetailsForm,
|
|
|
|
ListCommunitiesForm,
|
|
|
|
GetModlogForm,
|
|
|
|
BanFromCommunityForm,
|
|
|
|
AddModToCommunityForm,
|
|
|
|
TransferCommunityForm,
|
|
|
|
AddAdminForm,
|
|
|
|
TransferSiteForm,
|
|
|
|
BanUserForm,
|
|
|
|
SiteForm,
|
|
|
|
UserView,
|
|
|
|
GetRepliesForm,
|
2019-10-19 20:46:29 -04:00
|
|
|
GetUserMentionsForm,
|
2020-07-20 10:56:40 -04:00
|
|
|
MarkUserMentionAsReadForm,
|
2019-10-18 20:20:27 -04:00
|
|
|
SearchForm,
|
|
|
|
UserSettingsForm,
|
|
|
|
DeleteAccountForm,
|
2019-10-29 23:35:39 -04:00
|
|
|
PasswordResetForm,
|
2019-11-02 02:41:57 -04:00
|
|
|
PasswordChangeForm,
|
2020-01-22 16:35:29 -05:00
|
|
|
PrivateMessageForm,
|
|
|
|
EditPrivateMessageForm,
|
2020-07-20 00:29:44 -04:00
|
|
|
DeletePrivateMessageForm,
|
|
|
|
MarkPrivateMessageAsReadForm,
|
2020-01-22 16:35:29 -05:00
|
|
|
GetPrivateMessagesForm,
|
2020-02-07 23:05:15 -05:00
|
|
|
GetCommentsForm,
|
2020-01-31 20:02:20 -05:00
|
|
|
UserJoinForm,
|
2020-04-10 16:55:57 -04:00
|
|
|
GetSiteConfig,
|
|
|
|
SiteConfigForm,
|
2020-01-27 21:04:30 -05:00
|
|
|
MessageType,
|
2020-02-04 11:19:05 -05:00
|
|
|
WebSocketJsonResponse,
|
2019-10-18 20:20:27 -04:00
|
|
|
} from '../interfaces';
|
2019-03-22 21:42:57 -04:00
|
|
|
import { UserService } from './';
|
2019-08-09 20:14:43 -04:00
|
|
|
import { i18n } from '../i18next';
|
2020-01-22 22:29:11 -05:00
|
|
|
import { toast } from '../utils';
|
2020-02-01 22:52:16 -05:00
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { share } from 'rxjs/operators';
|
|
|
|
import ReconnectingWebSocket from 'reconnecting-websocket';
|
2019-03-22 21:42:57 -04:00
|
|
|
|
|
|
|
export class WebSocketService {
|
|
|
|
private static _instance: WebSocketService;
|
2020-02-01 22:52:16 -05:00
|
|
|
public ws: ReconnectingWebSocket;
|
|
|
|
public subject: Observable<any>;
|
2019-04-16 19:04:23 -04:00
|
|
|
|
|
|
|
public admins: Array<UserView>;
|
|
|
|
public banned: Array<UserView>;
|
2019-03-22 21:42:57 -04:00
|
|
|
|
|
|
|
private constructor() {
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws = new ReconnectingWebSocket(wsUri);
|
2020-03-04 22:35:55 -05:00
|
|
|
let firstConnect = true;
|
2019-03-26 14:00:18 -04:00
|
|
|
|
2020-02-01 22:52:16 -05:00
|
|
|
this.subject = Observable.create((obs: any) => {
|
|
|
|
this.ws.onmessage = e => {
|
|
|
|
obs.next(JSON.parse(e.data));
|
|
|
|
};
|
2020-02-04 11:19:05 -05:00
|
|
|
this.ws.onopen = () => {
|
|
|
|
console.log(`Connected to ${wsUri}`);
|
2020-03-04 22:35:55 -05:00
|
|
|
|
2020-02-04 11:19:05 -05:00
|
|
|
if (UserService.Instance.user) {
|
|
|
|
this.userJoin();
|
|
|
|
}
|
2020-03-04 22:35:55 -05:00
|
|
|
|
|
|
|
if (!firstConnect) {
|
|
|
|
let res: WebSocketJsonResponse = {
|
|
|
|
reconnect: true,
|
|
|
|
};
|
|
|
|
obs.next(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
firstConnect = false;
|
2020-02-04 11:19:05 -05:00
|
|
|
};
|
2020-02-01 22:52:16 -05:00
|
|
|
}).pipe(share());
|
2019-03-22 21:42:57 -04:00
|
|
|
}
|
|
|
|
|
2019-10-18 20:20:27 -04:00
|
|
|
public static get Instance() {
|
2019-03-22 21:42:57 -04:00
|
|
|
return this._instance || (this._instance = new this());
|
|
|
|
}
|
2019-10-18 20:20:27 -04:00
|
|
|
|
2020-01-26 12:23:28 -05:00
|
|
|
public userJoin() {
|
2020-01-31 20:02:20 -05:00
|
|
|
let form: UserJoinForm = { auth: UserService.Instance.auth };
|
2020-02-02 09:15:02 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.UserJoin, form));
|
2020-01-26 12:23:28 -05:00
|
|
|
}
|
|
|
|
|
2019-03-22 21:42:57 -04:00
|
|
|
public login(loginForm: LoginForm) {
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.Login, loginForm));
|
2019-03-22 21:42:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public register(registerForm: RegisterForm) {
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.Register, registerForm));
|
2019-03-22 21:42:57 -04:00
|
|
|
}
|
|
|
|
|
2020-07-20 13:37:39 -04:00
|
|
|
public createCommunity(form: CommunityForm) {
|
|
|
|
this.setAuth(form);
|
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.CreateCommunity, form));
|
2019-03-26 14:00:18 -04:00
|
|
|
}
|
|
|
|
|
2020-07-20 13:37:39 -04:00
|
|
|
public editCommunity(form: CommunityForm) {
|
|
|
|
this.setAuth(form);
|
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.EditCommunity, form));
|
|
|
|
}
|
|
|
|
|
|
|
|
public deleteCommunity(form: DeleteCommunityForm) {
|
|
|
|
this.setAuth(form);
|
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.DeleteCommunity, form));
|
|
|
|
}
|
|
|
|
|
|
|
|
public removeCommunity(form: RemoveCommunityForm) {
|
|
|
|
this.setAuth(form);
|
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.RemoveCommunity, form));
|
2019-04-04 18:29:14 -04:00
|
|
|
}
|
|
|
|
|
2019-04-05 02:26:38 -04:00
|
|
|
public followCommunity(followCommunityForm: FollowCommunityForm) {
|
|
|
|
this.setAuth(followCommunityForm);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(
|
2019-10-18 20:20:27 -04:00
|
|
|
this.wsSendWrapper(UserOperation.FollowCommunity, followCommunityForm)
|
|
|
|
);
|
2019-04-05 02:26:38 -04:00
|
|
|
}
|
|
|
|
|
2019-04-10 02:19:12 -04:00
|
|
|
public listCommunities(form: ListCommunitiesForm) {
|
|
|
|
this.setAuth(form, false);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.ListCommunities, form));
|
2019-03-26 14:00:18 -04:00
|
|
|
}
|
|
|
|
|
2019-04-05 15:14:54 -04:00
|
|
|
public getFollowedCommunities() {
|
2020-01-27 21:04:30 -05:00
|
|
|
let form: GetFollowedCommunitiesForm = { auth: UserService.Instance.auth };
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(
|
2020-01-27 21:04:30 -05:00
|
|
|
this.wsSendWrapper(UserOperation.GetFollowedCommunities, form)
|
2019-10-18 20:20:27 -04:00
|
|
|
);
|
2019-04-05 15:14:54 -04:00
|
|
|
}
|
|
|
|
|
2019-04-03 19:01:20 -04:00
|
|
|
public listCategories() {
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.ListCategories, {}));
|
2019-04-03 19:01:20 -04:00
|
|
|
}
|
|
|
|
|
2019-03-26 14:00:18 -04:00
|
|
|
public createPost(postForm: PostForm) {
|
|
|
|
this.setAuth(postForm);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.CreatePost, postForm));
|
2019-03-26 14:00:18 -04:00
|
|
|
}
|
|
|
|
|
2020-01-27 21:04:30 -05:00
|
|
|
public getPost(form: GetPostForm) {
|
2020-01-28 08:47:37 -05:00
|
|
|
this.setAuth(form, false);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.GetPost, form));
|
2019-03-26 14:00:18 -04:00
|
|
|
}
|
|
|
|
|
2020-01-27 21:04:30 -05:00
|
|
|
public getCommunity(form: GetCommunityForm) {
|
2020-01-28 08:47:37 -05:00
|
|
|
this.setAuth(form, false);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.GetCommunity, form));
|
2019-04-25 17:52:18 -04:00
|
|
|
}
|
|
|
|
|
2020-07-20 21:37:44 -04:00
|
|
|
public createComment(form: CommentForm) {
|
|
|
|
this.setAuth(form);
|
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.CreateComment, form));
|
|
|
|
}
|
|
|
|
|
|
|
|
public editComment(form: CommentForm) {
|
|
|
|
this.setAuth(form);
|
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.EditComment, form));
|
2019-03-26 14:00:18 -04:00
|
|
|
}
|
|
|
|
|
2020-07-20 21:37:44 -04:00
|
|
|
public deleteComment(form: DeleteCommentForm) {
|
|
|
|
this.setAuth(form);
|
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.DeleteComment, form));
|
|
|
|
}
|
|
|
|
|
|
|
|
public removeComment(form: RemoveCommentForm) {
|
|
|
|
this.setAuth(form);
|
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.RemoveComment, form));
|
|
|
|
}
|
|
|
|
|
|
|
|
public markCommentAsRead(form: MarkCommentAsReadForm) {
|
|
|
|
this.setAuth(form);
|
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.MarkCommentAsRead, form));
|
2019-03-29 00:56:23 -04:00
|
|
|
}
|
|
|
|
|
2019-03-28 15:32:08 -04:00
|
|
|
public likeComment(form: CommentLikeForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.CreateCommentLike, form));
|
2019-03-28 15:32:08 -04:00
|
|
|
}
|
|
|
|
|
2019-04-20 00:06:25 -04:00
|
|
|
public saveComment(form: SaveCommentForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.SaveComment, form));
|
2019-04-20 00:06:25 -04:00
|
|
|
}
|
|
|
|
|
2019-04-04 18:29:14 -04:00
|
|
|
public getPosts(form: GetPostsForm) {
|
2019-04-03 02:49:32 -04:00
|
|
|
this.setAuth(form, false);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.GetPosts, form));
|
2019-04-03 02:49:32 -04:00
|
|
|
}
|
|
|
|
|
2020-02-07 23:05:15 -05:00
|
|
|
public getComments(form: GetCommentsForm) {
|
|
|
|
this.setAuth(form, false);
|
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.GetComments, form));
|
|
|
|
}
|
|
|
|
|
2019-04-03 02:49:32 -04:00
|
|
|
public likePost(form: CreatePostLikeForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.CreatePostLike, form));
|
2019-04-03 02:49:32 -04:00
|
|
|
}
|
|
|
|
|
2019-04-03 16:59:37 -04:00
|
|
|
public editPost(postForm: PostForm) {
|
|
|
|
this.setAuth(postForm);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.EditPost, postForm));
|
2019-04-03 16:59:37 -04:00
|
|
|
}
|
|
|
|
|
2019-04-20 00:06:25 -04:00
|
|
|
public savePost(form: SavePostForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.SavePost, form));
|
2019-04-20 00:06:25 -04:00
|
|
|
}
|
|
|
|
|
2019-04-15 19:12:06 -04:00
|
|
|
public banFromCommunity(form: BanFromCommunityForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.BanFromCommunity, form));
|
2019-04-15 19:12:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public addModToCommunity(form: AddModToCommunityForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.AddModToCommunity, form));
|
2019-04-15 19:12:06 -04:00
|
|
|
}
|
|
|
|
|
2019-08-23 22:40:41 -04:00
|
|
|
public transferCommunity(form: TransferCommunityForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.TransferCommunity, form));
|
2019-08-23 22:40:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public transferSite(form: TransferSiteForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.TransferSite, form));
|
2019-08-23 22:40:41 -04:00
|
|
|
}
|
2019-10-18 20:20:27 -04:00
|
|
|
|
2019-04-20 00:06:25 -04:00
|
|
|
public banUser(form: BanUserForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.BanUser, form));
|
2019-04-20 00:06:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public addAdmin(form: AddAdminForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.AddAdmin, form));
|
2019-04-20 00:06:25 -04:00
|
|
|
}
|
|
|
|
|
2019-04-08 01:19:02 -04:00
|
|
|
public getUserDetails(form: GetUserDetailsForm) {
|
2019-04-29 17:19:00 -04:00
|
|
|
this.setAuth(form, false);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.GetUserDetails, form));
|
2019-04-08 01:19:02 -04:00
|
|
|
}
|
2019-04-20 14:17:00 -04:00
|
|
|
|
|
|
|
public getReplies(form: GetRepliesForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.GetReplies, form));
|
2019-04-20 14:17:00 -04:00
|
|
|
}
|
2019-04-08 01:19:02 -04:00
|
|
|
|
2019-10-19 20:46:29 -04:00
|
|
|
public getUserMentions(form: GetUserMentionsForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.GetUserMentions, form));
|
2019-10-19 20:46:29 -04:00
|
|
|
}
|
|
|
|
|
2020-07-20 10:56:40 -04:00
|
|
|
public markUserMentionAsRead(form: MarkUserMentionAsReadForm) {
|
2019-10-19 20:46:29 -04:00
|
|
|
this.setAuth(form);
|
2020-07-20 10:56:40 -04:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.MarkUserMentionAsRead, form));
|
2019-10-19 20:46:29 -04:00
|
|
|
}
|
|
|
|
|
2019-04-15 19:12:06 -04:00
|
|
|
public getModlog(form: GetModlogForm) {
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.GetModlog, form));
|
2019-04-15 19:12:06 -04:00
|
|
|
}
|
|
|
|
|
2019-04-16 19:04:23 -04:00
|
|
|
public createSite(siteForm: SiteForm) {
|
|
|
|
this.setAuth(siteForm);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.CreateSite, siteForm));
|
2019-04-16 19:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public editSite(siteForm: SiteForm) {
|
|
|
|
this.setAuth(siteForm);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.EditSite, siteForm));
|
2019-04-16 19:04:23 -04:00
|
|
|
}
|
2019-04-23 18:05:50 -04:00
|
|
|
|
2019-04-16 19:04:23 -04:00
|
|
|
public getSite() {
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.GetSite, {}));
|
2019-04-16 19:04:23 -04:00
|
|
|
}
|
|
|
|
|
2020-04-10 16:55:57 -04:00
|
|
|
public getSiteConfig() {
|
|
|
|
let siteConfig: GetSiteConfig = {};
|
|
|
|
this.setAuth(siteConfig);
|
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.GetSiteConfig, siteConfig));
|
|
|
|
}
|
|
|
|
|
2019-04-23 18:05:50 -04:00
|
|
|
public search(form: SearchForm) {
|
2020-01-20 18:39:45 -05:00
|
|
|
this.setAuth(form, false);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.Search, form));
|
2019-04-23 18:05:50 -04:00
|
|
|
}
|
|
|
|
|
2019-04-29 12:51:13 -04:00
|
|
|
public markAllAsRead() {
|
|
|
|
let form = {};
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.MarkAllAsRead, form));
|
2019-04-29 12:51:13 -04:00
|
|
|
}
|
|
|
|
|
2019-08-13 22:52:43 -04:00
|
|
|
public saveUserSettings(userSettingsForm: UserSettingsForm) {
|
|
|
|
this.setAuth(userSettingsForm);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(
|
2019-10-18 20:20:27 -04:00
|
|
|
this.wsSendWrapper(UserOperation.SaveUserSettings, userSettingsForm)
|
|
|
|
);
|
2019-08-13 22:52:43 -04:00
|
|
|
}
|
|
|
|
|
2019-10-18 00:25:23 -04:00
|
|
|
public deleteAccount(form: DeleteAccountForm) {
|
2019-10-15 18:09:01 -04:00
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.DeleteAccount, form));
|
2019-10-15 18:09:01 -04:00
|
|
|
}
|
|
|
|
|
2019-10-29 23:35:39 -04:00
|
|
|
public passwordReset(form: PasswordResetForm) {
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.PasswordReset, form));
|
2019-10-29 23:35:39 -04:00
|
|
|
}
|
|
|
|
|
2019-11-02 02:41:57 -04:00
|
|
|
public passwordChange(form: PasswordChangeForm) {
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.PasswordChange, form));
|
2019-11-02 02:41:57 -04:00
|
|
|
}
|
|
|
|
|
2020-01-22 16:35:29 -05:00
|
|
|
public createPrivateMessage(form: PrivateMessageForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.CreatePrivateMessage, form));
|
2020-01-22 16:35:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public editPrivateMessage(form: EditPrivateMessageForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.EditPrivateMessage, form));
|
2020-01-22 16:35:29 -05:00
|
|
|
}
|
|
|
|
|
2020-07-20 00:29:44 -04:00
|
|
|
public deletePrivateMessage(form: DeletePrivateMessageForm) {
|
|
|
|
this.setAuth(form);
|
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.DeletePrivateMessage, form));
|
|
|
|
}
|
|
|
|
|
|
|
|
public markPrivateMessageAsRead(form: MarkPrivateMessageAsReadForm) {
|
|
|
|
this.setAuth(form);
|
|
|
|
this.ws.send(
|
|
|
|
this.wsSendWrapper(UserOperation.MarkPrivateMessageAsRead, form)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-22 16:35:29 -05:00
|
|
|
public getPrivateMessages(form: GetPrivateMessagesForm) {
|
|
|
|
this.setAuth(form);
|
2020-02-01 22:52:16 -05:00
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.GetPrivateMessages, form));
|
2020-01-22 16:35:29 -05:00
|
|
|
}
|
|
|
|
|
2020-04-10 16:55:57 -04:00
|
|
|
public saveSiteConfig(form: SiteConfigForm) {
|
|
|
|
this.setAuth(form);
|
|
|
|
this.ws.send(this.wsSendWrapper(UserOperation.SaveSiteConfig, form));
|
|
|
|
}
|
|
|
|
|
2020-01-27 21:04:30 -05:00
|
|
|
private wsSendWrapper(op: UserOperation, data: MessageType) {
|
2019-03-26 14:00:18 -04:00
|
|
|
let send = { op: UserOperation[op], data: data };
|
2019-03-22 21:42:57 -04:00
|
|
|
console.log(send);
|
2020-02-01 22:52:16 -05:00
|
|
|
return JSON.stringify(send);
|
2019-03-22 21:42:57 -04:00
|
|
|
}
|
2019-03-26 14:00:18 -04:00
|
|
|
|
2019-04-03 02:49:32 -04:00
|
|
|
private setAuth(obj: any, throwErr: boolean = true) {
|
2019-03-26 14:00:18 -04:00
|
|
|
obj.auth = UserService.Instance.auth;
|
2019-04-03 02:49:32 -04:00
|
|
|
if (obj.auth == null && throwErr) {
|
2020-01-22 22:29:11 -05:00
|
|
|
toast(i18n.t('not_logged_in'), 'danger');
|
2019-10-18 20:20:27 -04:00
|
|
|
throw 'Not logged in';
|
2019-03-26 14:00:18 -04:00
|
|
|
}
|
|
|
|
}
|
2019-03-22 21:42:57 -04:00
|
|
|
}
|
2019-03-28 15:32:08 -04:00
|
|
|
|
2019-10-18 20:20:27 -04:00
|
|
|
window.onbeforeunload = () => {
|
2020-02-01 22:52:16 -05:00
|
|
|
WebSocketService.Instance.ws.close();
|
2019-10-18 20:20:27 -04:00
|
|
|
};
|