mirror of
https://github.com/LemmyNet/lemmy-js-client.git
synced 2024-12-23 03:11:26 +00:00
Adding an HTTP client. Cleaning up Websocket client.
This commit is contained in:
parent
942a8ec01a
commit
18d5ed8414
7 changed files with 702 additions and 305 deletions
15
README.md
15
README.md
|
@ -21,17 +21,20 @@ Check out the [Lemmy HTTP / websocket API](https://dev.lemmy.ml/docs/contributin
|
||||||
### Websocket
|
### Websocket
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Set up a websocket connection
|
import { LoginForm, LemmyWebsocket } from 'lemmy-js-client';
|
||||||
import { LoginForm, wsSendLogin } from 'lemmy-js-client';
|
|
||||||
|
|
||||||
public login(form: LoginForm) {
|
let client: LemmyWebsocket = new LemmyWebsocket();
|
||||||
this.ws.send(wsSendLogin(form));
|
this.ws.send(client.login(form));
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### HTTP
|
### HTTP
|
||||||
|
|
||||||
TODO
|
```js
|
||||||
|
import { LemmyHttp } from 'lemmy-js-client';
|
||||||
|
|
||||||
|
let client: LemmyHttp = new LemmyHttp(baseUrl);
|
||||||
|
let jwt = await client.httpLogin(loginForm).jwt;
|
||||||
|
```
|
||||||
|
|
||||||
## Support / Donate
|
## Support / Donate
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "lemmy-js-client",
|
"name": "lemmy-js-client",
|
||||||
"description": "A javascript / typescript client for Lemmy",
|
"description": "A javascript / typescript client for Lemmy",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"author": "Dessalines <tyhou13@gmx.com>",
|
"author": "Dessalines <tyhou13@gmx.com>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
|
|
387
src/http.ts
Normal file
387
src/http.ts
Normal file
|
@ -0,0 +1,387 @@
|
||||||
|
import {
|
||||||
|
MessageType,
|
||||||
|
LoginForm,
|
||||||
|
RegisterForm,
|
||||||
|
CommunityForm,
|
||||||
|
DeleteCommunityForm,
|
||||||
|
RemoveCommunityForm,
|
||||||
|
PostForm,
|
||||||
|
DeletePostForm,
|
||||||
|
RemovePostForm,
|
||||||
|
LockPostForm,
|
||||||
|
StickyPostForm,
|
||||||
|
SavePostForm,
|
||||||
|
CommentForm,
|
||||||
|
DeleteCommentForm,
|
||||||
|
RemoveCommentForm,
|
||||||
|
MarkCommentAsReadForm,
|
||||||
|
SaveCommentForm,
|
||||||
|
CommentLikeForm,
|
||||||
|
GetPostForm,
|
||||||
|
GetPostsForm,
|
||||||
|
CreatePostLikeForm,
|
||||||
|
GetCommunityForm,
|
||||||
|
FollowCommunityForm,
|
||||||
|
GetFollowedCommunitiesForm,
|
||||||
|
GetUserDetailsForm,
|
||||||
|
ListCommunitiesForm,
|
||||||
|
GetModlogForm,
|
||||||
|
BanFromCommunityForm,
|
||||||
|
AddModToCommunityForm,
|
||||||
|
TransferCommunityForm,
|
||||||
|
AddAdminForm,
|
||||||
|
TransferSiteForm,
|
||||||
|
BanUserForm,
|
||||||
|
SiteForm,
|
||||||
|
GetRepliesForm,
|
||||||
|
GetUserMentionsForm,
|
||||||
|
MarkUserMentionAsReadForm,
|
||||||
|
SearchForm,
|
||||||
|
UserSettingsForm,
|
||||||
|
DeleteAccountForm,
|
||||||
|
PasswordResetForm,
|
||||||
|
PasswordChangeForm,
|
||||||
|
PrivateMessageForm,
|
||||||
|
EditPrivateMessageForm,
|
||||||
|
DeletePrivateMessageForm,
|
||||||
|
MarkPrivateMessageAsReadForm,
|
||||||
|
GetPrivateMessagesForm,
|
||||||
|
GetCommentsForm,
|
||||||
|
UserJoinForm,
|
||||||
|
GetSiteConfig,
|
||||||
|
GetSiteForm,
|
||||||
|
SiteConfigForm,
|
||||||
|
MarkAllAsReadForm,
|
||||||
|
GetSiteResponse,
|
||||||
|
GetSiteConfigResponse,
|
||||||
|
SiteResponse,
|
||||||
|
LoginResponse,
|
||||||
|
ListCategoriesResponse,
|
||||||
|
GetModlogResponse,
|
||||||
|
SearchResponse,
|
||||||
|
PostResponse,
|
||||||
|
CommentResponse,
|
||||||
|
CommunityResponse,
|
||||||
|
GetRepliesResponse,
|
||||||
|
BanUserResponse,
|
||||||
|
GetPostResponse,
|
||||||
|
AddAdminResponse,
|
||||||
|
GetPostsResponse,
|
||||||
|
UserJoinResponse,
|
||||||
|
GetCaptchaResponse,
|
||||||
|
GetCommentsResponse,
|
||||||
|
UserDetailsResponse,
|
||||||
|
UserMentionResponse,
|
||||||
|
GetUserMentionsResponse,
|
||||||
|
GetCommunityResponse,
|
||||||
|
PrivateMessageResponse,
|
||||||
|
ListCommunitiesResponse,
|
||||||
|
PrivateMessagesResponse,
|
||||||
|
BanFromCommunityResponse,
|
||||||
|
AddModToCommunityResponse,
|
||||||
|
GetFollowedCommunitiesResponse,
|
||||||
|
PasswordResetResponse,
|
||||||
|
} from './interfaces';
|
||||||
|
|
||||||
|
enum HttpType {
|
||||||
|
Get = 'GET',
|
||||||
|
Post = 'POST',
|
||||||
|
Put = 'PUT',
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LemmyHttp {
|
||||||
|
private baseUrl: string;
|
||||||
|
|
||||||
|
constructor(baseUrl: string) {
|
||||||
|
this.baseUrl = baseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getSite(form: GetSiteForm): Promise<GetSiteResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/site', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async createSite(form: SiteForm): Promise<SiteResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/site', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async editSite(form: SiteForm): Promise<SiteResponse> {
|
||||||
|
return this.wrapper(HttpType.Put, '/site', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async transferSite(form: TransferSiteForm): Promise<GetSiteResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/site/transfer', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getSiteConfig(form: GetSiteConfig): Promise<GetSiteConfigResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/site/config', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveSiteConfig(form: SiteConfigForm): Promise<GetSiteConfigResponse> {
|
||||||
|
return this.wrapper(HttpType.Put, '/site/config', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async listCategories(): Promise<ListCategoriesResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/categories', {});
|
||||||
|
}
|
||||||
|
|
||||||
|
async getModlog(form: GetModlogForm): Promise<GetModlogResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/modlog', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async search(form: SearchForm): Promise<SearchResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/search', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async createCommunity(form: CommunityForm): Promise<CommunityResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/community', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getCommunity(form: GetCommunityForm): Promise<GetCommunityResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/community', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async editCommunity(form: CommunityForm): Promise<CommunityResponse> {
|
||||||
|
return this.wrapper(HttpType.Put, '/community', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async listCommunities(
|
||||||
|
form: ListCommunitiesForm
|
||||||
|
): Promise<ListCommunitiesResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/community/list', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async followCommunity(form: FollowCommunityForm): Promise<CommunityResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/community/follow', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteCommunity(form: DeleteCommunityForm): Promise<CommunityResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/community/delete', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeCommunity(form: RemoveCommunityForm): Promise<CommunityResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/community/remove', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async transferCommunity(
|
||||||
|
form: TransferCommunityForm
|
||||||
|
): Promise<GetCommunityResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/community/transfer', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async banFromCommunity(
|
||||||
|
form: BanFromCommunityForm
|
||||||
|
): Promise<BanFromCommunityResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/community/ban_user', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async addModToCommunity(
|
||||||
|
form: AddModToCommunityForm
|
||||||
|
): Promise<AddModToCommunityResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/community/mod', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async createPost(form: PostForm): Promise<PostResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/post', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPost(form: GetPostForm): Promise<GetPostResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/post', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async editPost(form: PostForm): Promise<PostResponse> {
|
||||||
|
return this.wrapper(HttpType.Put, '/post', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async deletePost(form: DeletePostForm): Promise<PostResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/post/delete', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async removePost(form: RemovePostForm): Promise<PostResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/post/remove', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async lockPost(form: LockPostForm): Promise<PostResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/post/lock', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async stickyPost(form: StickyPostForm): Promise<PostResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/post/sticky', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPosts(form: GetPostsForm): Promise<GetPostsResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/post/list', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async likePost(form: CreatePostLikeForm): Promise<PostResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/post/like', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async savePost(form: SavePostForm): Promise<PostResponse> {
|
||||||
|
return this.wrapper(HttpType.Put, '/post/save', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async createComment(form: CommentForm): Promise<CommentResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/comment', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async editComment(form: CommentForm): Promise<CommentResponse> {
|
||||||
|
return this.wrapper(HttpType.Put, '/comment', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteComment(form: DeleteCommentForm): Promise<CommentResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/comment/delete', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeComment(form: RemoveCommentForm): Promise<CommentResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/comment/remove', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async markCommentAsRead(
|
||||||
|
form: MarkCommentAsReadForm
|
||||||
|
): Promise<CommentResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/comment/mark_as_read', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async likeComment(form: CommentLikeForm): Promise<CommentResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/comment/like', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveComment(form: SaveCommentForm): Promise<CommentResponse> {
|
||||||
|
return this.wrapper(HttpType.Put, '/comment/save', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getComments(form: GetCommentsForm): Promise<GetCommentsResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/comment/list', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPrivateMessages(
|
||||||
|
form: GetPrivateMessagesForm
|
||||||
|
): Promise<PrivateMessagesResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/private_message/list', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async createPrivateMessage(
|
||||||
|
form: PrivateMessageForm
|
||||||
|
): Promise<PrivateMessageResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/private_message', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async editPrivateMessage(
|
||||||
|
form: EditPrivateMessageForm
|
||||||
|
): Promise<PrivateMessageResponse> {
|
||||||
|
return this.wrapper(HttpType.Put, '/private_message', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async deletePrivateMessage(
|
||||||
|
form: DeletePrivateMessageForm
|
||||||
|
): Promise<PrivateMessageResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/private_message/delete', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async markPrivateMessageAsRead(
|
||||||
|
form: MarkPrivateMessageAsReadForm
|
||||||
|
): Promise<PrivateMessageResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/private_message/mark_as_read', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async register(form: RegisterForm): Promise<LoginResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/user/register', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async login(form: LoginForm): Promise<LoginResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/user/login', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getUserDetails(form: GetUserDetailsForm): Promise<UserDetailsResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/user', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getUserMentions(
|
||||||
|
form: GetUserMentionsForm
|
||||||
|
): Promise<GetUserMentionsResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/user/mention', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async markUserMentionAsRead(
|
||||||
|
form: MarkUserMentionAsReadForm
|
||||||
|
): Promise<UserMentionResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/user/mention/mark_as_read', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getReplies(form: GetRepliesForm): Promise<GetRepliesResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/user/replies', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getFollowedCommunities(
|
||||||
|
form: GetFollowedCommunitiesForm
|
||||||
|
): Promise<GetFollowedCommunitiesResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/user/followed_communities', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async userJoin(form: UserJoinForm): Promise<UserJoinResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/user/join', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async banUser(form: BanUserForm): Promise<BanUserResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/user/ban', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getCaptcha(): Promise<GetCaptchaResponse> {
|
||||||
|
return this.wrapper(HttpType.Get, '/user/get_captcha', {});
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteAccount(form: DeleteAccountForm): Promise<LoginResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/user/delete_account', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async passwordReset(form: PasswordResetForm): Promise<PasswordResetResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/user/password_reset', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async passwordChange(form: PasswordChangeForm): Promise<LoginResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/user/password_change', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async markAllAsRead(form: MarkAllAsReadForm): Promise<LoginResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/user/mark_all_as_read', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveUserSettings(form: UserSettingsForm): Promise<LoginResponse> {
|
||||||
|
return this.wrapper(HttpType.Put, '/user/save_user_settings', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
async addAdmin(form: AddAdminForm): Promise<AddAdminResponse> {
|
||||||
|
return this.wrapper(HttpType.Post, '/admin/add', form);
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildFullUrl(endpoint: string): string {
|
||||||
|
return `${this.baseUrl}${endpoint}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async wrapper<Res>(
|
||||||
|
type_: HttpType,
|
||||||
|
endpoint: string,
|
||||||
|
form: MessageType
|
||||||
|
): Promise<Res> {
|
||||||
|
if (type_ == HttpType.Get) {
|
||||||
|
let getUrl = `${endpoint}?${encodeGetParams(form)}`;
|
||||||
|
return fetch(getUrl, {
|
||||||
|
method: 'GET',
|
||||||
|
}).then(d => d.json());
|
||||||
|
} else {
|
||||||
|
return fetch(this.buildFullUrl(endpoint), {
|
||||||
|
method: type_,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(form),
|
||||||
|
}).then(d => d.json());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function encodeGetParams(p: any): string {
|
||||||
|
return Object.entries(p)
|
||||||
|
.map(kv => kv.map(encodeURIComponent).join('='))
|
||||||
|
.join('&');
|
||||||
|
}
|
|
@ -1,2 +1,3 @@
|
||||||
export * from './interfaces';
|
export * from './interfaces';
|
||||||
export * from './utils';
|
export * from './websocket';
|
||||||
|
export * from './http';
|
||||||
|
|
|
@ -898,8 +898,11 @@ export interface PasswordResetForm {
|
||||||
email: string;
|
email: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// export interface PasswordResetResponse {
|
export interface PasswordResetResponse {}
|
||||||
// }
|
|
||||||
|
export interface MarkAllAsReadForm {
|
||||||
|
auth: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface PasswordChangeForm {
|
export interface PasswordChangeForm {
|
||||||
token: string;
|
token: string;
|
||||||
|
|
295
src/utils.ts
295
src/utils.ts
|
@ -1,295 +0,0 @@
|
||||||
import {
|
|
||||||
MessageType,
|
|
||||||
LoginForm,
|
|
||||||
RegisterForm,
|
|
||||||
UserOperation,
|
|
||||||
CommunityForm,
|
|
||||||
DeleteCommunityForm,
|
|
||||||
RemoveCommunityForm,
|
|
||||||
PostForm,
|
|
||||||
DeletePostForm,
|
|
||||||
RemovePostForm,
|
|
||||||
LockPostForm,
|
|
||||||
StickyPostForm,
|
|
||||||
SavePostForm,
|
|
||||||
CommentForm,
|
|
||||||
DeleteCommentForm,
|
|
||||||
RemoveCommentForm,
|
|
||||||
MarkCommentAsReadForm,
|
|
||||||
SaveCommentForm,
|
|
||||||
CommentLikeForm,
|
|
||||||
GetPostForm,
|
|
||||||
GetPostsForm,
|
|
||||||
CreatePostLikeForm,
|
|
||||||
GetCommunityForm,
|
|
||||||
FollowCommunityForm,
|
|
||||||
GetFollowedCommunitiesForm,
|
|
||||||
GetUserDetailsForm,
|
|
||||||
ListCommunitiesForm,
|
|
||||||
GetModlogForm,
|
|
||||||
BanFromCommunityForm,
|
|
||||||
AddModToCommunityForm,
|
|
||||||
TransferCommunityForm,
|
|
||||||
AddAdminForm,
|
|
||||||
TransferSiteForm,
|
|
||||||
BanUserForm,
|
|
||||||
SiteForm,
|
|
||||||
GetRepliesForm,
|
|
||||||
GetUserMentionsForm,
|
|
||||||
MarkUserMentionAsReadForm,
|
|
||||||
SearchForm,
|
|
||||||
UserSettingsForm,
|
|
||||||
DeleteAccountForm,
|
|
||||||
PasswordResetForm,
|
|
||||||
PasswordChangeForm,
|
|
||||||
PrivateMessageForm,
|
|
||||||
EditPrivateMessageForm,
|
|
||||||
DeletePrivateMessageForm,
|
|
||||||
MarkPrivateMessageAsReadForm,
|
|
||||||
GetPrivateMessagesForm,
|
|
||||||
GetCommentsForm,
|
|
||||||
UserJoinForm,
|
|
||||||
GetSiteConfig,
|
|
||||||
GetSiteForm,
|
|
||||||
SiteConfigForm,
|
|
||||||
} from './interfaces';
|
|
||||||
|
|
||||||
export function wsSendLogin(form: LoginForm): string {
|
|
||||||
return wsSendWrapper(UserOperation.Login, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendUserJoin(form: UserJoinForm): string {
|
|
||||||
return wsSendWrapper(UserOperation.UserJoin, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendRegister(registerForm: RegisterForm) {
|
|
||||||
return wsSendWrapper(UserOperation.Register, registerForm);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendGetCaptcha() {
|
|
||||||
return wsSendWrapper(UserOperation.GetCaptcha, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendCreateCommunity(form: CommunityForm) {
|
|
||||||
return wsSendWrapper(UserOperation.CreateCommunity, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendEditCommunity(form: CommunityForm) {
|
|
||||||
return wsSendWrapper(UserOperation.EditCommunity, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendDeleteCommunity(form: DeleteCommunityForm) {
|
|
||||||
return wsSendWrapper(UserOperation.DeleteCommunity, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendRemoveCommunity(form: RemoveCommunityForm) {
|
|
||||||
return wsSendWrapper(UserOperation.RemoveCommunity, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendFollowCommunity(form: FollowCommunityForm) {
|
|
||||||
return wsSendWrapper(UserOperation.FollowCommunity, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendListCommunities(form: ListCommunitiesForm) {
|
|
||||||
return wsSendWrapper(UserOperation.ListCommunities, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendGetFollowedCommunities(form: GetFollowedCommunitiesForm) {
|
|
||||||
return wsSendWrapper(UserOperation.GetFollowedCommunities, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendListCategories() {
|
|
||||||
return wsSendWrapper(UserOperation.ListCategories, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendCreatePost(form: PostForm) {
|
|
||||||
return wsSendWrapper(UserOperation.CreatePost, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendGetPost(form: GetPostForm) {
|
|
||||||
return wsSendWrapper(UserOperation.GetPost, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendGetCommunity(form: GetCommunityForm) {
|
|
||||||
return wsSendWrapper(UserOperation.GetCommunity, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendCreateComment(form: CommentForm) {
|
|
||||||
return wsSendWrapper(UserOperation.CreateComment, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendEditComment(form: CommentForm) {
|
|
||||||
return wsSendWrapper(UserOperation.EditComment, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendDeleteComment(form: DeleteCommentForm) {
|
|
||||||
return wsSendWrapper(UserOperation.DeleteComment, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendRemoveComment(form: RemoveCommentForm) {
|
|
||||||
return wsSendWrapper(UserOperation.RemoveComment, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendMarkCommentAsRead(form: MarkCommentAsReadForm) {
|
|
||||||
return wsSendWrapper(UserOperation.MarkCommentAsRead, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendLikeComment(form: CommentLikeForm) {
|
|
||||||
return wsSendWrapper(UserOperation.CreateCommentLike, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendSaveComment(form: SaveCommentForm) {
|
|
||||||
return wsSendWrapper(UserOperation.SaveComment, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendGetPosts(form: GetPostsForm) {
|
|
||||||
return wsSendWrapper(UserOperation.GetPosts, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendGetComments(form: GetCommentsForm) {
|
|
||||||
return wsSendWrapper(UserOperation.GetComments, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendLikePost(form: CreatePostLikeForm) {
|
|
||||||
return wsSendWrapper(UserOperation.CreatePostLike, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendEditPost(form: PostForm) {
|
|
||||||
return wsSendWrapper(UserOperation.EditPost, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendDeletePost(form: DeletePostForm) {
|
|
||||||
return wsSendWrapper(UserOperation.DeletePost, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendRemovePost(form: RemovePostForm) {
|
|
||||||
return wsSendWrapper(UserOperation.RemovePost, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendLockPost(form: LockPostForm) {
|
|
||||||
return wsSendWrapper(UserOperation.LockPost, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendStickyPost(form: StickyPostForm) {
|
|
||||||
return wsSendWrapper(UserOperation.StickyPost, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendSavePost(form: SavePostForm) {
|
|
||||||
return wsSendWrapper(UserOperation.SavePost, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendBanFromCommunity(form: BanFromCommunityForm) {
|
|
||||||
return wsSendWrapper(UserOperation.BanFromCommunity, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendAddModToCommunity(form: AddModToCommunityForm) {
|
|
||||||
return wsSendWrapper(UserOperation.AddModToCommunity, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendTransferCommunity(form: TransferCommunityForm) {
|
|
||||||
return wsSendWrapper(UserOperation.TransferCommunity, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendTransferSite(form: TransferSiteForm) {
|
|
||||||
return wsSendWrapper(UserOperation.TransferSite, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendBanUser(form: BanUserForm) {
|
|
||||||
return wsSendWrapper(UserOperation.BanUser, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendAddAdmin(form: AddAdminForm) {
|
|
||||||
return wsSendWrapper(UserOperation.AddAdmin, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendGetUserDetails(form: GetUserDetailsForm) {
|
|
||||||
return wsSendWrapper(UserOperation.GetUserDetails, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendGetReplies(form: GetRepliesForm) {
|
|
||||||
return wsSendWrapper(UserOperation.GetReplies, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendGetUserMentions(form: GetUserMentionsForm) {
|
|
||||||
return wsSendWrapper(UserOperation.GetUserMentions, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendMarkUserMentionAsRead(form: MarkUserMentionAsReadForm) {
|
|
||||||
return wsSendWrapper(UserOperation.MarkUserMentionAsRead, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendGetModlog(form: GetModlogForm) {
|
|
||||||
return wsSendWrapper(UserOperation.GetModlog, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendCreateSite(form: SiteForm) {
|
|
||||||
return wsSendWrapper(UserOperation.CreateSite, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendEditSite(form: SiteForm) {
|
|
||||||
return wsSendWrapper(UserOperation.EditSite, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendGetSite(form: GetSiteForm = {}) {
|
|
||||||
return wsSendWrapper(UserOperation.GetSite, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendGetSiteConfig(form: GetSiteConfig) {
|
|
||||||
return wsSendWrapper(UserOperation.GetSiteConfig, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendSearch(form: SearchForm) {
|
|
||||||
return wsSendWrapper(UserOperation.Search, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendMarkAllAsRead(form: any) {
|
|
||||||
return wsSendWrapper(UserOperation.MarkAllAsRead, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendSaveUserSettings(form: UserSettingsForm) {
|
|
||||||
return wsSendWrapper(UserOperation.SaveUserSettings, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendDeleteAccount(form: DeleteAccountForm) {
|
|
||||||
return wsSendWrapper(UserOperation.DeleteAccount, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendPasswordReset(form: PasswordResetForm) {
|
|
||||||
return wsSendWrapper(UserOperation.PasswordReset, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendPasswordChange(form: PasswordChangeForm) {
|
|
||||||
return wsSendWrapper(UserOperation.PasswordChange, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendCreatePrivateMessage(form: PrivateMessageForm) {
|
|
||||||
return wsSendWrapper(UserOperation.CreatePrivateMessage, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendEditPrivateMessage(form: EditPrivateMessageForm) {
|
|
||||||
return wsSendWrapper(UserOperation.EditPrivateMessage, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendDeletePrivateMessage(form: DeletePrivateMessageForm) {
|
|
||||||
return wsSendWrapper(UserOperation.DeletePrivateMessage, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendMarkPrivateMessageAsRead(
|
|
||||||
form: MarkPrivateMessageAsReadForm
|
|
||||||
) {
|
|
||||||
return wsSendWrapper(UserOperation.MarkPrivateMessageAsRead, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendGetPrivateMessages(form: GetPrivateMessagesForm) {
|
|
||||||
return wsSendWrapper(UserOperation.GetPrivateMessages, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wsSendSaveSiteConfig(form: SiteConfigForm) {
|
|
||||||
return wsSendWrapper(UserOperation.SaveSiteConfig, form);
|
|
||||||
}
|
|
||||||
|
|
||||||
function wsSendWrapper(op: UserOperation, data: MessageType) {
|
|
||||||
let send = { op: UserOperation[op], data: data };
|
|
||||||
console.log(send);
|
|
||||||
return JSON.stringify(send);
|
|
||||||
}
|
|
298
src/websocket.ts
Normal file
298
src/websocket.ts
Normal file
|
@ -0,0 +1,298 @@
|
||||||
|
import {
|
||||||
|
MessageType,
|
||||||
|
LoginForm,
|
||||||
|
RegisterForm,
|
||||||
|
UserOperation,
|
||||||
|
CommunityForm,
|
||||||
|
DeleteCommunityForm,
|
||||||
|
RemoveCommunityForm,
|
||||||
|
PostForm,
|
||||||
|
DeletePostForm,
|
||||||
|
RemovePostForm,
|
||||||
|
LockPostForm,
|
||||||
|
StickyPostForm,
|
||||||
|
SavePostForm,
|
||||||
|
CommentForm,
|
||||||
|
DeleteCommentForm,
|
||||||
|
RemoveCommentForm,
|
||||||
|
MarkCommentAsReadForm,
|
||||||
|
SaveCommentForm,
|
||||||
|
CommentLikeForm,
|
||||||
|
GetPostForm,
|
||||||
|
GetPostsForm,
|
||||||
|
CreatePostLikeForm,
|
||||||
|
GetCommunityForm,
|
||||||
|
FollowCommunityForm,
|
||||||
|
GetFollowedCommunitiesForm,
|
||||||
|
GetUserDetailsForm,
|
||||||
|
ListCommunitiesForm,
|
||||||
|
GetModlogForm,
|
||||||
|
BanFromCommunityForm,
|
||||||
|
AddModToCommunityForm,
|
||||||
|
TransferCommunityForm,
|
||||||
|
AddAdminForm,
|
||||||
|
TransferSiteForm,
|
||||||
|
BanUserForm,
|
||||||
|
SiteForm,
|
||||||
|
GetRepliesForm,
|
||||||
|
GetUserMentionsForm,
|
||||||
|
MarkUserMentionAsReadForm,
|
||||||
|
SearchForm,
|
||||||
|
UserSettingsForm,
|
||||||
|
DeleteAccountForm,
|
||||||
|
PasswordResetForm,
|
||||||
|
PasswordChangeForm,
|
||||||
|
PrivateMessageForm,
|
||||||
|
EditPrivateMessageForm,
|
||||||
|
DeletePrivateMessageForm,
|
||||||
|
MarkPrivateMessageAsReadForm,
|
||||||
|
GetPrivateMessagesForm,
|
||||||
|
GetCommentsForm,
|
||||||
|
UserJoinForm,
|
||||||
|
GetSiteConfig,
|
||||||
|
GetSiteForm,
|
||||||
|
SiteConfigForm,
|
||||||
|
MarkAllAsReadForm,
|
||||||
|
} from './interfaces';
|
||||||
|
|
||||||
|
export class LemmyWebsocket {
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
login(form: LoginForm): string {
|
||||||
|
return wrapper(UserOperation.Login, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
userJoin(form: UserJoinForm): string {
|
||||||
|
return wrapper(UserOperation.UserJoin, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
register(registerForm: RegisterForm) {
|
||||||
|
return wrapper(UserOperation.Register, registerForm);
|
||||||
|
}
|
||||||
|
|
||||||
|
getCaptcha() {
|
||||||
|
return wrapper(UserOperation.GetCaptcha, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
createCommunity(form: CommunityForm) {
|
||||||
|
return wrapper(UserOperation.CreateCommunity, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
editCommunity(form: CommunityForm) {
|
||||||
|
return wrapper(UserOperation.EditCommunity, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteCommunity(form: DeleteCommunityForm) {
|
||||||
|
return wrapper(UserOperation.DeleteCommunity, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeCommunity(form: RemoveCommunityForm) {
|
||||||
|
return wrapper(UserOperation.RemoveCommunity, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
followCommunity(form: FollowCommunityForm) {
|
||||||
|
return wrapper(UserOperation.FollowCommunity, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
listCommunities(form: ListCommunitiesForm) {
|
||||||
|
return wrapper(UserOperation.ListCommunities, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
getFollowedCommunities(form: GetFollowedCommunitiesForm) {
|
||||||
|
return wrapper(UserOperation.GetFollowedCommunities, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
listCategories() {
|
||||||
|
return wrapper(UserOperation.ListCategories, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
createPost(form: PostForm) {
|
||||||
|
return wrapper(UserOperation.CreatePost, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
getPost(form: GetPostForm) {
|
||||||
|
return wrapper(UserOperation.GetPost, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
getCommunity(form: GetCommunityForm) {
|
||||||
|
return wrapper(UserOperation.GetCommunity, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
createComment(form: CommentForm) {
|
||||||
|
return wrapper(UserOperation.CreateComment, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
editComment(form: CommentForm) {
|
||||||
|
return wrapper(UserOperation.EditComment, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteComment(form: DeleteCommentForm) {
|
||||||
|
return wrapper(UserOperation.DeleteComment, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeComment(form: RemoveCommentForm) {
|
||||||
|
return wrapper(UserOperation.RemoveComment, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
markCommentAsRead(form: MarkCommentAsReadForm) {
|
||||||
|
return wrapper(UserOperation.MarkCommentAsRead, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
likeComment(form: CommentLikeForm) {
|
||||||
|
return wrapper(UserOperation.CreateCommentLike, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveComment(form: SaveCommentForm) {
|
||||||
|
return wrapper(UserOperation.SaveComment, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
getPosts(form: GetPostsForm) {
|
||||||
|
return wrapper(UserOperation.GetPosts, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
getComments(form: GetCommentsForm) {
|
||||||
|
return wrapper(UserOperation.GetComments, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
likePost(form: CreatePostLikeForm) {
|
||||||
|
return wrapper(UserOperation.CreatePostLike, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
editPost(form: PostForm) {
|
||||||
|
return wrapper(UserOperation.EditPost, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
deletePost(form: DeletePostForm) {
|
||||||
|
return wrapper(UserOperation.DeletePost, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
removePost(form: RemovePostForm) {
|
||||||
|
return wrapper(UserOperation.RemovePost, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
lockPost(form: LockPostForm) {
|
||||||
|
return wrapper(UserOperation.LockPost, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
stickyPost(form: StickyPostForm) {
|
||||||
|
return wrapper(UserOperation.StickyPost, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
savePost(form: SavePostForm) {
|
||||||
|
return wrapper(UserOperation.SavePost, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
banFromCommunity(form: BanFromCommunityForm) {
|
||||||
|
return wrapper(UserOperation.BanFromCommunity, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
addModToCommunity(form: AddModToCommunityForm) {
|
||||||
|
return wrapper(UserOperation.AddModToCommunity, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
transferCommunity(form: TransferCommunityForm) {
|
||||||
|
return wrapper(UserOperation.TransferCommunity, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
transferSite(form: TransferSiteForm) {
|
||||||
|
return wrapper(UserOperation.TransferSite, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
banUser(form: BanUserForm) {
|
||||||
|
return wrapper(UserOperation.BanUser, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
addAdmin(form: AddAdminForm) {
|
||||||
|
return wrapper(UserOperation.AddAdmin, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
getUserDetails(form: GetUserDetailsForm) {
|
||||||
|
return wrapper(UserOperation.GetUserDetails, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
getReplies(form: GetRepliesForm) {
|
||||||
|
return wrapper(UserOperation.GetReplies, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
getUserMentions(form: GetUserMentionsForm) {
|
||||||
|
return wrapper(UserOperation.GetUserMentions, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
markUserMentionAsRead(form: MarkUserMentionAsReadForm) {
|
||||||
|
return wrapper(UserOperation.MarkUserMentionAsRead, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
getModlog(form: GetModlogForm) {
|
||||||
|
return wrapper(UserOperation.GetModlog, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
createSite(form: SiteForm) {
|
||||||
|
return wrapper(UserOperation.CreateSite, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
editSite(form: SiteForm) {
|
||||||
|
return wrapper(UserOperation.EditSite, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
getSite(form: GetSiteForm = {}) {
|
||||||
|
return wrapper(UserOperation.GetSite, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
getSiteConfig(form: GetSiteConfig) {
|
||||||
|
return wrapper(UserOperation.GetSiteConfig, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
search(form: SearchForm) {
|
||||||
|
return wrapper(UserOperation.Search, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
markAllAsRead(form: MarkAllAsReadForm) {
|
||||||
|
return wrapper(UserOperation.MarkAllAsRead, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveUserSettings(form: UserSettingsForm) {
|
||||||
|
return wrapper(UserOperation.SaveUserSettings, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteAccount(form: DeleteAccountForm) {
|
||||||
|
return wrapper(UserOperation.DeleteAccount, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
passwordReset(form: PasswordResetForm) {
|
||||||
|
return wrapper(UserOperation.PasswordReset, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
passwordChange(form: PasswordChangeForm) {
|
||||||
|
return wrapper(UserOperation.PasswordChange, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
createPrivateMessage(form: PrivateMessageForm) {
|
||||||
|
return wrapper(UserOperation.CreatePrivateMessage, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
editPrivateMessage(form: EditPrivateMessageForm) {
|
||||||
|
return wrapper(UserOperation.EditPrivateMessage, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
deletePrivateMessage(form: DeletePrivateMessageForm) {
|
||||||
|
return wrapper(UserOperation.DeletePrivateMessage, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
markPrivateMessageAsRead(form: MarkPrivateMessageAsReadForm) {
|
||||||
|
return wrapper(UserOperation.MarkPrivateMessageAsRead, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
getPrivateMessages(form: GetPrivateMessagesForm) {
|
||||||
|
return wrapper(UserOperation.GetPrivateMessages, form);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveSiteConfig(form: SiteConfigForm) {
|
||||||
|
return wrapper(UserOperation.SaveSiteConfig, form);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function wrapper(op: UserOperation, data: MessageType) {
|
||||||
|
let send = { op: UserOperation[op], data: data };
|
||||||
|
console.log(send);
|
||||||
|
return JSON.stringify(send);
|
||||||
|
}
|
Loading…
Reference in a new issue