2023-04-26 04:26:10 +00:00
|
|
|
import { LemmyHttp } from "lemmy-js-client";
|
|
|
|
import { CreatePost } from "lemmy-js-client/dist/types/CreatePost";
|
|
|
|
import { DeletePost } from "lemmy-js-client/dist/types/DeletePost";
|
|
|
|
import { EditPost } from "lemmy-js-client/dist/types/EditPost";
|
|
|
|
import { EditSite } from "lemmy-js-client/dist/types/EditSite";
|
|
|
|
import { FeaturePost } from "lemmy-js-client/dist/types/FeaturePost";
|
|
|
|
import { GetComments } from "lemmy-js-client/dist/types/GetComments";
|
|
|
|
import { GetCommentsResponse } from "lemmy-js-client/dist/types/GetCommentsResponse";
|
|
|
|
import { GetPost } from "lemmy-js-client/dist/types/GetPost";
|
|
|
|
import { GetPostResponse } from "lemmy-js-client/dist/types/GetPostResponse";
|
|
|
|
import { LockPost } from "lemmy-js-client/dist/types/LockPost";
|
|
|
|
import { Login } from "lemmy-js-client/dist/types/Login";
|
|
|
|
import { Post } from "lemmy-js-client/dist/types/Post";
|
|
|
|
import { PostResponse } from "lemmy-js-client/dist/types/PostResponse";
|
|
|
|
import { RemovePost } from "lemmy-js-client/dist/types/RemovePost";
|
|
|
|
import { ResolveObject } from "lemmy-js-client/dist/types/ResolveObject";
|
|
|
|
import { ResolveObjectResponse } from "lemmy-js-client/dist/types/ResolveObjectResponse";
|
|
|
|
import { Search } from "lemmy-js-client/dist/types/Search";
|
|
|
|
import { SearchResponse } from "lemmy-js-client/dist/types/SearchResponse";
|
|
|
|
import { Comment } from "lemmy-js-client/dist/types/Comment";
|
|
|
|
import { BanPersonResponse } from "lemmy-js-client/dist/types/BanPersonResponse";
|
|
|
|
import { BanPerson } from "lemmy-js-client/dist/types/BanPerson";
|
|
|
|
import { BanFromCommunityResponse } from "lemmy-js-client/dist/types/BanFromCommunityResponse";
|
|
|
|
import { BanFromCommunity } from "lemmy-js-client/dist/types/BanFromCommunity";
|
|
|
|
import { CommunityResponse } from "lemmy-js-client/dist/types/CommunityResponse";
|
|
|
|
import { FollowCommunity } from "lemmy-js-client/dist/types/FollowCommunity";
|
|
|
|
import { CreatePostLike } from "lemmy-js-client/dist/types/CreatePostLike";
|
|
|
|
import { CommentResponse } from "lemmy-js-client/dist/types/CommentResponse";
|
|
|
|
import { CreateComment } from "lemmy-js-client/dist/types/CreateComment";
|
|
|
|
import { EditComment } from "lemmy-js-client/dist/types/EditComment";
|
|
|
|
import { DeleteComment } from "lemmy-js-client/dist/types/DeleteComment";
|
|
|
|
import { RemoveComment } from "lemmy-js-client/dist/types/RemoveComment";
|
|
|
|
import { GetPersonMentionsResponse } from "lemmy-js-client/dist/types/GetPersonMentionsResponse";
|
|
|
|
import { GetPersonMentions } from "lemmy-js-client/dist/types/GetPersonMentions";
|
|
|
|
import { CreateCommentLike } from "lemmy-js-client/dist/types/CreateCommentLike";
|
|
|
|
import { CreateCommunity } from "lemmy-js-client/dist/types/CreateCommunity";
|
|
|
|
import { GetCommunity } from "lemmy-js-client/dist/types/GetCommunity";
|
|
|
|
import { DeleteCommunity } from "lemmy-js-client/dist/types/DeleteCommunity";
|
|
|
|
import { RemoveCommunity } from "lemmy-js-client/dist/types/RemoveCommunity";
|
|
|
|
import { PrivateMessageResponse } from "lemmy-js-client/dist/types/PrivateMessageResponse";
|
|
|
|
import { CreatePrivateMessage } from "lemmy-js-client/dist/types/CreatePrivateMessage";
|
|
|
|
import { EditPrivateMessage } from "lemmy-js-client/dist/types/EditPrivateMessage";
|
|
|
|
import { DeletePrivateMessage } from "lemmy-js-client/dist/types/DeletePrivateMessage";
|
|
|
|
import { LoginResponse } from "lemmy-js-client/dist/types/LoginResponse";
|
|
|
|
import { Register } from "lemmy-js-client/dist/types/Register";
|
|
|
|
import { SaveUserSettings } from "lemmy-js-client/dist/types/SaveUserSettings";
|
|
|
|
import { DeleteAccount } from "lemmy-js-client/dist/types/DeleteAccount";
|
|
|
|
import { GetSiteResponse } from "lemmy-js-client/dist/types/GetSiteResponse";
|
|
|
|
import { DeleteAccountResponse } from "lemmy-js-client/dist/types/DeleteAccountResponse";
|
|
|
|
import { GetSite } from "lemmy-js-client/dist/types/GetSite";
|
|
|
|
import { PrivateMessagesResponse } from "lemmy-js-client/dist/types/PrivateMessagesResponse";
|
|
|
|
import { GetPrivateMessages } from "lemmy-js-client/dist/types/GetPrivateMessages";
|
|
|
|
import { PostReportResponse } from "lemmy-js-client/dist/types/PostReportResponse";
|
|
|
|
import { CreatePostReport } from "lemmy-js-client/dist/types/CreatePostReport";
|
|
|
|
import { ListPostReportsResponse } from "lemmy-js-client/dist/types/ListPostReportsResponse";
|
|
|
|
import { ListPostReports } from "lemmy-js-client/dist/types/ListPostReports";
|
|
|
|
import { CommentReportResponse } from "lemmy-js-client/dist/types/CommentReportResponse";
|
|
|
|
import { CreateCommentReport } from "lemmy-js-client/dist/types/CreateCommentReport";
|
|
|
|
import { ListCommentReportsResponse } from "lemmy-js-client/dist/types/ListCommentReportsResponse";
|
|
|
|
import { ListCommentReports } from "lemmy-js-client/dist/types/ListCommentReports";
|
2023-07-26 17:51:11 +00:00
|
|
|
import { GetPostsResponse } from "lemmy-js-client/dist/types/GetPostsResponse";
|
|
|
|
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
|
2023-07-20 14:36:16 +00:00
|
|
|
import { GetPersonDetailsResponse } from "lemmy-js-client/dist/types/GetPersonDetailsResponse";
|
|
|
|
import { GetPersonDetails } from "lemmy-js-client/dist/types/GetPersonDetails";
|
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-04-26 04:26:10 +00:00
|
|
|
registration_mode: "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
|
2023-07-21 09:47:56 +00:00
|
|
|
// Ignore thrown errors of duplicates
|
|
|
|
try {
|
|
|
|
await createCommunity(alpha, "main");
|
|
|
|
await createCommunity(beta, "main");
|
|
|
|
} catch (_) {}
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createPost(
|
|
|
|
api: API,
|
2023-07-06 13:10:38 +00:00
|
|
|
community_id: number,
|
2020-08-04 14:57:37 +00:00
|
|
|
): 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,
|
2023-07-06 13:10:38 +00:00
|
|
|
post: Post,
|
2020-08-04 14:57:37 +00:00
|
|
|
): 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,
|
2023-07-06 13:10:38 +00:00
|
|
|
post: Post,
|
2020-08-04 14:57:37 +00:00
|
|
|
): 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,
|
2023-07-06 13:10:38 +00:00
|
|
|
post: Post,
|
2020-08-04 14:57:37 +00:00
|
|
|
): 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,
|
2023-04-26 04:26:10 +00:00
|
|
|
feature_type: "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,
|
2023-07-06 13:10:38 +00:00
|
|
|
post: Post,
|
2020-08-04 14:57:37 +00:00
|
|
|
): 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,
|
2023-07-06 13:10:38 +00:00
|
|
|
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,
|
2023-07-06 13:10:38 +00:00
|
|
|
post: Post,
|
2020-11-10 16:53:35 +00:00
|
|
|
): 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-04-26 04:26:10 +00:00
|
|
|
type_: "Posts",
|
|
|
|
sort: "TopAll",
|
2023-01-04 15:59:26 +00:00
|
|
|
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,
|
2023-07-06 13:10:38 +00:00
|
|
|
post_id: number,
|
2020-08-04 14:57:37 +00:00
|
|
|
): 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,
|
2023-07-06 13:10:38 +00:00
|
|
|
post_id: number,
|
2022-07-30 03:55:59 +00:00
|
|
|
): Promise<GetCommentsResponse> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: GetComments = {
|
|
|
|
post_id: post_id,
|
2023-04-26 04:26:10 +00:00
|
|
|
type_: "All",
|
|
|
|
sort: "New",
|
2023-01-04 15:59:26 +00:00
|
|
|
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,
|
2023-07-06 13:10:38 +00:00
|
|
|
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(
|
2023-07-06 13:10:38 +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,
|
2023-07-06 13:10:38 +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,
|
2023-07-06 13:10:38 +00:00
|
|
|
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,
|
2023-07-06 13:10:38 +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,
|
2023-07-06 13:10:38 +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,
|
2023-07-06 13:10:38 +00:00
|
|
|
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,
|
2023-07-06 13:10:38 +00:00
|
|
|
post: Post,
|
2020-08-04 14:57:37 +00:00
|
|
|
): 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,
|
2023-07-06 13:10:38 +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-07-06 13:10:38 +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,
|
2023-07-06 13:10:38 +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,
|
2023-07-06 13:10:38 +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(
|
2023-07-06 13:10:38 +00:00
|
|
|
api: API,
|
2022-10-27 09:24:07 +00:00
|
|
|
): Promise<GetPersonMentionsResponse> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: GetPersonMentions = {
|
2023-04-26 04:26:10 +00:00
|
|
|
sort: "New",
|
2023-01-04 15:59:26 +00:00
|
|
|
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,
|
2023-07-06 13:10:38 +00:00
|
|
|
comment: Comment,
|
2020-08-04 14:57:37 +00:00
|
|
|
): 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,
|
2023-07-06 13:10:38 +00:00
|
|
|
name_: string = randomString(5),
|
2020-08-04 14:57:37 +00:00
|
|
|
): 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,
|
2023-07-06 13:10:38 +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,
|
2023-07-06 13:10:38 +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,
|
2023-07-06 13:10:38 +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,
|
2023-07-06 13:10:38 +00:00
|
|
|
recipient_id: number,
|
2020-08-04 14:57:37 +00:00
|
|
|
): 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,
|
2023-07-06 13:10:38 +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,
|
2023-07-06 13:10:38 +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,
|
2023-07-06 13:10:38 +00:00
|
|
|
username: string = randomString(5),
|
2020-08-04 15:06:27 +00:00
|
|
|
): 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,
|
2023-07-26 11:53:45 +00:00
|
|
|
blur_nsfw: false,
|
|
|
|
auto_expand: true,
|
2023-01-04 15:59:26 +00:00
|
|
|
theme: "darkly",
|
2023-04-26 04:26:10 +00:00
|
|
|
default_sort_type: "Active",
|
|
|
|
default_listing_type: "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(
|
2023-07-06 13:10:38 +00:00
|
|
|
api: API,
|
2022-07-30 03:55:59 +00:00
|
|
|
): 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-07-26 11:53:45 +00:00
|
|
|
blur_nsfw: true,
|
|
|
|
auto_expand: false,
|
2023-04-26 04:26:10 +00:00
|
|
|
default_sort_type: "Hot",
|
|
|
|
default_listing_type: "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,
|
2023-07-06 13:10:38 +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
|
|
|
}
|
2023-07-20 14:36:16 +00:00
|
|
|
export async function getPersonDetails(
|
|
|
|
api: API,
|
|
|
|
person_id: number,
|
|
|
|
): Promise<GetPersonDetailsResponse> {
|
|
|
|
let form: GetPersonDetails = {
|
|
|
|
auth: api.auth,
|
|
|
|
person_id: person_id,
|
|
|
|
};
|
|
|
|
return api.client.getPersonDetails(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(
|
2023-07-06 13:10:38 +00:00
|
|
|
api: API,
|
2020-08-04 14:57:37 +00:00
|
|
|
): 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,
|
2023-07-06 13:10:38 +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(
|
2023-07-06 13:10:38 +00:00
|
|
|
api: API,
|
2022-10-27 09:24:07 +00:00
|
|
|
): 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,
|
2023-07-06 13:10:38 +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(
|
2023-07-06 13:10:38 +00:00
|
|
|
api: API,
|
2022-10-27 09:24:07 +00:00
|
|
|
): 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);
|
2023-07-26 17:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getPosts(
|
|
|
|
api: API,
|
|
|
|
moderator_view = false,
|
|
|
|
): Promise<GetPostsResponse> {
|
|
|
|
let form: GetPosts = {
|
|
|
|
moderator_view,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
|
|
|
return api.client.getPosts(form);
|
2021-10-15 14:37:33 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|