2020-08-04 14:57:37 +00:00
|
|
|
import {
|
|
|
|
LoginForm,
|
|
|
|
LoginResponse,
|
|
|
|
Post,
|
|
|
|
PostForm,
|
|
|
|
Comment,
|
|
|
|
DeletePostForm,
|
|
|
|
RemovePostForm,
|
|
|
|
StickyPostForm,
|
|
|
|
LockPostForm,
|
|
|
|
PostResponse,
|
|
|
|
SearchResponse,
|
|
|
|
FollowCommunityForm,
|
|
|
|
CommunityResponse,
|
|
|
|
GetFollowedCommunitiesResponse,
|
|
|
|
GetPostResponse,
|
2020-08-04 15:06:27 +00:00
|
|
|
RegisterForm,
|
2020-08-04 14:57:37 +00:00
|
|
|
CommentForm,
|
|
|
|
DeleteCommentForm,
|
|
|
|
RemoveCommentForm,
|
2020-08-20 14:50:26 +00:00
|
|
|
SearchForm,
|
2020-08-04 14:57:37 +00:00
|
|
|
CommentResponse,
|
|
|
|
CommunityForm,
|
|
|
|
DeleteCommunityForm,
|
|
|
|
RemoveCommunityForm,
|
2020-08-20 14:50:26 +00:00
|
|
|
GetUserMentionsForm,
|
2020-08-04 14:57:37 +00:00
|
|
|
CommentLikeForm,
|
|
|
|
CreatePostLikeForm,
|
|
|
|
PrivateMessageForm,
|
|
|
|
EditPrivateMessageForm,
|
|
|
|
DeletePrivateMessageForm,
|
2020-08-20 14:50:26 +00:00
|
|
|
GetFollowedCommunitiesForm,
|
|
|
|
GetPrivateMessagesForm,
|
|
|
|
GetSiteForm,
|
|
|
|
GetPostForm,
|
2020-08-04 14:57:37 +00:00
|
|
|
PrivateMessageResponse,
|
|
|
|
PrivateMessagesResponse,
|
|
|
|
GetUserMentionsResponse,
|
2020-08-04 15:06:27 +00:00
|
|
|
UserSettingsForm,
|
|
|
|
SortType,
|
|
|
|
ListingType,
|
|
|
|
GetSiteResponse,
|
2020-08-20 14:50:26 +00:00
|
|
|
SearchType,
|
|
|
|
LemmyHttp,
|
|
|
|
} from 'lemmy-js-client';
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
export interface API {
|
2020-08-20 14:50:26 +00:00
|
|
|
client: LemmyHttp;
|
2020-08-04 14:57:37 +00:00
|
|
|
auth?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export let alpha: API = {
|
2020-09-15 19:26:47 +00:00
|
|
|
client: new LemmyHttp('http://localhost:8541/api/v1'),
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export let beta: API = {
|
2020-09-15 19:26:47 +00:00
|
|
|
client: new LemmyHttp('http://localhost:8551/api/v1'),
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export let gamma: API = {
|
2020-09-15 19:26:47 +00:00
|
|
|
client: new LemmyHttp('http://localhost:8561/api/v1'),
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
|
|
|
|
2020-08-20 12:44:22 +00:00
|
|
|
export let delta: API = {
|
2020-09-15 19:26:47 +00:00
|
|
|
client: new LemmyHttp('http://localhost:8571/api/v1'),
|
2020-08-20 12:44:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export let epsilon: API = {
|
2020-09-15 19:26:47 +00:00
|
|
|
client: new LemmyHttp('http://localhost:8581/api/v1'),
|
2020-08-20 12:44:22 +00:00
|
|
|
};
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function setupLogins() {
|
2020-08-20 12:44:22 +00:00
|
|
|
let formAlpha: LoginForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
username_or_email: 'lemmy_alpha',
|
|
|
|
password: 'lemmy',
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resAlpha = alpha.client.login(formAlpha);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-08-20 12:44:22 +00:00
|
|
|
let formBeta = {
|
2020-08-04 14:57:37 +00:00
|
|
|
username_or_email: 'lemmy_beta',
|
|
|
|
password: 'lemmy',
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resBeta = beta.client.login(formBeta);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-08-20 12:44:22 +00:00
|
|
|
let formGamma = {
|
2020-08-04 14:57:37 +00:00
|
|
|
username_or_email: 'lemmy_gamma',
|
|
|
|
password: 'lemmy',
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resGamma = gamma.client.login(formGamma);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-08-20 12:44:22 +00:00
|
|
|
let formDelta = {
|
|
|
|
username_or_email: 'lemmy_delta',
|
|
|
|
password: 'lemmy',
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resDelta = delta.client.login(formDelta);
|
2020-08-20 12:44:22 +00:00
|
|
|
|
|
|
|
let formEpsilon = {
|
|
|
|
username_or_email: 'lemmy_epsilon',
|
|
|
|
password: 'lemmy',
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resEpsilon = epsilon.client.login(formEpsilon);
|
2020-08-20 12:44:22 +00:00
|
|
|
|
|
|
|
let res = await Promise.all([
|
|
|
|
resAlpha,
|
|
|
|
resBeta,
|
|
|
|
resGamma,
|
|
|
|
resDelta,
|
|
|
|
resEpsilon,
|
|
|
|
]);
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
alpha.auth = res[0].jwt;
|
|
|
|
beta.auth = res[1].jwt;
|
|
|
|
gamma.auth = res[2].jwt;
|
2020-08-20 12:44:22 +00:00
|
|
|
delta.auth = res[3].jwt;
|
|
|
|
epsilon.auth = res[4].jwt;
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createPost(
|
|
|
|
api: API,
|
|
|
|
community_id: number
|
|
|
|
): Promise<PostResponse> {
|
|
|
|
let name = 'A jest test post';
|
2020-09-15 19:26:47 +00:00
|
|
|
let body = 'Some body';
|
|
|
|
let url = 'https://google.com/';
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: PostForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
name,
|
2020-09-15 19:26:47 +00:00
|
|
|
url,
|
|
|
|
body,
|
2020-08-04 14:57:37 +00:00
|
|
|
auth: api.auth,
|
|
|
|
community_id,
|
|
|
|
nsfw: false,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.createPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function updatePost(api: API, post: Post): Promise<PostResponse> {
|
|
|
|
let name = 'A jest test federated post, updated';
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: PostForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
name,
|
|
|
|
edit_id: post.id,
|
|
|
|
auth: api.auth,
|
|
|
|
nsfw: false,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.editPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function deletePost(
|
|
|
|
api: API,
|
|
|
|
deleted: boolean,
|
|
|
|
post: Post
|
|
|
|
): Promise<PostResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: DeletePostForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
edit_id: post.id,
|
|
|
|
deleted: deleted,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.deletePost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function removePost(
|
|
|
|
api: API,
|
|
|
|
removed: boolean,
|
|
|
|
post: Post
|
|
|
|
): Promise<PostResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: RemovePostForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
edit_id: post.id,
|
|
|
|
removed,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.removePost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function stickyPost(
|
|
|
|
api: API,
|
|
|
|
stickied: boolean,
|
|
|
|
post: Post
|
|
|
|
): Promise<PostResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: StickyPostForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
edit_id: post.id,
|
|
|
|
stickied,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.stickyPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function lockPost(
|
|
|
|
api: API,
|
|
|
|
locked: boolean,
|
|
|
|
post: Post
|
|
|
|
): Promise<PostResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: LockPostForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
edit_id: post.id,
|
|
|
|
locked,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.lockPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function searchPost(
|
|
|
|
api: API,
|
|
|
|
post: Post
|
|
|
|
): Promise<SearchResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: SearchForm = {
|
|
|
|
q: post.ap_id,
|
2020-08-31 13:48:02 +00:00
|
|
|
type_: SearchType.Posts,
|
2020-08-20 14:50:26 +00:00
|
|
|
sort: SortType.TopAll,
|
|
|
|
};
|
|
|
|
return api.client.search(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getPost(
|
|
|
|
api: API,
|
|
|
|
post_id: number
|
|
|
|
): Promise<GetPostResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: GetPostForm = {
|
|
|
|
id: post_id,
|
|
|
|
};
|
|
|
|
return api.client.getPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function searchComment(
|
|
|
|
api: API,
|
|
|
|
comment: Comment
|
|
|
|
): Promise<SearchResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: SearchForm = {
|
|
|
|
q: comment.ap_id,
|
2020-08-31 13:48:02 +00:00
|
|
|
type_: SearchType.Comments,
|
2020-08-20 14:50:26 +00:00
|
|
|
sort: SortType.TopAll,
|
|
|
|
};
|
|
|
|
return api.client.search(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function searchForBetaCommunity(
|
|
|
|
api: API
|
|
|
|
): Promise<SearchResponse> {
|
|
|
|
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
|
|
|
|
// Use short-hand search url
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: SearchForm = {
|
2020-09-15 19:26:47 +00:00
|
|
|
q: '!main@lemmy-beta:8551',
|
|
|
|
type_: SearchType.Communities,
|
|
|
|
sort: SortType.TopAll,
|
|
|
|
};
|
|
|
|
return api.client.search(form);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function searchForCommunity(
|
|
|
|
api: API,
|
|
|
|
q: string,
|
|
|
|
): Promise<SearchResponse> {
|
|
|
|
// Use short-hand search url
|
|
|
|
let form: SearchForm = {
|
|
|
|
q,
|
2020-08-31 13:48:02 +00:00
|
|
|
type_: SearchType.Communities,
|
2020-08-20 14:50:26 +00:00
|
|
|
sort: SortType.TopAll,
|
|
|
|
};
|
|
|
|
return api.client.search(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 15:06:27 +00:00
|
|
|
export async function searchForUser(
|
|
|
|
api: API,
|
|
|
|
apShortname: string
|
|
|
|
): Promise<SearchResponse> {
|
|
|
|
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
|
|
|
|
// Use short-hand search url
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: SearchForm = {
|
|
|
|
q: apShortname,
|
2020-08-31 13:48:02 +00:00
|
|
|
type_: SearchType.Users,
|
2020-08-20 14:50:26 +00:00
|
|
|
sort: SortType.TopAll,
|
|
|
|
};
|
|
|
|
return api.client.search(form);
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function followCommunity(
|
|
|
|
api: API,
|
|
|
|
follow: boolean,
|
|
|
|
community_id: number
|
|
|
|
): Promise<CommunityResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: FollowCommunityForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
community_id,
|
|
|
|
follow,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.followCommunity(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function checkFollowedCommunities(
|
|
|
|
api: API
|
|
|
|
): Promise<GetFollowedCommunitiesResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: GetFollowedCommunitiesForm = {
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
|
|
|
return api.client.getFollowedCommunities(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function likePost(
|
|
|
|
api: API,
|
|
|
|
score: number,
|
|
|
|
post: Post
|
|
|
|
): Promise<PostResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: CreatePostLikeForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
post_id: post.id,
|
|
|
|
score: score,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
|
|
|
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.likePost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createComment(
|
|
|
|
api: API,
|
|
|
|
post_id: number,
|
|
|
|
parent_id?: number,
|
|
|
|
content = 'a jest test comment'
|
|
|
|
): Promise<CommentResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: CommentForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
content,
|
|
|
|
post_id,
|
|
|
|
parent_id,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.createComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function updateComment(
|
|
|
|
api: API,
|
|
|
|
edit_id: number,
|
|
|
|
content = 'A jest test federated comment update'
|
|
|
|
): Promise<CommentResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: CommentForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
content,
|
|
|
|
edit_id,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.editComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function deleteComment(
|
|
|
|
api: API,
|
|
|
|
deleted: boolean,
|
|
|
|
edit_id: number
|
|
|
|
): Promise<CommentResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: DeleteCommentForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
edit_id,
|
|
|
|
deleted,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.deleteComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function removeComment(
|
|
|
|
api: API,
|
|
|
|
removed: boolean,
|
|
|
|
edit_id: number
|
|
|
|
): Promise<CommentResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: RemoveCommentForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
edit_id,
|
|
|
|
removed,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.removeComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getMentions(api: API): Promise<GetUserMentionsResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: GetUserMentionsForm = {
|
|
|
|
sort: SortType.New,
|
|
|
|
unread_only: false,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
|
|
|
return api.client.getUserMentions(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function likeComment(
|
|
|
|
api: API,
|
|
|
|
score: number,
|
|
|
|
comment: Comment
|
|
|
|
): Promise<CommentResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: CommentLikeForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
comment_id: comment.id,
|
|
|
|
score,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.likeComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createCommunity(
|
|
|
|
api: API,
|
|
|
|
name_: string = randomString(5)
|
|
|
|
): Promise<CommunityResponse> {
|
2020-09-15 19:26:47 +00:00
|
|
|
let description = 'a sample description';
|
|
|
|
let icon = 'https://image.flaticon.com/icons/png/512/35/35896.png';
|
|
|
|
let banner = 'https://image.flaticon.com/icons/png/512/35/35896.png';
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: CommunityForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
name: name_,
|
|
|
|
title: name_,
|
2020-09-15 19:26:47 +00:00
|
|
|
description,
|
|
|
|
icon,
|
|
|
|
banner,
|
2020-08-04 14:57:37 +00:00
|
|
|
category_id: 1,
|
|
|
|
nsfw: false,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.createCommunity(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function deleteCommunity(
|
|
|
|
api: API,
|
|
|
|
deleted: boolean,
|
|
|
|
edit_id: number
|
|
|
|
): Promise<CommunityResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: DeleteCommunityForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
edit_id,
|
|
|
|
deleted,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.deleteCommunity(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function removeCommunity(
|
|
|
|
api: API,
|
|
|
|
removed: boolean,
|
|
|
|
edit_id: number
|
|
|
|
): Promise<CommunityResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: RemoveCommunityForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
edit_id,
|
|
|
|
removed,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.removeCommunity(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createPrivateMessage(
|
|
|
|
api: API,
|
|
|
|
recipient_id: number
|
|
|
|
): Promise<PrivateMessageResponse> {
|
|
|
|
let content = 'A jest test federated private message';
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: PrivateMessageForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
content,
|
|
|
|
recipient_id,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.createPrivateMessage(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function updatePrivateMessage(
|
|
|
|
api: API,
|
|
|
|
edit_id: number
|
|
|
|
): Promise<PrivateMessageResponse> {
|
|
|
|
let updatedContent = 'A jest test federated private message edited';
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: EditPrivateMessageForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
content: updatedContent,
|
|
|
|
edit_id,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.editPrivateMessage(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function deletePrivateMessage(
|
|
|
|
api: API,
|
|
|
|
deleted: boolean,
|
|
|
|
edit_id: number
|
|
|
|
): Promise<PrivateMessageResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: DeletePrivateMessageForm = {
|
2020-08-04 14:57:37 +00:00
|
|
|
deleted,
|
|
|
|
edit_id,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.deletePrivateMessage(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 15:06:27 +00:00
|
|
|
export async function registerUser(
|
|
|
|
api: API,
|
|
|
|
username: string = randomString(5)
|
|
|
|
): Promise<LoginResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: RegisterForm = {
|
2020-08-04 15:06:27 +00:00
|
|
|
username,
|
|
|
|
password: 'test',
|
|
|
|
password_verify: 'test',
|
|
|
|
admin: false,
|
|
|
|
show_nsfw: true,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.register(form);
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function saveUserSettingsBio(
|
|
|
|
api: API,
|
|
|
|
auth: string
|
|
|
|
): Promise<LoginResponse> {
|
|
|
|
let form: UserSettingsForm = {
|
|
|
|
show_nsfw: true,
|
|
|
|
theme: 'darkly',
|
2020-08-20 14:50:26 +00:00
|
|
|
default_sort_type: Object.keys(SortType).indexOf(SortType.Active),
|
|
|
|
default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
|
2020-08-04 15:06:27 +00:00
|
|
|
lang: 'en',
|
|
|
|
show_avatars: true,
|
|
|
|
send_notifications_to_email: false,
|
|
|
|
bio: 'a changed bio',
|
|
|
|
auth,
|
|
|
|
};
|
2020-09-17 15:41:51 +00:00
|
|
|
return saveUserSettings(api, form);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function saveUserSettings(
|
|
|
|
api: API,
|
|
|
|
form: UserSettingsForm
|
|
|
|
): Promise<LoginResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.saveUserSettings(form);
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getSite(
|
|
|
|
api: API,
|
|
|
|
auth: string
|
|
|
|
): Promise<GetSiteResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: GetSiteForm = {
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
return api.client.getSite(form);
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function listPrivateMessages(
|
|
|
|
api: API
|
|
|
|
): Promise<PrivateMessagesResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
let form: GetPrivateMessagesForm = {
|
|
|
|
auth: api.auth,
|
|
|
|
unread_only: false,
|
|
|
|
limit: 999,
|
|
|
|
};
|
|
|
|
return api.client.getPrivateMessages(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function unfollowRemotes(
|
|
|
|
api: API
|
|
|
|
): Promise<GetFollowedCommunitiesResponse> {
|
|
|
|
// Unfollow all remote communities
|
|
|
|
let followed = await checkFollowedCommunities(api);
|
|
|
|
let remoteFollowed = followed.communities.filter(
|
|
|
|
c => c.community_local == false
|
|
|
|
);
|
|
|
|
for (let cu of remoteFollowed) {
|
|
|
|
await followCommunity(api, false, cu.community_id);
|
|
|
|
}
|
|
|
|
let followed2 = await checkFollowedCommunities(api);
|
|
|
|
return followed2;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function followBeta(api: API): Promise<CommunityResponse> {
|
|
|
|
await unfollowRemotes(api);
|
|
|
|
|
|
|
|
// Cache it
|
|
|
|
let search = await searchForBetaCommunity(api);
|
2020-08-04 15:06:27 +00:00
|
|
|
let com = search.communities.filter(c => c.local == false);
|
|
|
|
if (com[0]) {
|
|
|
|
let follow = await followCommunity(api, true, com[0].id);
|
|
|
|
return follow;
|
|
|
|
}
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 13:48:02 +00:00
|
|
|
export const delay = (millis: number = 1500) =>
|
|
|
|
new Promise((resolve, _reject) => {
|
|
|
|
setTimeout(_ => resolve(), millis);
|
|
|
|
});
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export function wrapper(form: any): string {
|
|
|
|
return JSON.stringify(form);
|
|
|
|
}
|
|
|
|
|
|
|
|
function randomString(length: number): string {
|
|
|
|
var result = '';
|
|
|
|
var characters = 'abcdefghijklmnopqrstuvwxyz0123456789_';
|
|
|
|
var charactersLength = characters.length;
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|