2022-10-27 09:24:07 +00:00
|
|
|
import { None, Some, Option } from "@sniptt/monads";
|
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,
|
|
|
|
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-07-30 03:55:59 +00:00
|
|
|
DeleteAccountResponse,
|
|
|
|
EditSite,
|
|
|
|
CommentSortType,
|
|
|
|
GetComments,
|
2022-10-27 09:24:07 +00:00
|
|
|
GetCommentsResponse,
|
2022-12-12 11:17:10 +00:00
|
|
|
FeaturePost,
|
|
|
|
PostFeatureType,
|
2022-10-27 09:24:07 +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;
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: Option<string>;
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export let alpha: API = {
|
2022-10-27 09:24:07 +00:00
|
|
|
client: new LemmyHttp("http://127.0.0.1:8541"),
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: None,
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export let beta: API = {
|
2022-10-27 09:24:07 +00:00
|
|
|
client: new LemmyHttp("http://127.0.0.1:8551"),
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: None,
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export let gamma: API = {
|
2022-10-27 09:24:07 +00:00
|
|
|
client: new LemmyHttp("http://127.0.0.1:8561"),
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: None,
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
|
|
|
|
2020-08-20 12:44:22 +00:00
|
|
|
export let delta: API = {
|
2022-10-27 09:24:07 +00:00
|
|
|
client: new LemmyHttp("http://127.0.0.1:8571"),
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: None,
|
2020-08-20 12:44:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export let epsilon: API = {
|
2022-10-27 09:24:07 +00:00
|
|
|
client: new LemmyHttp("http://127.0.0.1:8581"),
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: None,
|
2020-08-20 12:44:22 +00:00
|
|
|
};
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
const password = "lemmylemmy";
|
2021-09-19 21:20:47 +00:00
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function setupLogins() {
|
2022-07-30 03:55:59 +00:00
|
|
|
let formAlpha = new Login({
|
2022-10-27 09:24:07 +00:00
|
|
|
username_or_email: "lemmy_alpha",
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2022-07-30 03:55:59 +00:00
|
|
|
});
|
2020-08-20 14:50:26 +00:00
|
|
|
let resAlpha = alpha.client.login(formAlpha);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2022-07-30 03:55:59 +00:00
|
|
|
let formBeta = new Login({
|
2022-10-27 09:24:07 +00:00
|
|
|
username_or_email: "lemmy_beta",
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2022-07-30 03:55:59 +00:00
|
|
|
});
|
2020-08-20 14:50:26 +00:00
|
|
|
let resBeta = beta.client.login(formBeta);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2022-07-30 03:55:59 +00:00
|
|
|
let formGamma = new Login({
|
2022-10-27 09:24:07 +00:00
|
|
|
username_or_email: "lemmy_gamma",
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2022-07-30 03:55:59 +00:00
|
|
|
});
|
2020-08-20 14:50:26 +00:00
|
|
|
let resGamma = gamma.client.login(formGamma);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2022-07-30 03:55:59 +00:00
|
|
|
let formDelta = new Login({
|
2022-10-27 09:24:07 +00:00
|
|
|
username_or_email: "lemmy_delta",
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2022-07-30 03:55:59 +00:00
|
|
|
});
|
2020-08-20 14:50:26 +00:00
|
|
|
let resDelta = delta.client.login(formDelta);
|
2020-08-20 12:44:22 +00:00
|
|
|
|
2022-07-30 03:55:59 +00:00
|
|
|
let formEpsilon = new Login({
|
2022-10-27 09:24:07 +00:00
|
|
|
username_or_email: "lemmy_epsilon",
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2022-07-30 03:55:59 +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
|
|
|
|
2022-07-30 03:55:59 +00:00
|
|
|
// Registration applications are now enabled by default, need to disable them
|
|
|
|
let editSiteForm = new EditSite({
|
2022-10-27 09:24:07 +00:00
|
|
|
require_application: Some(false),
|
|
|
|
federation_debug: Some(true),
|
2022-07-30 03:55:59 +00:00
|
|
|
name: None,
|
|
|
|
sidebar: None,
|
|
|
|
description: None,
|
|
|
|
icon: None,
|
|
|
|
banner: None,
|
|
|
|
enable_downvotes: None,
|
|
|
|
open_registration: None,
|
|
|
|
enable_nsfw: None,
|
|
|
|
community_creation_admin_only: None,
|
|
|
|
require_email_verification: None,
|
|
|
|
application_question: None,
|
|
|
|
private_instance: None,
|
|
|
|
default_theme: None,
|
|
|
|
default_post_listing_type: None,
|
2022-10-27 09:24:07 +00:00
|
|
|
legal_information: None,
|
|
|
|
application_email_admins: None,
|
|
|
|
hide_modlog_mod_names: None,
|
|
|
|
discussion_languages: None,
|
|
|
|
slur_filter_regex: None,
|
|
|
|
actor_name_max_length: None,
|
|
|
|
rate_limit_message: Some(999),
|
|
|
|
rate_limit_message_per_second: None,
|
|
|
|
rate_limit_post: Some(999),
|
|
|
|
rate_limit_post_per_second: None,
|
|
|
|
rate_limit_register: Some(999),
|
|
|
|
rate_limit_register_per_second: None,
|
|
|
|
rate_limit_image: Some(999),
|
|
|
|
rate_limit_image_per_second: None,
|
|
|
|
rate_limit_comment: Some(999),
|
|
|
|
rate_limit_comment_per_second: None,
|
|
|
|
rate_limit_search: Some(999),
|
|
|
|
rate_limit_search_per_second: None,
|
|
|
|
federation_enabled: None,
|
|
|
|
federation_worker_count: None,
|
|
|
|
captcha_enabled: None,
|
|
|
|
captcha_difficulty: None,
|
|
|
|
allowed_instances: None,
|
|
|
|
blocked_instances: None,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: "",
|
2022-12-12 11:17:10 +00:00
|
|
|
taglines: None,
|
2022-07-30 03:55:59 +00:00
|
|
|
});
|
2022-10-27 09:24:07 +00:00
|
|
|
|
|
|
|
// Set the blocks and auths for each
|
2022-07-30 03:55:59 +00:00
|
|
|
editSiteForm.auth = alpha.auth.unwrap();
|
2022-10-27 09:24:07 +00:00
|
|
|
editSiteForm.allowed_instances = Some([
|
|
|
|
"lemmy-beta",
|
|
|
|
"lemmy-gamma",
|
|
|
|
"lemmy-delta",
|
|
|
|
"lemmy-epsilon",
|
|
|
|
]);
|
2022-07-30 03:55:59 +00:00
|
|
|
await alpha.client.editSite(editSiteForm);
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2022-07-30 03:55:59 +00:00
|
|
|
editSiteForm.auth = beta.auth.unwrap();
|
2022-10-27 09:24:07 +00:00
|
|
|
editSiteForm.allowed_instances = Some([
|
|
|
|
"lemmy-alpha",
|
|
|
|
"lemmy-gamma",
|
|
|
|
"lemmy-delta",
|
|
|
|
"lemmy-epsilon",
|
|
|
|
]);
|
2022-07-30 03:55:59 +00:00
|
|
|
await beta.client.editSite(editSiteForm);
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2022-07-30 03:55:59 +00:00
|
|
|
editSiteForm.auth = gamma.auth.unwrap();
|
2022-10-27 09:24:07 +00:00
|
|
|
editSiteForm.allowed_instances = Some([
|
|
|
|
"lemmy-alpha",
|
|
|
|
"lemmy-beta",
|
|
|
|
"lemmy-delta",
|
|
|
|
"lemmy-epsilon",
|
|
|
|
]);
|
2022-07-30 03:55:59 +00:00
|
|
|
await gamma.client.editSite(editSiteForm);
|
2022-10-27 09:24:07 +00:00
|
|
|
|
|
|
|
editSiteForm.allowed_instances = Some(["lemmy-beta"]);
|
2022-07-30 03:55:59 +00:00
|
|
|
editSiteForm.auth = delta.auth.unwrap();
|
|
|
|
await delta.client.editSite(editSiteForm);
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2022-07-30 03:55:59 +00:00
|
|
|
editSiteForm.auth = epsilon.auth.unwrap();
|
2022-10-27 09:24:07 +00:00
|
|
|
editSiteForm.allowed_instances = Some([]);
|
|
|
|
editSiteForm.blocked_instances = Some(["lemmy-alpha"]);
|
2022-07-30 03:55:59 +00:00
|
|
|
await epsilon.client.editSite(editSiteForm);
|
2022-06-22 19:38:27 +00:00
|
|
|
|
2022-10-13 16:30:31 +00:00
|
|
|
// Create the main alpha/beta communities
|
|
|
|
await createCommunity(alpha, "main");
|
2022-06-22 19:38:27 +00:00
|
|
|
await createCommunity(beta, "main");
|
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);
|
2022-07-30 03:55:59 +00:00
|
|
|
let body = Some(randomString(10));
|
2022-10-27 09:24:07 +00:00
|
|
|
let url = Some("https://google.com/");
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new CreatePost({
|
2020-08-04 14:57:37 +00:00
|
|
|
name,
|
2020-09-15 19:26:47 +00:00
|
|
|
url,
|
|
|
|
body,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
2020-08-04 14:57:37 +00:00
|
|
|
community_id,
|
2022-07-30 03:55:59 +00:00
|
|
|
nsfw: None,
|
|
|
|
honeypot: None,
|
2022-10-27 09:24:07 +00:00
|
|
|
language_id: None,
|
2022-07-30 03:55:59 +00:00
|
|
|
});
|
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> {
|
2022-10-27 09:24:07 +00:00
|
|
|
let name = Some("A jest test federated post, updated");
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new EditPost({
|
2020-08-04 14:57:37 +00:00
|
|
|
name,
|
2021-01-18 21:57:31 +00:00
|
|
|
post_id: post.id,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
nsfw: None,
|
|
|
|
url: None,
|
|
|
|
body: None,
|
2022-10-27 09:24:07 +00:00
|
|
|
language_id: None,
|
2022-07-30 03:55:59 +00:00
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new DeletePost({
|
2021-01-18 21:57:31 +00:00
|
|
|
post_id: post.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
deleted: deleted,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new RemovePost({
|
2021-01-18 21:57:31 +00:00
|
|
|
post_id: post.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
removed,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
reason: None,
|
|
|
|
});
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.removePost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-12-12 11:17:10 +00:00
|
|
|
export async function featurePost(
|
2020-08-04 14:57:37 +00:00
|
|
|
api: API,
|
2022-12-12 11:17:10 +00:00
|
|
|
featured: boolean,
|
2020-08-04 14:57:37 +00:00
|
|
|
post: Post
|
|
|
|
): Promise<PostResponse> {
|
2022-12-12 11:17:10 +00:00
|
|
|
let form = new FeaturePost({
|
2021-01-18 21:57:31 +00:00
|
|
|
post_id: post.id,
|
2022-12-12 11:17:10 +00:00
|
|
|
featured,
|
|
|
|
feature_type: PostFeatureType.Community,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
2022-12-12 11:17:10 +00:00
|
|
|
return api.client.featurePost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function lockPost(
|
|
|
|
api: API,
|
|
|
|
locked: boolean,
|
|
|
|
post: Post
|
|
|
|
): Promise<PostResponse> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new LockPost({
|
2021-01-18 21:57:31 +00:00
|
|
|
post_id: post.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
locked,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new ResolveObject({
|
2020-08-20 14:50:26 +00:00
|
|
|
q: post.ap_id,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth,
|
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new Search({
|
2020-11-10 16:53:35 +00:00
|
|
|
q: post.name,
|
2022-07-30 03:55:59 +00:00
|
|
|
type_: Some(SearchType.Posts),
|
|
|
|
sort: Some(SortType.TopAll),
|
|
|
|
community_id: None,
|
|
|
|
community_name: None,
|
|
|
|
creator_id: None,
|
|
|
|
listing_type: None,
|
|
|
|
page: None,
|
|
|
|
limit: None,
|
|
|
|
auth: api.auth,
|
|
|
|
});
|
2020-11-10 16:53:35 +00:00
|
|
|
return api.client.search(form);
|
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function getPost(
|
|
|
|
api: API,
|
|
|
|
post_id: number
|
|
|
|
): Promise<GetPostResponse> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new GetPost({
|
|
|
|
id: Some(post_id),
|
|
|
|
comment_id: None,
|
|
|
|
auth: api.auth,
|
|
|
|
});
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.getPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-07-30 03:55:59 +00:00
|
|
|
export async function getComments(
|
|
|
|
api: API,
|
|
|
|
post_id: number
|
|
|
|
): Promise<GetCommentsResponse> {
|
|
|
|
let form = new GetComments({
|
|
|
|
post_id: Some(post_id),
|
|
|
|
type_: Some(ListingType.All),
|
|
|
|
sort: Some(CommentSortType.New), // TODO this sort might be wrong
|
|
|
|
max_depth: None,
|
|
|
|
page: None,
|
|
|
|
limit: None,
|
|
|
|
community_id: None,
|
|
|
|
community_name: None,
|
|
|
|
saved_only: None,
|
|
|
|
parent_id: None,
|
|
|
|
auth: api.auth,
|
|
|
|
});
|
|
|
|
return api.client.getComments(form);
|
|
|
|
}
|
|
|
|
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new ResolveObject({
|
2020-08-20 14:50:26 +00:00
|
|
|
q: comment.ap_id,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth,
|
|
|
|
});
|
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
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new ResolveObject({
|
2022-10-27 09:24:07 +00:00
|
|
|
q: "!main@lemmy-beta:8551",
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth,
|
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new ResolveObject({
|
2020-09-15 19:26:47 +00:00
|
|
|
q,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth,
|
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new ResolveObject({
|
2020-08-20 14:50:26 +00:00
|
|
|
q: apShortname,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth,
|
|
|
|
});
|
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
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new BanPerson({
|
2021-03-12 19:09:03 +00:00
|
|
|
person_id,
|
2020-11-10 16:53:35 +00:00
|
|
|
ban,
|
2022-07-30 03:55:59 +00:00
|
|
|
remove_data: Some(remove_data),
|
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
reason: None,
|
|
|
|
expires: None,
|
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new BanFromCommunity({
|
2021-03-12 19:09:03 +00:00
|
|
|
person_id,
|
2020-11-10 16:53:35 +00:00
|
|
|
community_id,
|
2022-07-30 03:55:59 +00:00
|
|
|
remove_data: Some(remove_data),
|
2020-11-10 16:53:35 +00:00
|
|
|
ban,
|
2022-07-30 03:55:59 +00:00
|
|
|
reason: None,
|
|
|
|
expires: None,
|
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
2020-11-10 16:53:35 +00:00
|
|
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new FollowCommunity({
|
2020-08-04 14:57:37 +00:00
|
|
|
community_id,
|
|
|
|
follow,
|
2022-10-27 09:24:07 +00:00
|
|
|
auth: api.auth.unwrap(),
|
2022-07-30 03:55:59 +00:00
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new CreatePostLike({
|
2020-08-04 14:57:37 +00:00
|
|
|
post_id: post.id,
|
|
|
|
score: score,
|
2022-10-27 09:24:07 +00:00
|
|
|
auth: api.auth.unwrap(),
|
2022-07-30 03:55:59 +00:00
|
|
|
});
|
2020-08-04 14:57:37 +00:00
|
|
|
|
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,
|
2022-07-30 03:55:59 +00:00
|
|
|
parent_id: Option<number>,
|
2022-10-27 09:24:07 +00:00
|
|
|
content = "a jest test comment"
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<CommentResponse> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new CreateComment({
|
2020-08-04 14:57:37 +00:00
|
|
|
content,
|
|
|
|
post_id,
|
|
|
|
parent_id,
|
2022-07-30 03:55:59 +00:00
|
|
|
form_id: None,
|
2022-10-27 09:24:07 +00:00
|
|
|
language_id: None,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
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,
|
2022-10-27 09:24:07 +00:00
|
|
|
content = Some("A jest test federated comment update")
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<CommentResponse> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new EditComment({
|
2020-08-04 14:57:37 +00:00
|
|
|
content,
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id,
|
2022-07-30 03:55:59 +00:00
|
|
|
form_id: None,
|
2022-10-27 09:24:07 +00:00
|
|
|
language_id: None,
|
|
|
|
distinguished: None,
|
|
|
|
auth: api.auth.unwrap(),
|
2022-07-30 03:55:59 +00:00
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new DeleteComment({
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
deleted,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new RemoveComment({
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
removed,
|
2022-07-30 03:55:59 +00:00
|
|
|
reason: None,
|
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.removeComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
export async function getMentions(
|
|
|
|
api: API
|
|
|
|
): Promise<GetPersonMentionsResponse> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new GetPersonMentions({
|
|
|
|
sort: Some(CommentSortType.New),
|
|
|
|
unread_only: Some(false),
|
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
page: None,
|
|
|
|
limit: None,
|
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new CreateCommentLike({
|
2020-08-04 14:57:37 +00:00
|
|
|
comment_id: comment.id,
|
|
|
|
score,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
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> {
|
2022-10-27 09:24:07 +00:00
|
|
|
let description = Some("a sample description");
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new CreateCommunity({
|
2020-08-04 14:57:37 +00:00
|
|
|
name: name_,
|
|
|
|
title: name_,
|
2020-09-15 19:26:47 +00:00
|
|
|
description,
|
2022-07-30 03:55:59 +00:00
|
|
|
nsfw: None,
|
|
|
|
icon: None,
|
|
|
|
banner: None,
|
|
|
|
posting_restricted_to_mods: None,
|
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new GetCommunity({
|
|
|
|
id: Some(id),
|
|
|
|
name: None,
|
|
|
|
auth: api.auth,
|
|
|
|
});
|
2020-11-05 20:19:06 +00:00
|
|
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new DeleteCommunity({
|
2021-01-18 21:57:31 +00:00
|
|
|
community_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
deleted,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new RemoveCommunity({
|
2021-01-18 21:57:31 +00:00
|
|
|
community_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
removed,
|
2022-07-30 03:55:59 +00:00
|
|
|
reason: None,
|
|
|
|
expires: None,
|
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
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> {
|
2022-10-27 09:24:07 +00:00
|
|
|
let content = "A jest test federated private message";
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new CreatePrivateMessage({
|
2020-08-04 14:57:37 +00:00
|
|
|
content,
|
|
|
|
recipient_id,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
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> {
|
2022-10-27 09:24:07 +00:00
|
|
|
let updatedContent = "A jest test federated private message edited";
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new EditPrivateMessage({
|
2020-08-04 14:57:37 +00:00
|
|
|
content: updatedContent,
|
2021-01-18 21:57:31 +00:00
|
|
|
private_message_id,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new DeletePrivateMessage({
|
2020-08-04 14:57:37 +00:00
|
|
|
deleted,
|
2021-01-18 21:57:31 +00:00
|
|
|
private_message_id,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new 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,
|
2022-07-30 03:55:59 +00:00
|
|
|
email: None,
|
|
|
|
captcha_uuid: None,
|
|
|
|
captcha_answer: None,
|
|
|
|
honeypot: None,
|
|
|
|
answer: None,
|
|
|
|
});
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.register(form);
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
export async function saveUserSettingsBio(api: API): Promise<LoginResponse> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new SaveUserSettings({
|
|
|
|
show_nsfw: Some(true),
|
2022-10-27 09:24:07 +00:00
|
|
|
theme: Some("darkly"),
|
2022-07-30 03:55:59 +00:00
|
|
|
default_sort_type: Some(Object.keys(SortType).indexOf(SortType.Active)),
|
2022-10-27 09:24:07 +00:00
|
|
|
default_listing_type: Some(
|
|
|
|
Object.keys(ListingType).indexOf(ListingType.All)
|
|
|
|
),
|
|
|
|
interface_language: Some("en"),
|
2022-07-30 03:55:59 +00:00
|
|
|
show_avatars: Some(true),
|
|
|
|
send_notifications_to_email: Some(false),
|
2022-10-27 09:24:07 +00:00
|
|
|
bio: Some("a changed bio"),
|
2022-07-30 03:55:59 +00:00
|
|
|
avatar: None,
|
|
|
|
banner: None,
|
|
|
|
display_name: None,
|
|
|
|
email: None,
|
|
|
|
matrix_user_id: None,
|
|
|
|
show_scores: None,
|
|
|
|
show_read_posts: None,
|
|
|
|
show_bot_accounts: None,
|
|
|
|
show_new_post_notifs: None,
|
|
|
|
bot_account: None,
|
2022-10-27 09:24:07 +00:00
|
|
|
discussion_languages: None,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
2020-09-17 15:41:51 +00:00
|
|
|
return saveUserSettings(api, form);
|
|
|
|
}
|
|
|
|
|
2022-07-30 03:55:59 +00:00
|
|
|
export async function saveUserSettingsFederated(
|
|
|
|
api: API
|
|
|
|
): Promise<LoginResponse> {
|
2022-10-27 09:24:07 +00:00
|
|
|
let avatar = Some("https://image.flaticon.com/icons/png/512/35/35896.png");
|
|
|
|
let banner = Some("https://image.flaticon.com/icons/png/512/36/35896.png");
|
|
|
|
let bio = Some("a changed bio");
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new SaveUserSettings({
|
|
|
|
show_nsfw: Some(false),
|
2022-10-27 09:24:07 +00:00
|
|
|
theme: Some(""),
|
2022-07-30 03:55:59 +00:00
|
|
|
default_sort_type: Some(Object.keys(SortType).indexOf(SortType.Hot)),
|
2022-10-27 09:24:07 +00:00
|
|
|
default_listing_type: Some(
|
|
|
|
Object.keys(ListingType).indexOf(ListingType.All)
|
|
|
|
),
|
|
|
|
interface_language: Some(""),
|
2022-07-30 03:55:59 +00:00
|
|
|
avatar,
|
|
|
|
banner,
|
2022-10-27 09:24:07 +00:00
|
|
|
display_name: Some("user321"),
|
2022-07-30 03:55:59 +00:00
|
|
|
show_avatars: Some(false),
|
|
|
|
send_notifications_to_email: Some(false),
|
|
|
|
bio,
|
|
|
|
email: None,
|
|
|
|
show_scores: None,
|
|
|
|
show_read_posts: None,
|
|
|
|
matrix_user_id: None,
|
|
|
|
bot_account: None,
|
|
|
|
show_bot_accounts: None,
|
|
|
|
show_new_post_notifs: None,
|
2022-10-27 09:24:07 +00:00
|
|
|
discussion_languages: None,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
|
|
|
return await saveUserSettings(alpha, form);
|
|
|
|
}
|
|
|
|
|
2020-09-17 15:41:51 +00:00
|
|
|
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-10-27 09:24:07 +00:00
|
|
|
export async function deleteUser(api: API): Promise<DeleteAccountResponse> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new DeleteAccount({
|
|
|
|
auth: api.auth.unwrap(),
|
2022-10-27 09:24:07 +00:00
|
|
|
password,
|
2022-07-30 03:55:59 +00:00
|
|
|
});
|
2022-04-07 20:52:17 +00:00
|
|
|
return api.client.deleteAccount(form);
|
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
export async function getSite(api: API): Promise<GetSiteResponse> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new GetSite({
|
2021-08-19 20:54:15 +00:00
|
|
|
auth: api.auth,
|
2022-07-30 03:55:59 +00:00
|
|
|
});
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new GetPrivateMessages({
|
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
unread_only: Some(false),
|
|
|
|
page: None,
|
|
|
|
limit: None,
|
|
|
|
});
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.getPrivateMessages(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
export async function unfollowRemotes(api: API): 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);
|
2022-10-27 09:24:07 +00:00
|
|
|
let remoteFollowed = site.my_user
|
|
|
|
.unwrap()
|
|
|
|
.follows.filter(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;
|
2022-07-30 03:55:59 +00:00
|
|
|
if (betaCommunity.isSome()) {
|
2022-10-27 09:24:07 +00:00
|
|
|
let follow = await followCommunity(
|
|
|
|
api,
|
|
|
|
true,
|
|
|
|
betaCommunity.unwrap().community.id
|
|
|
|
);
|
2020-08-04 15:06:27 +00:00
|
|
|
return follow;
|
2022-07-30 03:55:59 +00:00
|
|
|
} else {
|
|
|
|
return Promise.reject("no community worked");
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new CreatePostReport({
|
2021-10-15 14:37:33 +00:00
|
|
|
post_id,
|
|
|
|
reason,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
2021-10-15 14:37:33 +00:00
|
|
|
return api.client.createPostReport(form);
|
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
export async function listPostReports(
|
|
|
|
api: API
|
|
|
|
): Promise<ListPostReportsResponse> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new ListPostReports({
|
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
page: None,
|
|
|
|
limit: None,
|
|
|
|
community_id: None,
|
|
|
|
unresolved_only: None,
|
|
|
|
});
|
2021-10-15 14:37:33 +00:00
|
|
|
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> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new CreateCommentReport({
|
2021-10-15 14:37:33 +00:00
|
|
|
comment_id,
|
|
|
|
reason,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
2021-10-15 14:37:33 +00:00
|
|
|
return api.client.createCommentReport(form);
|
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
export async function listCommentReports(
|
|
|
|
api: API
|
|
|
|
): Promise<ListCommentReportsResponse> {
|
2022-07-30 03:55:59 +00:00
|
|
|
let form = new ListCommentReports({
|
|
|
|
page: None,
|
|
|
|
limit: None,
|
|
|
|
community_id: None,
|
|
|
|
unresolved_only: None,
|
|
|
|
auth: api.auth.unwrap(),
|
|
|
|
});
|
2021-10-15 14:37:33 +00:00
|
|
|
return api.client.listCommentReports(form);
|
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
export function delay(millis = 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 {
|
2022-10-27 09:24:07 +00:00
|
|
|
var result = "";
|
|
|
|
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);
|
|
|
|
}
|
2022-07-30 03:55:59 +00:00
|
|
|
|
|
|
|
export function getCommentParentId(comment: Comment): Option<number> {
|
|
|
|
let split = comment.path.split(".");
|
|
|
|
// remove the 0
|
|
|
|
split.shift();
|
|
|
|
|
|
|
|
if (split.length > 1) {
|
|
|
|
return Some(Number(split[split.length - 2]));
|
|
|
|
} else {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
}
|