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,
|
2023-01-05 01:42:30 +00:00
|
|
|
RegistrationMode,
|
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;
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: 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"),
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: "",
|
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"),
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: "",
|
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"),
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: "",
|
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"),
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: "",
|
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"),
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: "",
|
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() {
|
2023-01-04 15:59:26 +00:00
|
|
|
let formAlpha: Login = {
|
2022-10-27 09:24:07 +00:00
|
|
|
username_or_email: "lemmy_alpha",
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resAlpha = alpha.client.login(formAlpha);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2023-01-04 15:59:26 +00:00
|
|
|
let formBeta: Login = {
|
2022-10-27 09:24:07 +00:00
|
|
|
username_or_email: "lemmy_beta",
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resBeta = beta.client.login(formBeta);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2023-01-04 15:59:26 +00:00
|
|
|
let formGamma: Login = {
|
2022-10-27 09:24:07 +00:00
|
|
|
username_or_email: "lemmy_gamma",
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resGamma = gamma.client.login(formGamma);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2023-01-04 15:59:26 +00:00
|
|
|
let formDelta: Login = {
|
2022-10-27 09:24:07 +00:00
|
|
|
username_or_email: "lemmy_delta",
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resDelta = delta.client.login(formDelta);
|
2020-08-20 12:44:22 +00:00
|
|
|
|
2023-01-04 15:59:26 +00:00
|
|
|
let formEpsilon: Login = {
|
2022-10-27 09:24:07 +00:00
|
|
|
username_or_email: "lemmy_epsilon",
|
2021-09-19 21:20:47 +00:00
|
|
|
password,
|
2023-01-04 15:59:26 +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,
|
|
|
|
]);
|
|
|
|
|
2023-01-04 15:59:26 +00:00
|
|
|
alpha.auth = res[0].jwt ?? "";
|
|
|
|
beta.auth = res[1].jwt ?? "";
|
|
|
|
gamma.auth = res[2].jwt ?? "";
|
|
|
|
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
|
2023-01-04 15:59:26 +00:00
|
|
|
let editSiteForm: EditSite = {
|
2023-01-05 01:42:30 +00:00
|
|
|
registration_mode: RegistrationMode.Open,
|
2023-01-04 15:59:26 +00:00
|
|
|
rate_limit_message: 999,
|
|
|
|
rate_limit_post: 999,
|
|
|
|
rate_limit_register: 999,
|
|
|
|
rate_limit_image: 999,
|
|
|
|
rate_limit_comment: 999,
|
|
|
|
rate_limit_search: 999,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: "",
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2022-10-27 09:24:07 +00:00
|
|
|
|
|
|
|
// Set the blocks and auths for each
|
2023-01-04 15:59:26 +00:00
|
|
|
editSiteForm.auth = alpha.auth;
|
|
|
|
editSiteForm.allowed_instances = [
|
2022-10-27 09:24:07 +00:00
|
|
|
"lemmy-beta",
|
|
|
|
"lemmy-gamma",
|
|
|
|
"lemmy-delta",
|
|
|
|
"lemmy-epsilon",
|
2023-01-04 15:59:26 +00:00
|
|
|
];
|
2022-07-30 03:55:59 +00:00
|
|
|
await alpha.client.editSite(editSiteForm);
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2023-01-04 15:59:26 +00:00
|
|
|
editSiteForm.auth = beta.auth;
|
|
|
|
editSiteForm.allowed_instances = [
|
2022-10-27 09:24:07 +00:00
|
|
|
"lemmy-alpha",
|
|
|
|
"lemmy-gamma",
|
|
|
|
"lemmy-delta",
|
|
|
|
"lemmy-epsilon",
|
2023-01-04 15:59:26 +00:00
|
|
|
];
|
2022-07-30 03:55:59 +00:00
|
|
|
await beta.client.editSite(editSiteForm);
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2023-01-04 15:59:26 +00:00
|
|
|
editSiteForm.auth = gamma.auth;
|
|
|
|
editSiteForm.allowed_instances = [
|
2022-10-27 09:24:07 +00:00
|
|
|
"lemmy-alpha",
|
|
|
|
"lemmy-beta",
|
|
|
|
"lemmy-delta",
|
|
|
|
"lemmy-epsilon",
|
2023-01-04 15:59:26 +00:00
|
|
|
];
|
2022-07-30 03:55:59 +00:00
|
|
|
await gamma.client.editSite(editSiteForm);
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2023-01-04 15:59:26 +00:00
|
|
|
editSiteForm.allowed_instances = ["lemmy-beta"];
|
|
|
|
editSiteForm.auth = delta.auth;
|
2022-07-30 03:55:59 +00:00
|
|
|
await delta.client.editSite(editSiteForm);
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2023-01-04 15:59:26 +00:00
|
|
|
editSiteForm.auth = epsilon.auth;
|
|
|
|
editSiteForm.allowed_instances = [];
|
|
|
|
editSiteForm.blocked_instances = ["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);
|
2023-01-04 15:59:26 +00:00
|
|
|
let body = randomString(10);
|
|
|
|
let url = "https://google.com/";
|
|
|
|
let form: CreatePost = {
|
2020-08-04 14:57:37 +00:00
|
|
|
name,
|
2020-09-15 19:26:47 +00:00
|
|
|
url,
|
|
|
|
body,
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: api.auth,
|
2020-08-04 14:57:37 +00:00
|
|
|
community_id,
|
2023-01-04 15:59:26 +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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let name = "A jest test federated post, updated";
|
|
|
|
let form: EditPost = {
|
2020-08-04 14:57:37 +00:00
|
|
|
name,
|
2021-01-18 21:57:31 +00:00
|
|
|
post_id: post.id,
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +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,
|
2023-01-04 15:59:26 +00:00
|
|
|
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> {
|
2023-01-04 15:59:26 +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,
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: 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,
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +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,
|
2023-01-04 15:59:26 +00:00
|
|
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: ResolveObject = {
|
2020-08-20 14:50:26 +00:00
|
|
|
q: post.ap_id,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: Search = {
|
2020-11-10 16:53:35 +00:00
|
|
|
q: post.name,
|
2023-01-04 15:59:26 +00:00
|
|
|
type_: SearchType.Posts,
|
|
|
|
sort: SortType.TopAll,
|
|
|
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: GetPost = {
|
|
|
|
id: post_id,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: GetComments = {
|
|
|
|
post_id: post_id,
|
|
|
|
type_: ListingType.All,
|
|
|
|
sort: CommentSortType.New,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2022-07-30 03:55:59 +00:00
|
|
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: ResolveObject = {
|
2020-08-20 14:50:26 +00:00
|
|
|
q: comment.ap_id,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth,
|
2023-01-04 15:59: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 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
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: 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,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: ResolveObject = {
|
2020-09-15 19:26:47 +00:00
|
|
|
q,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth,
|
2023-01-04 15:59: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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: ResolveObject = {
|
2020-08-20 14:50:26 +00:00
|
|
|
q: apShortname,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
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
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: BanPerson = {
|
2021-03-12 19:09:03 +00:00
|
|
|
person_id,
|
2020-11-10 16:53:35 +00:00
|
|
|
ban,
|
2023-01-04 15:59:26 +00:00
|
|
|
remove_data: remove_data,
|
|
|
|
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> {
|
2023-01-04 15:59:26 +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,
|
2023-01-04 15:59:26 +00:00
|
|
|
remove_data: remove_data,
|
2020-11-10 16:53:35 +00:00
|
|
|
ban,
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: FollowCommunity = {
|
2020-08-04 14:57:37 +00:00
|
|
|
community_id,
|
|
|
|
follow,
|
2023-01-04 15:59:26 +00:00
|
|
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: CreatePostLike = {
|
2020-08-04 14:57:37 +00:00
|
|
|
post_id: post.id,
|
|
|
|
score: score,
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
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,
|
2023-01-04 15:59:26 +00:00
|
|
|
parent_id?: number,
|
2022-10-27 09:24:07 +00:00
|
|
|
content = "a jest test comment"
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<CommentResponse> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: CreateComment = {
|
2020-08-04 14:57:37 +00:00
|
|
|
content,
|
|
|
|
post_id,
|
|
|
|
parent_id,
|
2023-01-04 15:59:26 +00:00
|
|
|
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,
|
2023-01-04 15:59:26 +00:00
|
|
|
content = "A jest test federated comment update"
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<CommentResponse> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: EditComment = {
|
2020-08-04 14:57:37 +00:00
|
|
|
content,
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id,
|
2023-01-04 15:59:26 +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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: DeleteComment = {
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
deleted,
|
2023-01-04 15:59:26 +00:00
|
|
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: RemoveComment = {
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
removed,
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: GetPersonMentions = {
|
|
|
|
sort: CommentSortType.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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: CreateCommentLike = {
|
2020-08-04 14:57:37 +00:00
|
|
|
comment_id: comment.id,
|
|
|
|
score,
|
2023-01-04 15:59:26 +00:00
|
|
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let description = "a sample description";
|
|
|
|
let form: CreateCommunity = {
|
2020-08-04 14:57:37 +00:00
|
|
|
name: name_,
|
|
|
|
title: name_,
|
2020-09-15 19:26:47 +00:00
|
|
|
description,
|
2023-01-04 15:59:26 +00:00
|
|
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: GetCommunity = {
|
|
|
|
id,
|
2022-07-30 03:55:59 +00:00
|
|
|
auth: api.auth,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: DeleteCommunity = {
|
2021-01-18 21:57:31 +00:00
|
|
|
community_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
deleted,
|
2023-01-04 15:59:26 +00:00
|
|
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: RemoveCommunity = {
|
2021-01-18 21:57:31 +00:00
|
|
|
community_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
removed,
|
2023-01-04 15:59:26 +00:00
|
|
|
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> {
|
2022-10-27 09:24:07 +00:00
|
|
|
let content = "A jest test federated private message";
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: CreatePrivateMessage = {
|
2020-08-04 14:57:37 +00:00
|
|
|
content,
|
|
|
|
recipient_id,
|
2023-01-04 15:59:26 +00:00
|
|
|
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> {
|
2022-10-27 09:24:07 +00:00
|
|
|
let updatedContent = "A jest test federated private message edited";
|
2023-01-04 15:59:26 +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,
|
2023-01-04 15:59:26 +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> {
|
2023-01-04 15:59:26 +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,
|
2023-01-04 15:59:26 +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> {
|
2023-01-04 15:59:26 +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,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: SaveUserSettings = {
|
|
|
|
show_nsfw: true,
|
|
|
|
theme: "darkly",
|
2023-04-17 19:19:51 +00:00
|
|
|
default_sort_type: SortType.Active,
|
|
|
|
default_listing_type: ListingType.All,
|
2023-01-04 15:59:26 +00:00
|
|
|
interface_language: "en",
|
|
|
|
show_avatars: true,
|
|
|
|
send_notifications_to_email: false,
|
|
|
|
bio: "a changed bio",
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let avatar = "https://image.flaticon.com/icons/png/512/35/35896.png";
|
|
|
|
let banner = "https://image.flaticon.com/icons/png/512/36/35896.png";
|
|
|
|
let bio = "a changed bio";
|
|
|
|
let form: SaveUserSettings = {
|
|
|
|
show_nsfw: false,
|
2023-04-17 19:19:51 +00:00
|
|
|
default_sort_type: SortType.Hot,
|
|
|
|
default_listing_type: ListingType.All,
|
2023-01-04 15:59:26 +00:00
|
|
|
interface_language: "",
|
2022-07-30 03:55:59 +00:00
|
|
|
avatar,
|
|
|
|
banner,
|
2023-01-04 15:59:26 +00:00
|
|
|
display_name: "user321",
|
|
|
|
show_avatars: false,
|
|
|
|
send_notifications_to_email: false,
|
2022-07-30 03:55:59 +00:00
|
|
|
bio,
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
2022-07-30 03:55:59 +00:00
|
|
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: DeleteAccount = {
|
|
|
|
auth: api.auth,
|
2022-10-27 09:24:07 +00:00
|
|
|
password,
|
2023-01-04 15:59:26 +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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: GetSite = {
|
2021-08-19 20:54:15 +00:00
|
|
|
auth: api.auth,
|
2023-01-04 15:59:26 +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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: GetPrivateMessages = {
|
|
|
|
auth: api.auth,
|
|
|
|
unread_only: false,
|
|
|
|
};
|
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);
|
2023-01-04 15:59:26 +00:00
|
|
|
let remoteFollowed =
|
|
|
|
site.my_user?.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;
|
2023-01-04 15:59:26 +00:00
|
|
|
if (betaCommunity) {
|
|
|
|
let follow = await followCommunity(api, true, betaCommunity.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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: CreatePostReport = {
|
2021-10-15 14:37:33 +00:00
|
|
|
post_id,
|
|
|
|
reason,
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: ListPostReports = {
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: CreateCommentReport = {
|
2021-10-15 14:37:33 +00:00
|
|
|
comment_id,
|
|
|
|
reason,
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
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> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: ListCommentReports = {
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
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
|
|
|
|
2023-01-04 15:59:26 +00:00
|
|
|
export function getCommentParentId(comment: Comment): number | undefined {
|
2022-07-30 03:55:59 +00:00
|
|
|
let split = comment.path.split(".");
|
|
|
|
// remove the 0
|
|
|
|
split.shift();
|
|
|
|
|
|
|
|
if (split.length > 1) {
|
2023-01-04 15:59:26 +00:00
|
|
|
return Number(split[split.length - 2]);
|
2022-07-30 03:55:59 +00:00
|
|
|
} else {
|
2023-01-04 15:59:26 +00:00
|
|
|
return undefined;
|
2022-07-30 03:55:59 +00:00
|
|
|
}
|
|
|
|
}
|