From 46043334c839c995d8bc39e70bd7873d22ec0202 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 19 Aug 2020 23:59:45 -0400 Subject: [PATCH] Adding an HTTP client. Cleaning up Websocket client. --- server/src/routes/api.rs | 4 +- ui/package.json | 2 +- ui/src/api_tests/comment.spec.ts | 2 +- ui/src/api_tests/shared.ts | 457 +++++++--------------------- ui/src/services/WebSocketService.ts | 179 ++++------- ui/yarn.lock | 8 +- 6 files changed, 176 insertions(+), 476 deletions(-) diff --git a/server/src/routes/api.rs b/server/src/routes/api.rs index 1c88ffa24..201908623 100644 --- a/server/src/routes/api.rs +++ b/server/src/routes/api.rs @@ -94,7 +94,8 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { web::post().to(route_post::), ) .route("/like", web::post().to(route_post::)) - .route("/save", web::put().to(route_post::)), + .route("/save", web::put().to(route_post::)) + .route("/list", web::get().to(route_get::)), ) // Private Message .service( @@ -136,6 +137,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { "/followed_communities", web::get().to(route_get::), ) + .route("/join", web::post().to(route_post::)) // Admin action. I don't like that it's in /user .route("/ban", web::post().to(route_post::)) // Account actions. I don't like that they're in /user maybe /accounts diff --git a/ui/package.json b/ui/package.json index 6d8c5183c..74740b76f 100644 --- a/ui/package.json +++ b/ui/package.json @@ -37,7 +37,7 @@ "inferno-router": "^7.4.2", "js-cookie": "^2.2.0", "jwt-decode": "^2.2.0", - "lemmy-js-client": "^1.0.2", + "lemmy-js-client": "^1.0.8", "markdown-it": "^11.0.0", "markdown-it-container": "^3.0.0", "markdown-it-emoji": "^1.4.0", diff --git a/ui/src/api_tests/comment.spec.ts b/ui/src/api_tests/comment.spec.ts index a7efefeac..dd55907bf 100644 --- a/ui/src/api_tests/comment.spec.ts +++ b/ui/src/api_tests/comment.spec.ts @@ -131,7 +131,7 @@ test('Remove a comment from admin and community on the same instance', async () test('Remove a comment from admin and community on different instance', async () => { let alphaUser = await registerUser(alpha); let newAlphaApi: API = { - url: alpha.url, + client: alpha.client, auth: alphaUser.jwt, }; diff --git a/ui/src/api_tests/shared.ts b/ui/src/api_tests/shared.ts index 7aa46e5de..d66232171 100644 --- a/ui/src/api_tests/shared.ts +++ b/ui/src/api_tests/shared.ts @@ -1,5 +1,3 @@ -import fetch from 'node-fetch'; - import { LoginForm, LoginResponse, @@ -20,15 +18,21 @@ import { CommentForm, DeleteCommentForm, RemoveCommentForm, + SearchForm, CommentResponse, CommunityForm, DeleteCommunityForm, RemoveCommunityForm, + GetUserMentionsForm, CommentLikeForm, CreatePostLikeForm, PrivateMessageForm, EditPrivateMessageForm, DeletePrivateMessageForm, + GetFollowedCommunitiesForm, + GetPrivateMessagesForm, + GetSiteForm, + GetPostForm, PrivateMessageResponse, PrivateMessagesResponse, GetUserMentionsResponse, @@ -36,27 +40,25 @@ import { SortType, ListingType, GetSiteResponse, + SearchType, + LemmyHttp, } from 'lemmy-js-client'; export interface API { - url: string; + client: LemmyHttp; auth?: string; } -function apiUrl(api: API) { - return `${api.url}/api/v1`; -} - export let alpha: API = { - url: 'http://localhost:8540', + client: new LemmyHttp('http://localhost:8540/api/v1'), }; export let beta: API = { - url: 'http://localhost:8550', + client: new LemmyHttp('http://localhost:8550/api/v1'), }; export let gamma: API = { - url: 'http://localhost:8560', + client: new LemmyHttp('http://localhost:8560/api/v1'), }; export async function setupLogins() { @@ -65,39 +67,21 @@ export async function setupLogins() { password: 'lemmy', }; - let resA: Promise = fetch(`${apiUrl(alpha)}/user/login`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(form), - }).then(d => d.json()); + let resA = alpha.client.login(form); let formB = { username_or_email: 'lemmy_beta', password: 'lemmy', }; - let resB: Promise = fetch(`${apiUrl(beta)}/user/login`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(formB), - }).then(d => d.json()); + let resB = beta.client.login(formB); - let formC = { + let formG = { username_or_email: 'lemmy_gamma', password: 'lemmy', }; - let resG: Promise = fetch(`${apiUrl(gamma)}/user/login`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(formC), - }).then(d => d.json()); + let resG = gamma.client.login(formG); let res = await Promise.all([resA, resB, resG]); alpha.auth = res[0].jwt; @@ -110,40 +94,24 @@ export async function createPost( community_id: number ): Promise { let name = 'A jest test post'; - let postForm: PostForm = { + let form: PostForm = { name, auth: api.auth, community_id, nsfw: false, }; - - let createPostRes: PostResponse = await fetch(`${apiUrl(api)}/post`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(postForm), - }).then(d => d.json()); - return createPostRes; + return api.client.createPost(form); } export async function updatePost(api: API, post: Post): Promise { let name = 'A jest test federated post, updated'; - let postForm: PostForm = { + let form: PostForm = { name, edit_id: post.id, auth: api.auth, nsfw: false, }; - - let updateResponse: PostResponse = await fetch(`${apiUrl(api)}/post`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(postForm), - }).then(d => d.json()); - return updateResponse; + return api.client.editPost(form); } export async function deletePost( @@ -151,20 +119,12 @@ export async function deletePost( deleted: boolean, post: Post ): Promise { - let deletePostForm: DeletePostForm = { + let form: DeletePostForm = { edit_id: post.id, deleted: deleted, auth: api.auth, }; - - let deletePostRes: PostResponse = await fetch(`${apiUrl(api)}/post/delete`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(deletePostForm), - }).then(d => d.json()); - return deletePostRes; + return api.client.deletePost(form); } export async function removePost( @@ -172,20 +132,12 @@ export async function removePost( removed: boolean, post: Post ): Promise { - let removePostForm: RemovePostForm = { + let form: RemovePostForm = { edit_id: post.id, removed, auth: api.auth, }; - - let removePostRes: PostResponse = await fetch(`${apiUrl(api)}/post/remove`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(removePostForm), - }).then(d => d.json()); - return removePostRes; + return api.client.removePost(form); } export async function stickyPost( @@ -193,21 +145,12 @@ export async function stickyPost( stickied: boolean, post: Post ): Promise { - let stickyPostForm: StickyPostForm = { + let form: StickyPostForm = { edit_id: post.id, stickied, auth: api.auth, }; - - let stickyRes: PostResponse = await fetch(`${apiUrl(api)}/post/sticky`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(stickyPostForm), - }).then(d => d.json()); - - return stickyRes; + return api.client.stickyPost(form); } export async function lockPost( @@ -215,57 +158,46 @@ export async function lockPost( locked: boolean, post: Post ): Promise { - let lockPostForm: LockPostForm = { + let form: LockPostForm = { edit_id: post.id, locked, auth: api.auth, }; - - let lockRes: PostResponse = await fetch(`${apiUrl(api)}/post/lock`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(lockPostForm), - }).then(d => d.json()); - - return lockRes; + return api.client.lockPost(form); } export async function searchPost( api: API, post: Post ): Promise { - let searchUrl = `${apiUrl(api)}/search?q=${post.ap_id}&type_=All&sort=TopAll`; - let searchResponse: SearchResponse = await fetch(searchUrl, { - method: 'GET', - }).then(d => d.json()); - return searchResponse; + let form: SearchForm = { + q: post.ap_id, + type_: SearchType.All, + sort: SortType.TopAll, + }; + return api.client.search(form); } export async function getPost( api: API, post_id: number ): Promise { - let getPostUrl = `${apiUrl(api)}/post?id=${post_id}`; - let getPostRes: GetPostResponse = await fetch(getPostUrl, { - method: 'GET', - }).then(d => d.json()); - - return getPostRes; + let form: GetPostForm = { + id: post_id, + }; + return api.client.getPost(form); } export async function searchComment( api: API, comment: Comment ): Promise { - let searchUrl = `${apiUrl(api)}/search?q=${ - comment.ap_id - }&type_=All&sort=TopAll`; - let searchResponse: SearchResponse = await fetch(searchUrl, { - method: 'GET', - }).then(d => d.json()); - return searchResponse; + let form: SearchForm = { + q: comment.ap_id, + type_: SearchType.All, + sort: SortType.TopAll, + }; + return api.client.search(form); } export async function searchForBetaCommunity( @@ -273,14 +205,12 @@ export async function searchForBetaCommunity( ): Promise { // Make sure lemmy-beta/c/main is cached on lemmy_alpha // Use short-hand search url - let searchUrl = `${apiUrl( - api - )}/search?q=!main@lemmy-beta:8550&type_=All&sort=TopAll`; - - let searchResponse: SearchResponse = await fetch(searchUrl, { - method: 'GET', - }).then(d => d.json()); - return searchResponse; + let form: SearchForm = { + q: '!main@lemmy-beta:8550', + type_: SearchType.All, + sort: SortType.TopAll, + }; + return api.client.search(form); } export async function searchForUser( @@ -289,14 +219,12 @@ export async function searchForUser( ): Promise { // Make sure lemmy-beta/c/main is cached on lemmy_alpha // Use short-hand search url - let searchUrl = `${apiUrl( - api - )}/search?q=${apShortname}&type_=All&sort=TopAll`; - - let searchResponse: SearchResponse = await fetch(searchUrl, { - method: 'GET', - }).then(d => d.json()); - return searchResponse; + let form: SearchForm = { + q: apShortname, + type_: SearchType.All, + sort: SortType.TopAll, + }; + return api.client.search(form); } export async function followCommunity( @@ -304,41 +232,21 @@ export async function followCommunity( follow: boolean, community_id: number ): Promise { - let followForm: FollowCommunityForm = { + let form: FollowCommunityForm = { community_id, follow, auth: api.auth, }; - - let followRes: CommunityResponse = await fetch( - `${apiUrl(api)}/community/follow`, - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(followForm), - } - ) - .then(d => d.json()) - .catch(_e => {}); - - return followRes; + return api.client.followCommunity(form); } export async function checkFollowedCommunities( api: API ): Promise { - let followedCommunitiesUrl = `${apiUrl( - api - )}/user/followed_communities?&auth=${api.auth}`; - let followedCommunitiesRes: GetFollowedCommunitiesResponse = await fetch( - followedCommunitiesUrl, - { - method: 'GET', - } - ).then(d => d.json()); - return followedCommunitiesRes; + let form: GetFollowedCommunitiesForm = { + auth: api.auth, + }; + return api.client.getFollowedCommunities(form); } export async function likePost( @@ -346,21 +254,13 @@ export async function likePost( score: number, post: Post ): Promise { - let likePostForm: CreatePostLikeForm = { + let form: CreatePostLikeForm = { post_id: post.id, score: score, auth: api.auth, }; - let likePostRes: PostResponse = await fetch(`${apiUrl(api)}/post/like`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(likePostForm), - }).then(d => d.json()); - - return likePostRes; + return api.client.likePost(form); } export async function createComment( @@ -369,21 +269,13 @@ export async function createComment( parent_id?: number, content = 'a jest test comment' ): Promise { - let commentForm: CommentForm = { + let form: CommentForm = { content, post_id, parent_id, auth: api.auth, }; - - let createResponse: CommentResponse = await fetch(`${apiUrl(api)}/comment`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(commentForm), - }).then(d => d.json()); - return createResponse; + return api.client.createComment(form); } export async function updateComment( @@ -391,20 +283,12 @@ export async function updateComment( edit_id: number, content = 'A jest test federated comment update' ): Promise { - let commentForm: CommentForm = { + let form: CommentForm = { content, edit_id, auth: api.auth, }; - - let updateResponse: CommentResponse = await fetch(`${apiUrl(api)}/comment`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(commentForm), - }).then(d => d.json()); - return updateResponse; + return api.client.editComment(form); } export async function deleteComment( @@ -412,23 +296,12 @@ export async function deleteComment( deleted: boolean, edit_id: number ): Promise { - let deleteCommentForm: DeleteCommentForm = { + let form: DeleteCommentForm = { edit_id, deleted, auth: api.auth, }; - - let deleteCommentRes: CommentResponse = await fetch( - `${apiUrl(api)}/comment/delete`, - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(deleteCommentForm), - } - ).then(d => d.json()); - return deleteCommentRes; + return api.client.deleteComment(form); } export async function removeComment( @@ -436,33 +309,21 @@ export async function removeComment( removed: boolean, edit_id: number ): Promise { - let removeCommentForm: RemoveCommentForm = { + let form: RemoveCommentForm = { edit_id, removed, auth: api.auth, }; - - let removeCommentRes: CommentResponse = await fetch( - `${apiUrl(api)}/comment/remove`, - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(removeCommentForm), - } - ).then(d => d.json()); - return removeCommentRes; + return api.client.removeComment(form); } export async function getMentions(api: API): Promise { - let getMentionUrl = `${apiUrl( - api - )}/user/mention?sort=New&unread_only=false&auth=${api.auth}`; - let getMentionsRes: GetUserMentionsResponse = await fetch(getMentionUrl, { - method: 'GET', - }).then(d => d.json()); - return getMentionsRes; + let form: GetUserMentionsForm = { + sort: SortType.New, + unread_only: false, + auth: api.auth, + }; + return api.client.getUserMentions(form); } export async function likeComment( @@ -470,48 +331,26 @@ export async function likeComment( score: number, comment: Comment ): Promise { - let likeCommentForm: CommentLikeForm = { + let form: CommentLikeForm = { comment_id: comment.id, score, auth: api.auth, }; - - let likeCommentRes: CommentResponse = await fetch( - `${apiUrl(api)}/comment/like`, - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(likeCommentForm), - } - ).then(d => d.json()); - return likeCommentRes; + return api.client.likeComment(form); } export async function createCommunity( api: API, name_: string = randomString(5) ): Promise { - let communityForm: CommunityForm = { + let form: CommunityForm = { name: name_, title: name_, category_id: 1, nsfw: false, auth: api.auth, }; - - let createCommunityRes: CommunityResponse = await fetch( - `${apiUrl(api)}/community`, - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(communityForm), - } - ).then(d => d.json()); - return createCommunityRes; + return api.client.createCommunity(form); } export async function deleteCommunity( @@ -519,23 +358,12 @@ export async function deleteCommunity( deleted: boolean, edit_id: number ): Promise { - let deleteCommunityForm: DeleteCommunityForm = { + let form: DeleteCommunityForm = { edit_id, deleted, auth: api.auth, }; - - let deleteResponse: CommunityResponse = await fetch( - `${apiUrl(api)}/community/delete`, - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(deleteCommunityForm), - } - ).then(d => d.json()); - return deleteResponse; + return api.client.deleteCommunity(form); } export async function removeCommunity( @@ -543,23 +371,12 @@ export async function removeCommunity( removed: boolean, edit_id: number ): Promise { - let removeCommunityForm: RemoveCommunityForm = { + let form: RemoveCommunityForm = { edit_id, removed, auth: api.auth, }; - - let removeResponse: CommunityResponse = await fetch( - `${apiUrl(api)}/community/remove`, - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(removeCommunityForm), - } - ).then(d => d.json()); - return removeResponse; + return api.client.removeCommunity(form); } export async function createPrivateMessage( @@ -567,23 +384,12 @@ export async function createPrivateMessage( recipient_id: number ): Promise { let content = 'A jest test federated private message'; - let privateMessageForm: PrivateMessageForm = { + let form: PrivateMessageForm = { content, recipient_id, auth: api.auth, }; - - let createRes: PrivateMessageResponse = await fetch( - `${apiUrl(api)}/private_message`, - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(privateMessageForm), - } - ).then(d => d.json()); - return createRes; + return api.client.createPrivateMessage(form); } export async function updatePrivateMessage( @@ -591,23 +397,12 @@ export async function updatePrivateMessage( edit_id: number ): Promise { let updatedContent = 'A jest test federated private message edited'; - let updatePrivateMessageForm: EditPrivateMessageForm = { + let form: EditPrivateMessageForm = { content: updatedContent, edit_id, auth: api.auth, }; - - let updateRes: PrivateMessageResponse = await fetch( - `${apiUrl(api)}/private_message`, - { - method: 'PUT', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(updatePrivateMessageForm), - } - ).then(d => d.json()); - return updateRes; + return api.client.editPrivateMessage(form); } export async function deletePrivateMessage( @@ -615,50 +410,26 @@ export async function deletePrivateMessage( deleted: boolean, edit_id: number ): Promise { - let deletePrivateMessageForm: DeletePrivateMessageForm = { + let form: DeletePrivateMessageForm = { deleted, edit_id, auth: api.auth, }; - - let deleteRes: PrivateMessageResponse = await fetch( - `${apiUrl(api)}/private_message/delete`, - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(deletePrivateMessageForm), - } - ).then(d => d.json()); - - return deleteRes; + return api.client.deletePrivateMessage(form); } export async function registerUser( api: API, username: string = randomString(5) ): Promise { - let registerForm: RegisterForm = { + let form: RegisterForm = { username, password: 'test', password_verify: 'test', admin: false, show_nsfw: true, }; - - let registerRes: Promise = fetch( - `${apiUrl(api)}/user/register`, - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(registerForm), - } - ).then(d => d.json()); - - return registerRes; + return api.client.register(form); } export async function saveUserSettingsBio( @@ -676,46 +447,28 @@ export async function saveUserSettingsBio( bio: 'a changed bio', auth, }; - - let res: Promise = fetch( - `${apiUrl(api)}/user/save_user_settings`, - { - method: 'PUT', - headers: { - 'Content-Type': 'application/json', - }, - body: wrapper(form), - } - ).then(d => d.json()); - return res; + return api.client.saveUserSettings(form); } export async function getSite( api: API, auth: string ): Promise { - let siteUrl = `${apiUrl(api)}/site?auth=${auth}`; - - let res: GetSiteResponse = await fetch(siteUrl, { - method: 'GET', - }).then(d => d.json()); - return res; + let form: GetSiteForm = { + auth, + }; + return api.client.getSite(form); } export async function listPrivateMessages( api: API ): Promise { - let getPrivateMessagesUrl = `${apiUrl(api)}/private_message/list?auth=${ - api.auth - }&unread_only=false&limit=999`; - - let getPrivateMessagesRes: PrivateMessagesResponse = await fetch( - getPrivateMessagesUrl, - { - method: 'GET', - } - ).then(d => d.json()); - return getPrivateMessagesRes; + let form: GetPrivateMessagesForm = { + auth: api.auth, + unread_only: false, + limit: 999, + }; + return api.client.getPrivateMessages(form); } export async function unfollowRemotes( diff --git a/ui/src/services/WebSocketService.ts b/ui/src/services/WebSocketService.ts index 59e842979..93587c990 100644 --- a/ui/src/services/WebSocketService.ts +++ b/ui/src/services/WebSocketService.ts @@ -1,63 +1,6 @@ import { wsUri } from '../env'; import { - wsSendSearch, - wsSendGetPost, - wsSendBanUser, - wsSendGetSite, - wsSendUserJoin, - wsSendRegister, - wsSendLogin, - wsSendGetPosts, - wsSendLikePost, - wsSendEditPost, - wsSendLockPost, - wsSendSavePost, - wsSendAddAdmin, - wsSendEditSite, - wsSendGetModlog, - wsSendGetCaptcha, - wsSendCreatePost, - wsSendDeletePost, - wsSendRemovePost, - wsSendStickyPost, - wsSendGetReplies, - wsSendCreateSite, - wsSendEditComment, - wsSendLikeComment, - wsSendSaveComment, - wsSendGetComments, - wsSendGetCommunity, - wsSendTransferSite, - wsSendEditCommunity, - wsSendCreateComment, - wsSendDeleteComment, - wsSendRemoveComment, - wsSendGetSiteConfig, - wsSendMarkAllAsRead, - wsSendDeleteAccount, - wsSendPasswordReset, - wsSendPasswordChange, - wsSendListCategories, - wsSendGetUserDetails, - wsSendGetUserMentions, - wsSendSaveSiteConfig, - wsSendDeleteCommunity, - wsSendCreateCommunity, - wsSendRemoveCommunity, - wsSendFollowCommunity, - wsSendListCommunities, - wsSendBanFromCommunity, - wsSendSaveUserSettings, - wsSendMarkCommentAsRead, - wsSendGetFollowedCommunities, - wsSendAddModToCommunity, - wsSendTransferCommunity, - wsSendMarkUserMentionAsRead, - wsSendDeletePrivateMessage, - wsSendEditPrivateMessage, - wsSendGetPrivateMessages, - wsSendCreatePrivateMessage, - wsSendMarkPrivateMessageAsRead, + LemmyWebsocket, LoginForm, RegisterForm, CommunityForm, @@ -110,6 +53,7 @@ import { GetSiteConfig, GetSiteForm, SiteConfigForm, + MarkAllAsReadForm, WebSocketJsonResponse, } from 'lemmy-js-client'; import { UserService } from './'; @@ -126,6 +70,7 @@ export class WebSocketService { public admins: Array; public banned: Array; + private client = new LemmyWebsocket(); private constructor() { this.ws = new ReconnectingWebSocket(wsUri); @@ -156,287 +101,287 @@ export class WebSocketService { public userJoin() { let form: UserJoinForm = { auth: UserService.Instance.auth }; - this.ws.send(wsSendUserJoin(form)); + this.ws.send(this.client.userJoin(form)); } public login(form: LoginForm) { - this.ws.send(wsSendLogin(form)); + this.ws.send(this.client.login(form)); } public register(form: RegisterForm) { - this.ws.send(wsSendRegister(form)); + this.ws.send(this.client.register(form)); } public getCaptcha() { - this.ws.send(wsSendGetCaptcha()); + this.ws.send(this.client.getCaptcha()); } public createCommunity(form: CommunityForm) { this.setAuth(form); // TODO all these setauths at some point would be good to make required - this.ws.send(wsSendCreateCommunity(form)); + this.ws.send(this.client.createCommunity(form)); } public editCommunity(form: CommunityForm) { this.setAuth(form); - this.ws.send(wsSendEditCommunity(form)); + this.ws.send(this.client.editCommunity(form)); } public deleteCommunity(form: DeleteCommunityForm) { this.setAuth(form); - this.ws.send(wsSendDeleteCommunity(form)); + this.ws.send(this.client.deleteCommunity(form)); } public removeCommunity(form: RemoveCommunityForm) { this.setAuth(form); - this.ws.send(wsSendRemoveCommunity(form)); + this.ws.send(this.client.removeCommunity(form)); } public followCommunity(form: FollowCommunityForm) { this.setAuth(form); - this.ws.send(wsSendFollowCommunity(form)); + this.ws.send(this.client.followCommunity(form)); } public listCommunities(form: ListCommunitiesForm) { this.setAuth(form, false); - this.ws.send(wsSendListCommunities(form)); + this.ws.send(this.client.listCommunities(form)); } public getFollowedCommunities() { let form: GetFollowedCommunitiesForm = { auth: UserService.Instance.auth }; - this.ws.send(wsSendGetFollowedCommunities(form)); + this.ws.send(this.client.getFollowedCommunities(form)); } public listCategories() { - this.ws.send(wsSendListCategories()); + this.ws.send(this.client.listCategories()); } public createPost(form: PostForm) { this.setAuth(form); - this.ws.send(wsSendCreatePost(form)); + this.ws.send(this.client.createPost(form)); } public getPost(form: GetPostForm) { this.setAuth(form, false); - this.ws.send(wsSendGetPost(form)); + this.ws.send(this.client.getPost(form)); } public getCommunity(form: GetCommunityForm) { this.setAuth(form, false); - this.ws.send(wsSendGetCommunity(form)); + this.ws.send(this.client.getCommunity(form)); } public createComment(form: CommentForm) { this.setAuth(form); - this.ws.send(wsSendCreateComment(form)); + this.ws.send(this.client.createComment(form)); } public editComment(form: CommentForm) { this.setAuth(form); - this.ws.send(wsSendEditComment(form)); + this.ws.send(this.client.editComment(form)); } public deleteComment(form: DeleteCommentForm) { this.setAuth(form); - this.ws.send(wsSendDeleteComment(form)); + this.ws.send(this.client.deleteComment(form)); } public removeComment(form: RemoveCommentForm) { this.setAuth(form); - this.ws.send(wsSendRemoveComment(form)); + this.ws.send(this.client.removeComment(form)); } public markCommentAsRead(form: MarkCommentAsReadForm) { this.setAuth(form); - this.ws.send(wsSendMarkCommentAsRead(form)); + this.ws.send(this.client.markCommentAsRead(form)); } public likeComment(form: CommentLikeForm) { this.setAuth(form); - this.ws.send(wsSendLikeComment(form)); + this.ws.send(this.client.likeComment(form)); } public saveComment(form: SaveCommentForm) { this.setAuth(form); - this.ws.send(wsSendSaveComment(form)); + this.ws.send(this.client.saveComment(form)); } public getPosts(form: GetPostsForm) { this.setAuth(form, false); - this.ws.send(wsSendGetPosts(form)); + this.ws.send(this.client.getPosts(form)); } public getComments(form: GetCommentsForm) { this.setAuth(form, false); - this.ws.send(wsSendGetComments(form)); + this.ws.send(this.client.getComments(form)); } public likePost(form: CreatePostLikeForm) { this.setAuth(form); - this.ws.send(wsSendLikePost(form)); + this.ws.send(this.client.likePost(form)); } public editPost(form: PostForm) { this.setAuth(form); - this.ws.send(wsSendEditPost(form)); + this.ws.send(this.client.editPost(form)); } public deletePost(form: DeletePostForm) { this.setAuth(form); - this.ws.send(wsSendDeletePost(form)); + this.ws.send(this.client.deletePost(form)); } public removePost(form: RemovePostForm) { this.setAuth(form); - this.ws.send(wsSendRemovePost(form)); + this.ws.send(this.client.removePost(form)); } public lockPost(form: LockPostForm) { this.setAuth(form); - this.ws.send(wsSendLockPost(form)); + this.ws.send(this.client.lockPost(form)); } public stickyPost(form: StickyPostForm) { this.setAuth(form); - this.ws.send(wsSendStickyPost(form)); + this.ws.send(this.client.stickyPost(form)); } public savePost(form: SavePostForm) { this.setAuth(form); - this.ws.send(wsSendSavePost(form)); + this.ws.send(this.client.savePost(form)); } public banFromCommunity(form: BanFromCommunityForm) { this.setAuth(form); - this.ws.send(wsSendBanFromCommunity(form)); + this.ws.send(this.client.banFromCommunity(form)); } public addModToCommunity(form: AddModToCommunityForm) { this.setAuth(form); - this.ws.send(wsSendAddModToCommunity(form)); + this.ws.send(this.client.addModToCommunity(form)); } public transferCommunity(form: TransferCommunityForm) { this.setAuth(form); - this.ws.send(wsSendTransferCommunity(form)); + this.ws.send(this.client.transferCommunity(form)); } public transferSite(form: TransferSiteForm) { this.setAuth(form); - this.ws.send(wsSendTransferSite(form)); + this.ws.send(this.client.transferSite(form)); } public banUser(form: BanUserForm) { this.setAuth(form); - this.ws.send(wsSendBanUser(form)); + this.ws.send(this.client.banUser(form)); } public addAdmin(form: AddAdminForm) { this.setAuth(form); - this.ws.send(wsSendAddAdmin(form)); + this.ws.send(this.client.addAdmin(form)); } public getUserDetails(form: GetUserDetailsForm) { this.setAuth(form, false); - this.ws.send(wsSendGetUserDetails(form)); + this.ws.send(this.client.getUserDetails(form)); } public getReplies(form: GetRepliesForm) { this.setAuth(form); - this.ws.send(wsSendGetReplies(form)); + this.ws.send(this.client.getReplies(form)); } public getUserMentions(form: GetUserMentionsForm) { this.setAuth(form); - this.ws.send(wsSendGetUserMentions(form)); + this.ws.send(this.client.getUserMentions(form)); } public markUserMentionAsRead(form: MarkUserMentionAsReadForm) { this.setAuth(form); - this.ws.send(wsSendMarkUserMentionAsRead(form)); + this.ws.send(this.client.markUserMentionAsRead(form)); } public getModlog(form: GetModlogForm) { - this.ws.send(wsSendGetModlog(form)); + this.ws.send(this.client.getModlog(form)); } public createSite(form: SiteForm) { this.setAuth(form); - this.ws.send(wsSendCreateSite(form)); + this.ws.send(this.client.createSite(form)); } public editSite(form: SiteForm) { this.setAuth(form); - this.ws.send(wsSendEditSite(form)); + this.ws.send(this.client.editSite(form)); } public getSite(form: GetSiteForm = {}) { this.setAuth(form, false); - this.ws.send(wsSendGetSite(form)); + this.ws.send(this.client.getSite(form)); } public getSiteConfig() { let form: GetSiteConfig = {}; this.setAuth(form); - this.ws.send(wsSendGetSiteConfig(form)); + this.ws.send(this.client.getSiteConfig(form)); } public search(form: SearchForm) { this.setAuth(form, false); - this.ws.send(wsSendSearch(form)); + this.ws.send(this.client.search(form)); } public markAllAsRead() { - let form = {}; + let form: MarkAllAsReadForm; this.setAuth(form); - this.ws.send(wsSendMarkAllAsRead(form)); + this.ws.send(this.client.markAllAsRead(form)); } public saveUserSettings(form: UserSettingsForm) { this.setAuth(form); - this.ws.send(wsSendSaveUserSettings(form)); + this.ws.send(this.client.saveUserSettings(form)); } public deleteAccount(form: DeleteAccountForm) { this.setAuth(form); - this.ws.send(wsSendDeleteAccount(form)); + this.ws.send(this.client.deleteAccount(form)); } public passwordReset(form: PasswordResetForm) { - this.ws.send(wsSendPasswordReset(form)); + this.ws.send(this.client.passwordReset(form)); } public passwordChange(form: PasswordChangeForm) { - this.ws.send(wsSendPasswordChange(form)); + this.ws.send(this.client.passwordChange(form)); } public createPrivateMessage(form: PrivateMessageForm) { this.setAuth(form); - this.ws.send(wsSendCreatePrivateMessage(form)); + this.ws.send(this.client.createPrivateMessage(form)); } public editPrivateMessage(form: EditPrivateMessageForm) { this.setAuth(form); - this.ws.send(wsSendEditPrivateMessage(form)); + this.ws.send(this.client.editPrivateMessage(form)); } public deletePrivateMessage(form: DeletePrivateMessageForm) { this.setAuth(form); - this.ws.send(wsSendDeletePrivateMessage(form)); + this.ws.send(this.client.deletePrivateMessage(form)); } public markPrivateMessageAsRead(form: MarkPrivateMessageAsReadForm) { this.setAuth(form); - this.ws.send(wsSendMarkPrivateMessageAsRead(form)); + this.ws.send(this.client.markPrivateMessageAsRead(form)); } public getPrivateMessages(form: GetPrivateMessagesForm) { this.setAuth(form); - this.ws.send(wsSendGetPrivateMessages(form)); + this.ws.send(this.client.getPrivateMessages(form)); } public saveSiteConfig(form: SiteConfigForm) { this.setAuth(form); - this.ws.send(wsSendSaveSiteConfig(form)); + this.ws.send(this.client.saveSiteConfig(form)); } private setAuth(obj: any, throwErr: boolean = true) { diff --git a/ui/yarn.lock b/ui/yarn.lock index 285f815b8..a474636ed 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -4938,10 +4938,10 @@ lego-api@^1.0.7: dependencies: chain-able "^3.0.0" -lemmy-js-client@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.2.tgz#6345a40ebc9218d4ad9a32cdbafdd29140e3768a" - integrity sha512-m4ZayBvyOF/v7M+MzPNROtrc54OHAL9+7qtxkF0lbsiGwx2vDcPDCd1Nw/tg+i3qheCvldYAdIGP4tD/zwiMgg== +lemmy-js-client@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.8.tgz#98e34c8e3cd07427f883f60fad376dc4d6f46e7f" + integrity sha512-YZxD3+8RGz7cRKdI8EIe5iQqQIMm5WzdNz6zZ7/CdkMtXUv6YuMOEv8HLTvBoGuaWIJwlMJ+23NIarxlT26IEw== leven@^3.1.0: version "3.1.0"