2020-08-04 14:57:37 +00:00
|
|
|
import {
|
2020-12-20 21:16:57 +00:00
|
|
|
Login,
|
2020-08-04 14:57:37 +00:00
|
|
|
LoginResponse,
|
2020-12-20 21:16:57 +00:00
|
|
|
CreatePost,
|
|
|
|
EditPost,
|
|
|
|
CreateComment,
|
|
|
|
DeletePost,
|
|
|
|
RemovePost,
|
|
|
|
StickyPost,
|
|
|
|
LockPost,
|
2020-08-04 14:57:37 +00:00
|
|
|
PostResponse,
|
|
|
|
SearchResponse,
|
2020-12-20 21:16:57 +00:00
|
|
|
FollowCommunity,
|
2020-08-04 14:57:37 +00:00
|
|
|
CommunityResponse,
|
|
|
|
GetPostResponse,
|
2020-12-20 21:16:57 +00:00
|
|
|
Register,
|
|
|
|
Comment,
|
|
|
|
EditComment,
|
|
|
|
DeleteComment,
|
|
|
|
RemoveComment,
|
|
|
|
Search,
|
2020-08-04 14:57:37 +00:00
|
|
|
CommentResponse,
|
2020-12-20 21:16:57 +00:00
|
|
|
GetCommunity,
|
|
|
|
CreateCommunity,
|
|
|
|
DeleteCommunity,
|
|
|
|
RemoveCommunity,
|
2021-03-12 19:09:03 +00:00
|
|
|
GetPersonMentions,
|
2020-12-20 21:16:57 +00:00
|
|
|
CreateCommentLike,
|
|
|
|
CreatePostLike,
|
|
|
|
EditPrivateMessage,
|
|
|
|
DeletePrivateMessage,
|
|
|
|
GetPrivateMessages,
|
|
|
|
GetSite,
|
|
|
|
GetPost,
|
2020-08-04 14:57:37 +00:00
|
|
|
PrivateMessageResponse,
|
|
|
|
PrivateMessagesResponse,
|
2021-03-12 19:09:03 +00:00
|
|
|
GetPersonMentionsResponse,
|
2020-12-20 21:16:57 +00:00
|
|
|
SaveUserSettings,
|
2020-08-04 15:06:27 +00:00
|
|
|
SortType,
|
|
|
|
ListingType,
|
|
|
|
GetSiteResponse,
|
2020-08-20 14:50:26 +00:00
|
|
|
SearchType,
|
|
|
|
LemmyHttp,
|
2021-03-12 19:09:03 +00:00
|
|
|
BanPersonResponse,
|
|
|
|
BanPerson,
|
2020-12-20 21:16:57 +00:00
|
|
|
BanFromCommunity,
|
2020-11-10 16:53:35 +00:00
|
|
|
BanFromCommunityResponse,
|
2020-12-20 21:16:57 +00:00
|
|
|
Post,
|
|
|
|
CreatePrivateMessage,
|
2021-08-23 15:25:39 +00:00
|
|
|
ResolveObjectResponse,
|
|
|
|
ResolveObject,
|
2021-10-15 14:37:33 +00:00
|
|
|
CreatePostReport,
|
|
|
|
ListPostReports,
|
|
|
|
PostReportResponse,
|
|
|
|
ListPostReportsResponse,
|
|
|
|
CreateCommentReport,
|
|
|
|
CommentReportResponse,
|
|
|
|
ListCommentReports,
|
|
|
|
ListCommentReportsResponse,
|
2022-04-07 20:52:17 +00:00
|
|
|
DeleteAccount,
|
2022-04-19 19:13:20 +00:00
|
|
|
DeleteAccountResponse
|
2020-08-20 14:50:26 +00:00
|
|
|
} 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 = {
|
2022-02-07 19:23:12 +00:00
|
|
|
client: new LemmyHttp('http://127.0.0.1:8541'),
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export let beta: API = {
|
2022-02-07 19:23:12 +00:00
|
|
|
client: new LemmyHttp('http://127.0.0.1:8551'),
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export let gamma: API = {
|
2022-02-07 19:23:12 +00:00
|
|
|
client: new LemmyHttp('http://127.0.0.1:8561'),
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
|
|
|
|
2020-08-20 12:44:22 +00:00
|
|
|
export let delta: API = {
|
2022-02-07 19:23:12 +00:00
|
|
|
client: new LemmyHttp('http://127.0.0.1:8571'),
|
2020-08-20 12:44:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export let epsilon: API = {
|
2022-02-07 19:23:12 +00:00
|
|
|
client: new LemmyHttp('http://127.0.0.1:8581'),
|
2020-08-20 12:44:22 +00:00
|
|
|
};
|
|
|
|
|
2021-09-19 21:20:47 +00:00
|
|
|
const password = 'lemmylemmy'
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function setupLogins() {
|
2020-12-20 21:16:57 +00:00
|
|
|
let formAlpha: Login = {
|
2020-08-04 14:57:37 +00:00
|
|
|
username_or_email: 'lemmy_alpha',
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
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',
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
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',
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
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',
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2020-08-20 12:44:22 +00:00
|
|
|
};
|
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',
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2020-08-20 12:44:22 +00:00
|
|
|
};
|
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;
|
2022-04-19 19:13:20 +00:00
|
|
|
|
|
|
|
// regstration applications are now enabled by default, need to disable them
|
|
|
|
await alpha.client.editSite({ require_application: false, auth: alpha.auth});
|
|
|
|
await beta.client.editSite({ require_application: false, auth: beta.auth});
|
|
|
|
await gamma.client.editSite({ require_application: false, auth: gamma.auth});
|
|
|
|
await delta.client.editSite({ require_application: false, auth: delta.auth});
|
|
|
|
await epsilon.client.editSite({ require_application: false, auth: epsilon.auth});
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createPost(
|
|
|
|
api: API,
|
|
|
|
community_id: number
|
|
|
|
): Promise<PostResponse> {
|
2020-11-10 16:53:35 +00:00
|
|
|
let name = randomString(5);
|
|
|
|
let body = randomString(10);
|
2020-09-15 19:26:47 +00:00
|
|
|
let url = 'https://google.com/';
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: CreatePost = {
|
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
|
|
|
}
|
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
export async function editPost(api: API, post: Post): Promise<PostResponse> {
|
2020-08-04 14:57:37 +00:00
|
|
|
let name = 'A jest test federated post, updated';
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: EditPost = {
|
2020-08-04 14:57:37 +00:00
|
|
|
name,
|
2021-01-18 21:57:31 +00:00
|
|
|
post_id: post.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
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-12-20 21:16:57 +00:00
|
|
|
let form: DeletePost = {
|
2021-01-18 21:57:31 +00:00
|
|
|
post_id: post.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
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-12-20 21:16:57 +00:00
|
|
|
let form: RemovePost = {
|
2021-01-18 21:57:31 +00:00
|
|
|
post_id: post.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
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-12-20 21:16:57 +00:00
|
|
|
let form: StickyPost = {
|
2021-01-18 21:57:31 +00:00
|
|
|
post_id: post.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
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-12-20 21:16:57 +00:00
|
|
|
let form: LockPost = {
|
2021-01-18 21:57:31 +00:00
|
|
|
post_id: post.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
export async function resolvePost(
|
2020-08-04 14:57:37 +00:00
|
|
|
api: API,
|
|
|
|
post: Post
|
2021-08-23 15:25:39 +00:00
|
|
|
): Promise<ResolveObjectResponse> {
|
|
|
|
let form: ResolveObject = {
|
2020-08-20 14:50:26 +00:00
|
|
|
q: post.ap_id,
|
|
|
|
};
|
2021-08-23 15:25:39 +00:00
|
|
|
return api.client.resolveObject(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 16:53:35 +00:00
|
|
|
export async function searchPostLocal(
|
|
|
|
api: API,
|
|
|
|
post: Post
|
|
|
|
): Promise<SearchResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: Search = {
|
2020-11-10 16:53:35 +00:00
|
|
|
q: post.name,
|
|
|
|
type_: SearchType.Posts,
|
|
|
|
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-12-20 21:16:57 +00:00
|
|
|
let form: GetPost = {
|
2020-08-20 14:50:26 +00:00
|
|
|
id: post_id,
|
|
|
|
};
|
|
|
|
return api.client.getPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
export async function resolveComment(
|
2020-08-04 14:57:37 +00:00
|
|
|
api: API,
|
|
|
|
comment: Comment
|
2021-08-23 15:25:39 +00:00
|
|
|
): Promise<ResolveObjectResponse> {
|
|
|
|
let form: ResolveObject = {
|
2020-08-20 14:50:26 +00:00
|
|
|
q: comment.ap_id,
|
|
|
|
};
|
2021-08-23 15:25:39 +00:00
|
|
|
return api.client.resolveObject(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
export async function resolveBetaCommunity(
|
2020-08-04 14:57:37 +00:00
|
|
|
api: API
|
2021-08-23 15:25:39 +00:00
|
|
|
): Promise<ResolveObjectResponse> {
|
2020-08-04 14:57:37 +00:00
|
|
|
// Use short-hand search url
|
2021-08-23 15:25:39 +00:00
|
|
|
let form: ResolveObject = {
|
2020-09-15 19:26:47 +00:00
|
|
|
q: '!main@lemmy-beta:8551',
|
|
|
|
};
|
2021-08-23 15:25:39 +00:00
|
|
|
return api.client.resolveObject(form);
|
2020-09-15 19:26:47 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
export async function resolveCommunity(
|
2020-09-15 19:26:47 +00:00
|
|
|
api: API,
|
2020-12-20 21:16:57 +00:00
|
|
|
q: string
|
2021-08-23 15:25:39 +00:00
|
|
|
): Promise<ResolveObjectResponse> {
|
|
|
|
let form: ResolveObject = {
|
2020-09-15 19:26:47 +00:00
|
|
|
q,
|
2020-08-20 14:50:26 +00:00
|
|
|
};
|
2021-08-23 15:25:39 +00:00
|
|
|
return api.client.resolveObject(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
export async function resolvePerson(
|
2020-08-04 15:06:27 +00:00
|
|
|
api: API,
|
|
|
|
apShortname: string
|
2021-08-23 15:25:39 +00:00
|
|
|
): Promise<ResolveObjectResponse> {
|
|
|
|
let form: ResolveObject = {
|
2020-08-20 14:50:26 +00:00
|
|
|
q: apShortname,
|
|
|
|
};
|
2021-08-23 15:25:39 +00:00
|
|
|
return api.client.resolveObject(form);
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 19:09:03 +00:00
|
|
|
export async function banPersonFromSite(
|
2020-11-10 16:53:35 +00:00
|
|
|
api: API,
|
2021-03-12 19:09:03 +00:00
|
|
|
person_id: number,
|
2022-02-07 19:23:12 +00:00
|
|
|
ban: boolean,
|
2022-06-22 12:05:41 +00:00
|
|
|
remove_data: boolean
|
2021-03-12 19:09:03 +00:00
|
|
|
): Promise<BanPersonResponse> {
|
2020-11-10 16:53:35 +00:00
|
|
|
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
|
2021-03-12 19:09:03 +00:00
|
|
|
let form: BanPerson = {
|
|
|
|
person_id,
|
2020-11-10 16:53:35 +00:00
|
|
|
ban,
|
2022-02-07 19:23:12 +00:00
|
|
|
remove_data,
|
2020-11-10 16:53:35 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
2021-03-12 19:09:03 +00:00
|
|
|
return api.client.banPerson(form);
|
2020-11-10 16:53:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 19:09:03 +00:00
|
|
|
export async function banPersonFromCommunity(
|
2020-11-10 16:53:35 +00:00
|
|
|
api: API,
|
2021-03-12 19:09:03 +00:00
|
|
|
person_id: number,
|
2020-11-10 16:53:35 +00:00
|
|
|
community_id: number,
|
2022-02-07 19:23:12 +00:00
|
|
|
remove_data: boolean,
|
2020-12-20 21:16:57 +00:00
|
|
|
ban: boolean
|
2020-11-10 16:53:35 +00:00
|
|
|
): Promise<BanFromCommunityResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: BanFromCommunity = {
|
2021-03-12 19:09:03 +00:00
|
|
|
person_id,
|
2020-11-10 16:53:35 +00:00
|
|
|
community_id,
|
2022-02-07 19:23:12 +00:00
|
|
|
remove_data,
|
2020-11-10 16:53:35 +00:00
|
|
|
ban,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
|
|
|
return api.client.banFromCommunity(form);
|
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function followCommunity(
|
|
|
|
api: API,
|
|
|
|
follow: boolean,
|
|
|
|
community_id: number
|
2022-05-26 15:17:04 +00:00
|
|
|
): Promise<CommunityResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: FollowCommunity = {
|
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 likePost(
|
|
|
|
api: API,
|
|
|
|
score: number,
|
|
|
|
post: Post
|
|
|
|
): Promise<PostResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: CreatePostLike = {
|
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-12-20 21:16:57 +00:00
|
|
|
let form: CreateComment = {
|
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
|
|
|
}
|
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
export async function editComment(
|
2020-08-04 14:57:37 +00:00
|
|
|
api: API,
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id: number,
|
2020-08-04 14:57:37 +00:00
|
|
|
content = 'A jest test federated comment update'
|
|
|
|
): Promise<CommentResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: EditComment = {
|
2020-08-04 14:57:37 +00:00
|
|
|
content,
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
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,
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id: number
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<CommentResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: DeleteComment = {
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
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,
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id: number
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<CommentResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: RemoveComment = {
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-03-12 19:09:03 +00:00
|
|
|
export async function getMentions(api: API): Promise<GetPersonMentionsResponse> {
|
|
|
|
let form: GetPersonMentions = {
|
2020-08-20 14:50:26 +00:00
|
|
|
sort: SortType.New,
|
|
|
|
unread_only: false,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2021-03-12 19:09:03 +00:00
|
|
|
return api.client.getPersonMentions(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function likeComment(
|
|
|
|
api: API,
|
|
|
|
score: number,
|
|
|
|
comment: Comment
|
|
|
|
): Promise<CommentResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: CreateCommentLike = {
|
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';
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: CreateCommunity = {
|
2020-08-04 14:57:37 +00:00
|
|
|
name: name_,
|
|
|
|
title: name_,
|
2020-09-15 19:26:47 +00:00
|
|
|
description,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-05 20:19:06 +00:00
|
|
|
export async function getCommunity(
|
|
|
|
api: API,
|
2020-12-20 21:16:57 +00:00
|
|
|
id: number
|
2020-11-05 20:19:06 +00:00
|
|
|
): Promise<CommunityResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: GetCommunity = {
|
2020-11-05 20:19:06 +00:00
|
|
|
id,
|
|
|
|
};
|
|
|
|
return api.client.getCommunity(form);
|
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function deleteCommunity(
|
|
|
|
api: API,
|
|
|
|
deleted: boolean,
|
2021-01-18 21:57:31 +00:00
|
|
|
community_id: number
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<CommunityResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: DeleteCommunity = {
|
2021-01-18 21:57:31 +00:00
|
|
|
community_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
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,
|
2021-01-18 21:57:31 +00:00
|
|
|
community_id: number
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<CommunityResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: RemoveCommunity = {
|
2021-01-18 21:57:31 +00:00
|
|
|
community_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
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-12-20 21:16:57 +00:00
|
|
|
let form: CreatePrivateMessage = {
|
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
|
|
|
}
|
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
export async function editPrivateMessage(
|
2020-08-04 14:57:37 +00:00
|
|
|
api: API,
|
2021-01-18 21:57:31 +00:00
|
|
|
private_message_id: number
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<PrivateMessageResponse> {
|
|
|
|
let updatedContent = 'A jest test federated private message edited';
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: EditPrivateMessage = {
|
2020-08-04 14:57:37 +00:00
|
|
|
content: updatedContent,
|
2021-01-18 21:57:31 +00:00
|
|
|
private_message_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
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,
|
2021-01-18 21:57:31 +00:00
|
|
|
private_message_id: number
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<PrivateMessageResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: DeletePrivateMessage = {
|
2020-08-04 14:57:37 +00:00
|
|
|
deleted,
|
2021-01-18 21:57:31 +00:00
|
|
|
private_message_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
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-12-20 21:16:57 +00:00
|
|
|
let form: Register = {
|
2020-08-04 15:06:27 +00:00
|
|
|
username,
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
|
|
|
password_verify: password,
|
2020-08-04 15:06:27 +00:00
|
|
|
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(
|
2021-08-19 20:54:15 +00:00
|
|
|
api: API
|
2020-08-04 15:06:27 +00:00
|
|
|
): Promise<LoginResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: SaveUserSettings = {
|
2020-08-04 15:06:27 +00:00
|
|
|
show_nsfw: true,
|
|
|
|
theme: 'darkly',
|
2021-01-04 19:09:53 +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',
|
2021-08-19 20:54:15 +00:00
|
|
|
auth: api.auth,
|
2020-08-04 15:06:27 +00:00
|
|
|
};
|
2020-09-17 15:41:51 +00:00
|
|
|
return saveUserSettings(api, form);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function saveUserSettings(
|
|
|
|
api: API,
|
2020-12-20 21:16:57 +00:00
|
|
|
form: SaveUserSettings
|
2020-09-17 15:41:51 +00:00
|
|
|
): Promise<LoginResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.saveUserSettings(form);
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 20:52:17 +00:00
|
|
|
export async function deleteUser(
|
2022-06-22 12:05:41 +00:00
|
|
|
api: API
|
2022-04-19 19:13:20 +00:00
|
|
|
): Promise<DeleteAccountResponse> {
|
2022-04-07 20:52:17 +00:00
|
|
|
let form: DeleteAccount = {
|
|
|
|
auth: api.auth,
|
|
|
|
password
|
|
|
|
};
|
|
|
|
return api.client.deleteAccount(form);
|
|
|
|
}
|
|
|
|
|
2020-08-04 15:06:27 +00:00
|
|
|
export async function getSite(
|
2021-08-19 20:54:15 +00:00
|
|
|
api: API
|
2020-08-04 15:06:27 +00:00
|
|
|
): Promise<GetSiteResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: GetSite = {
|
2021-08-19 20:54:15 +00:00
|
|
|
auth: api.auth,
|
2020-08-20 14:50:26 +00:00
|
|
|
};
|
|
|
|
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-12-20 21:16:57 +00:00
|
|
|
let form: GetPrivateMessages = {
|
2020-08-20 14:50:26 +00:00
|
|
|
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
|
2021-08-19 20:54:15 +00:00
|
|
|
): Promise<GetSiteResponse> {
|
2020-08-04 14:57:37 +00:00
|
|
|
// Unfollow all remote communities
|
2021-08-19 20:54:15 +00:00
|
|
|
let site = await getSite(api);
|
|
|
|
let remoteFollowed = site.my_user.follows.filter(
|
2020-12-20 21:16:57 +00:00
|
|
|
c => c.community.local == false
|
2020-08-04 14:57:37 +00:00
|
|
|
);
|
|
|
|
for (let cu of remoteFollowed) {
|
2020-12-20 21:16:57 +00:00
|
|
|
await followCommunity(api, false, cu.community.id);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
2021-08-19 20:54:15 +00:00
|
|
|
let siteRes = await getSite(api);
|
|
|
|
return siteRes;
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 15:17:04 +00:00
|
|
|
export async function followBeta(api: API): Promise<CommunityResponse> {
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaCommunity = (await resolveBetaCommunity(api)).community;
|
|
|
|
if (betaCommunity) {
|
|
|
|
let follow = await followCommunity(api, true, betaCommunity.community.id);
|
2020-08-04 15:06:27 +00:00
|
|
|
return follow;
|
|
|
|
}
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 14:37:33 +00:00
|
|
|
export async function reportPost(
|
|
|
|
api: API,
|
|
|
|
post_id: number,
|
2022-06-22 12:05:41 +00:00
|
|
|
reason: string
|
2021-10-15 14:37:33 +00:00
|
|
|
): Promise<PostReportResponse> {
|
|
|
|
let form: CreatePostReport = {
|
|
|
|
post_id,
|
|
|
|
reason,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
|
|
|
return api.client.createPostReport(form);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function listPostReports(api: API): Promise<ListPostReportsResponse> {
|
|
|
|
let form: ListPostReports = {
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
|
|
|
return api.client.listPostReports(form);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function reportComment(
|
|
|
|
api: API,
|
|
|
|
comment_id: number,
|
2022-06-22 12:05:41 +00:00
|
|
|
reason: string
|
2021-10-15 14:37:33 +00:00
|
|
|
): Promise<CommentReportResponse> {
|
|
|
|
let form: CreateCommentReport = {
|
|
|
|
comment_id,
|
|
|
|
reason,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
|
|
|
return api.client.createCommentReport(form);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function listCommentReports(api: API): Promise<ListCommentReportsResponse> {
|
|
|
|
let form: ListCommentReports = {
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
|
|
|
return api.client.listCommentReports(form);
|
|
|
|
}
|
|
|
|
|
2020-10-01 13:32:01 +00:00
|
|
|
export function delay(millis: number = 500) {
|
2020-12-20 21:16:57 +00:00
|
|
|
return new Promise(resolve => setTimeout(resolve, millis));
|
2020-10-01 13:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function longDelay() {
|
|
|
|
return delay(10000);
|
|
|
|
}
|
2020-08-31 13:48:02 +00:00
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export function wrapper(form: any): string {
|
|
|
|
return JSON.stringify(form);
|
|
|
|
}
|
|
|
|
|
2021-10-15 14:37:33 +00:00
|
|
|
export function randomString(length: number): string {
|
2020-08-04 14:57:37 +00:00
|
|
|
var result = '';
|
2021-12-20 22:23:06 +00:00
|
|
|
var characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
|
2020-08-04 14:57:37 +00:00
|
|
|
var charactersLength = characters.length;
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2022-03-22 19:50:47 +00:00
|
|
|
|
|
|
|
export async function unfollows() {
|
|
|
|
await unfollowRemotes(alpha);
|
|
|
|
await unfollowRemotes(gamma);
|
|
|
|
await unfollowRemotes(delta);
|
|
|
|
await unfollowRemotes(epsilon);
|
|
|
|
}
|