2023-08-01 13:14:40 +00:00
|
|
|
import {
|
2023-11-09 11:03:25 +00:00
|
|
|
BlockCommunity,
|
|
|
|
BlockCommunityResponse,
|
2023-09-20 09:56:13 +00:00
|
|
|
BlockInstance,
|
2023-10-20 00:15:55 +00:00
|
|
|
BlockInstanceResponse,
|
2023-11-09 11:03:25 +00:00
|
|
|
CommunityId,
|
2023-12-18 09:25:05 +00:00
|
|
|
CreatePrivateMessageReport,
|
2024-03-26 16:06:11 +00:00
|
|
|
DeleteImage,
|
2024-01-25 16:04:25 +00:00
|
|
|
EditCommunity,
|
2023-08-01 13:14:40 +00:00
|
|
|
GetReplies,
|
|
|
|
GetRepliesResponse,
|
|
|
|
GetUnreadCountResponse,
|
2023-09-20 09:56:13 +00:00
|
|
|
InstanceId,
|
2023-08-01 13:14:40 +00:00
|
|
|
LemmyHttp,
|
2023-09-20 10:46:25 +00:00
|
|
|
PostView,
|
2023-12-18 09:25:05 +00:00
|
|
|
PrivateMessageReportResponse,
|
2023-11-17 04:43:40 +00:00
|
|
|
SuccessResponse,
|
2023-08-01 13:14:40 +00:00
|
|
|
} from "lemmy-js-client";
|
2023-04-26 04:26:10 +00:00
|
|
|
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";
|
2023-10-20 00:15:55 +00:00
|
|
|
import { BanPersonResponse } from "lemmy-js-client/dist/types/BanPersonResponse";
|
2023-04-26 04:26:10 +00:00
|
|
|
import { BanPerson } from "lemmy-js-client/dist/types/BanPerson";
|
2023-10-20 00:15:55 +00:00
|
|
|
import { BanFromCommunityResponse } from "lemmy-js-client/dist/types/BanFromCommunityResponse";
|
2023-04-26 04:26:10 +00:00
|
|
|
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 { 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";
|
2023-08-31 11:07:45 +00:00
|
|
|
import { ListingType } from "lemmy-js-client/dist/types/ListingType";
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2023-11-24 09:29:41 +00:00
|
|
|
export const fetchFunction = fetch;
|
2024-03-26 16:06:11 +00:00
|
|
|
export const imageFetchLimit = 50;
|
2023-11-24 09:29:41 +00:00
|
|
|
|
2023-09-21 10:42:28 +00:00
|
|
|
export let alphaUrl = "http://127.0.0.1:8541";
|
|
|
|
export let betaUrl = "http://127.0.0.1:8551";
|
|
|
|
export let gammaUrl = "http://127.0.0.1:8561";
|
|
|
|
export let deltaUrl = "http://127.0.0.1:8571";
|
|
|
|
export let epsilonUrl = "http://127.0.0.1:8581";
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2023-11-24 09:29:41 +00:00
|
|
|
export let alpha = new LemmyHttp(alphaUrl, { fetchFunction });
|
|
|
|
export let alphaImage = new LemmyHttp(alphaUrl);
|
|
|
|
export let beta = new LemmyHttp(betaUrl, { fetchFunction });
|
|
|
|
export let gamma = new LemmyHttp(gammaUrl, { fetchFunction });
|
|
|
|
export let delta = new LemmyHttp(deltaUrl, { fetchFunction });
|
|
|
|
export let epsilon = new LemmyHttp(epsilonUrl, { fetchFunction });
|
2020-08-20 12:44:22 +00:00
|
|
|
|
2023-10-16 10:03:49 +00:00
|
|
|
export let betaAllowedInstances = [
|
|
|
|
"lemmy-alpha",
|
|
|
|
"lemmy-gamma",
|
|
|
|
"lemmy-delta",
|
|
|
|
"lemmy-epsilon",
|
|
|
|
];
|
|
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
let resAlpha = alpha.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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
let resBeta = beta.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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
let resGamma = gamma.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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
let resDelta = delta.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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
let resEpsilon = epsilon.login(formEpsilon);
|
2020-08-20 12:44:22 +00:00
|
|
|
|
|
|
|
let res = await Promise.all([
|
|
|
|
resAlpha,
|
|
|
|
resBeta,
|
|
|
|
resGamma,
|
|
|
|
resDelta,
|
|
|
|
resEpsilon,
|
|
|
|
]);
|
2023-09-25 10:37:45 +00:00
|
|
|
alpha.setHeaders({ Authorization: `Bearer ${res[0].jwt ?? ""}` });
|
2023-11-24 09:29:41 +00:00
|
|
|
alphaImage.setHeaders({ Authorization: `Bearer ${res[0].jwt ?? ""}` });
|
2023-09-25 10:37:45 +00:00
|
|
|
beta.setHeaders({ Authorization: `Bearer ${res[1].jwt ?? ""}` });
|
2023-09-25 11:18:06 +00:00
|
|
|
gamma.setHeaders({ Authorization: `Bearer ${res[2].jwt ?? ""}` });
|
2023-09-25 10:37:45 +00:00
|
|
|
delta.setHeaders({ Authorization: `Bearer ${res[3].jwt ?? ""}` });
|
|
|
|
epsilon.setHeaders({ Authorization: `Bearer ${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-10-27 09:24:07 +00:00
|
|
|
|
|
|
|
// Set the blocks and auths for each
|
2023-01-04 15:59:26 +00:00
|
|
|
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
|
|
|
];
|
2023-09-21 10:42:28 +00:00
|
|
|
await alpha.editSite(editSiteForm);
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2023-10-16 10:03:49 +00:00
|
|
|
editSiteForm.allowed_instances = betaAllowedInstances;
|
2023-09-21 10:42:28 +00:00
|
|
|
await beta.editSite(editSiteForm);
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2023-01-04 15:59:26 +00:00
|
|
|
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
|
|
|
];
|
2023-09-21 10:42:28 +00:00
|
|
|
await gamma.editSite(editSiteForm);
|
2022-10-27 09:24:07 +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");
|
2023-09-09 16:25:03 +00:00
|
|
|
// wait for > INSTANCES_RECHECK_DELAY to ensure federation is initialized
|
|
|
|
// otherwise the first few federated events may be missed
|
|
|
|
// (because last_successful_id is set to current id when federation to an instance is first started)
|
|
|
|
// only needed the first time so do in this try
|
2023-09-18 18:39:09 +00:00
|
|
|
await delay(10_000);
|
2023-08-31 11:07:45 +00:00
|
|
|
} catch (_) {
|
|
|
|
console.log("Communities already exist");
|
|
|
|
}
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createPost(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2023-07-06 13:10:38 +00:00
|
|
|
community_id: number,
|
2023-11-22 15:15:06 +00:00
|
|
|
url: string = "https://example.com/",
|
2024-01-25 14:22:11 +00:00
|
|
|
body = randomString(10),
|
2024-01-15 14:33:39 +00:00
|
|
|
// use example.com for consistent title and embed description
|
|
|
|
name: string = randomString(5),
|
2024-03-05 10:34:57 +00:00
|
|
|
alt_text = randomString(10),
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<PostResponse> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: CreatePost = {
|
2020-08-04 14:57:37 +00:00
|
|
|
name,
|
2020-09-15 19:26:47 +00:00
|
|
|
url,
|
|
|
|
body,
|
2024-03-05 10:34:57 +00:00
|
|
|
alt_text,
|
2020-08-04 14:57:37 +00:00
|
|
|
community_id,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.createPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 10:42:28 +00:00
|
|
|
export async function editPost(
|
|
|
|
api: LemmyHttp,
|
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.editPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2024-04-10 14:59:46 +00:00
|
|
|
export async function editPostThumbnail(
|
|
|
|
api: LemmyHttp,
|
|
|
|
post: Post,
|
|
|
|
customThumbnail: string,
|
|
|
|
): Promise<PostResponse> {
|
|
|
|
let form: EditPost = {
|
|
|
|
post_id: post.id,
|
|
|
|
custom_thumbnail: customThumbnail,
|
|
|
|
};
|
|
|
|
return api.editPost(form);
|
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function deletePost(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.deletePost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function removePost(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.removePost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-12-12 11:17:10 +00:00
|
|
|
export async function featurePost(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.featurePost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function lockPost(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.lockPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
export async function resolvePost(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.resolveObject(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 16:53:35 +00:00
|
|
|
export async function searchPostLocal(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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-11-22 14:41:52 +00:00
|
|
|
listing_type: "All",
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.search(form);
|
2020-11-10 16:53:35 +00:00
|
|
|
}
|
|
|
|
|
2023-09-20 10:46:25 +00:00
|
|
|
/// wait for a post to appear locally without pulling it
|
|
|
|
export async function waitForPost(
|
2023-09-21 12:32:41 +00:00
|
|
|
api: LemmyHttp,
|
2023-09-20 10:46:25 +00:00
|
|
|
post: Post,
|
2023-09-20 11:21:47 +00:00
|
|
|
checker: (t: PostView | undefined) => boolean = p => !!p,
|
2023-09-20 10:46:25 +00:00
|
|
|
) {
|
2023-09-20 11:21:47 +00:00
|
|
|
return waitUntil<PostView>(
|
|
|
|
() => searchPostLocal(api, post).then(p => p.posts[0]),
|
2023-09-20 10:46:25 +00:00
|
|
|
checker,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function getPost(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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,
|
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.getPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-07-30 03:55:59 +00:00
|
|
|
export async function getComments(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2023-08-31 11:07:45 +00:00
|
|
|
post_id?: number,
|
|
|
|
listingType: ListingType = "All",
|
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-08-31 11:07:45 +00:00
|
|
|
type_: listingType,
|
2023-04-26 04:26:10 +00:00
|
|
|
sort: "New",
|
2023-12-12 13:54:54 +00:00
|
|
|
limit: 50,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.getComments(form);
|
2022-07-30 03:55:59 +00:00
|
|
|
}
|
|
|
|
|
2023-08-01 13:14:40 +00:00
|
|
|
export async function getUnreadCount(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2023-08-01 13:14:40 +00:00
|
|
|
): Promise<GetUnreadCountResponse> {
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.getUnreadCount();
|
2023-08-01 13:14:40 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 10:42:28 +00:00
|
|
|
export async function getReplies(api: LemmyHttp): Promise<GetRepliesResponse> {
|
2023-08-01 13:14:40 +00:00
|
|
|
let form: GetReplies = {
|
|
|
|
sort: "New",
|
|
|
|
unread_only: false,
|
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.getReplies(form);
|
2023-08-01 13:14:40 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
export async function resolveComment(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.resolveObject(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
export async function resolveBetaCommunity(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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",
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.resolveObject(form);
|
2020-09-15 19:26:47 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
export async function resolveCommunity(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.resolveObject(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
export async function resolvePerson(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.resolveObject(form);
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 19:09:03 +00:00
|
|
|
export async function banPersonFromSite(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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,
|
2023-10-20 00:15:55 +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,
|
2024-03-01 18:45:06 +00:00
|
|
|
remove_data,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.banPerson(form);
|
2020-11-10 16:53:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 19:09:03 +00:00
|
|
|
export async function banPersonFromCommunity(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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,
|
2023-10-20 00:15:55 +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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.banFromCommunity(form);
|
2020-11-10 16:53:35 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function followCommunity(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
};
|
2023-09-21 11:57:13 +00:00
|
|
|
const res = await api.followCommunity(form);
|
2023-09-18 16:29:08 +00:00
|
|
|
await waitUntil(
|
2023-11-17 09:55:26 +00:00
|
|
|
() => getCommunity(api, res.community_view.community.id),
|
|
|
|
g =>
|
|
|
|
g.community_view.subscribed === (follow ? "Subscribed" : "NotSubscribed"),
|
2023-09-18 16:29:08 +00:00
|
|
|
);
|
|
|
|
// wait FOLLOW_ADDITIONS_RECHECK_DELAY (there's no API to wait for this currently)
|
|
|
|
await delay(2000);
|
|
|
|
return res;
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function likePost(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
};
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.likePost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createComment(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.createComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
export async function editComment(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.editComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function deleteComment(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.deleteComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function removeComment(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.removeComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
export async function getMentions(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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,
|
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.getPersonMentions(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function likeComment(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.likeComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createCommunity(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2024-01-25 14:22:11 +00:00
|
|
|
name_: string = randomString(10),
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.createCommunity(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2024-01-25 16:04:25 +00:00
|
|
|
export async function editCommunity(
|
|
|
|
api: LemmyHttp,
|
|
|
|
form: EditCommunity,
|
|
|
|
): Promise<CommunityResponse> {
|
|
|
|
return api.editCommunity(form);
|
|
|
|
}
|
|
|
|
|
2020-11-05 20:19:06 +00:00
|
|
|
export async function getCommunity(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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,
|
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.getCommunity(form);
|
2020-11-05 20:19:06 +00:00
|
|
|
}
|
|
|
|
|
2023-08-22 15:10:21 +00:00
|
|
|
export async function getCommunityByName(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2023-08-22 15:10:21 +00:00
|
|
|
name: string,
|
|
|
|
): Promise<CommunityResponse> {
|
|
|
|
let form: GetCommunity = {
|
|
|
|
name,
|
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.getCommunity(form);
|
2023-08-22 15:10:21 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function deleteCommunity(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.deleteCommunity(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function removeCommunity(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.removeCommunity(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createPrivateMessage(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.createPrivateMessage(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
export async function editPrivateMessage(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.editPrivateMessage(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function deletePrivateMessage(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2020-08-04 14:57:37 +00:00
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.deletePrivateMessage(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 15:06:27 +00:00
|
|
|
export async function registerUser(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2023-11-22 15:15:06 +00:00
|
|
|
url: string,
|
2023-07-06 13:10:38 +00:00
|
|
|
username: string = randomString(5),
|
2023-11-22 15:15:06 +00:00
|
|
|
): Promise<LemmyHttp> {
|
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
|
|
|
};
|
2023-11-22 15:15:06 +00:00
|
|
|
let login_response = await api.register(form);
|
|
|
|
|
|
|
|
expect(login_response.jwt).toBeDefined();
|
|
|
|
let lemmy_http = new LemmyHttp(url, {
|
|
|
|
headers: { Authorization: `Bearer ${login_response.jwt ?? ""}` },
|
|
|
|
});
|
|
|
|
return lemmy_http;
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
2023-10-09 10:46:12 +00:00
|
|
|
export async function loginUser(
|
|
|
|
api: LemmyHttp,
|
|
|
|
username: string,
|
|
|
|
): Promise<LoginResponse> {
|
|
|
|
let form: Login = {
|
|
|
|
username_or_email: username,
|
|
|
|
password: password,
|
|
|
|
};
|
|
|
|
return api.login(form);
|
|
|
|
}
|
|
|
|
|
2023-09-21 10:42:28 +00:00
|
|
|
export async function saveUserSettingsBio(
|
|
|
|
api: LemmyHttp,
|
2023-11-17 04:43:40 +00:00
|
|
|
): Promise<SuccessResponse> {
|
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",
|
|
|
|
};
|
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-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2023-11-17 04:43:40 +00:00
|
|
|
): Promise<SuccessResponse> {
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return await saveUserSettings(api, form);
|
2022-07-30 03:55:59 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 15:41:51 +00:00
|
|
|
export async function saveUserSettings(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2023-07-06 13:10:38 +00:00
|
|
|
form: SaveUserSettings,
|
2023-11-17 04:43:40 +00:00
|
|
|
): Promise<SuccessResponse> {
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.saveUserSettings(form);
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
2023-07-20 14:36:16 +00:00
|
|
|
export async function getPersonDetails(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2023-07-20 14:36:16 +00:00
|
|
|
person_id: number,
|
|
|
|
): Promise<GetPersonDetailsResponse> {
|
|
|
|
let form: GetPersonDetails = {
|
|
|
|
person_id: person_id,
|
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.getPersonDetails(form);
|
2023-07-20 14:36:16 +00:00
|
|
|
}
|
2020-08-04 15:06:27 +00:00
|
|
|
|
2023-11-17 04:43:40 +00:00
|
|
|
export async function deleteUser(api: LemmyHttp): Promise<SuccessResponse> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: DeleteAccount = {
|
2023-08-28 10:23:45 +00:00
|
|
|
delete_content: true,
|
2022-10-27 09:24:07 +00:00
|
|
|
password,
|
2023-01-04 15:59:26 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.deleteAccount(form);
|
2022-04-07 20:52:17 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 10:42:28 +00:00
|
|
|
export async function getSite(api: LemmyHttp): Promise<GetSiteResponse> {
|
|
|
|
return api.getSite();
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function listPrivateMessages(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<PrivateMessagesResponse> {
|
2023-01-04 15:59:26 +00:00
|
|
|
let form: GetPrivateMessages = {
|
|
|
|
unread_only: false,
|
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.getPrivateMessages(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 10:42:28 +00:00
|
|
|
export async function unfollowRemotes(
|
|
|
|
api: LemmyHttp,
|
|
|
|
): 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) ?? [];
|
2023-09-18 16:29:08 +00:00
|
|
|
await Promise.all(
|
|
|
|
remoteFollowed.map(cu => followCommunity(api, false, cu.community.id)),
|
|
|
|
);
|
2021-08-19 20:54:15 +00:00
|
|
|
let siteRes = await getSite(api);
|
|
|
|
return siteRes;
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 10:42:28 +00:00
|
|
|
export async function followBeta(api: LemmyHttp): 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(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2021-10-15 14:37:33 +00:00
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.createPostReport(form);
|
2021-10-15 14:37:33 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
export async function listPostReports(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2022-10-27 09:24:07 +00:00
|
|
|
): Promise<ListPostReportsResponse> {
|
2023-09-21 10:42:28 +00:00
|
|
|
let form: ListPostReports = {};
|
|
|
|
return api.listPostReports(form);
|
2021-10-15 14:37:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function reportComment(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2021-10-15 14:37:33 +00:00
|
|
|
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
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.createCommentReport(form);
|
2021-10-15 14:37:33 +00:00
|
|
|
}
|
|
|
|
|
2023-12-18 09:25:05 +00:00
|
|
|
export async function reportPrivateMessage(
|
|
|
|
api: LemmyHttp,
|
|
|
|
private_message_id: number,
|
|
|
|
reason: string,
|
|
|
|
): Promise<PrivateMessageReportResponse> {
|
|
|
|
let form: CreatePrivateMessageReport = {
|
|
|
|
private_message_id,
|
|
|
|
reason,
|
|
|
|
};
|
|
|
|
return api.createPrivateMessageReport(form);
|
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
export async function listCommentReports(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2022-10-27 09:24:07 +00:00
|
|
|
): Promise<ListCommentReportsResponse> {
|
2023-09-21 10:42:28 +00:00
|
|
|
let form: ListCommentReports = {};
|
|
|
|
return api.listCommentReports(form);
|
2023-07-26 17:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getPosts(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2023-08-31 11:07:45 +00:00
|
|
|
listingType?: ListingType,
|
2024-01-04 16:42:18 +00:00
|
|
|
community_id?: number,
|
2023-07-26 17:51:11 +00:00
|
|
|
): Promise<GetPostsResponse> {
|
|
|
|
let form: GetPosts = {
|
2023-08-31 11:07:45 +00:00
|
|
|
type_: listingType,
|
2023-12-12 13:54:54 +00:00
|
|
|
limit: 50,
|
2024-01-04 16:42:18 +00:00
|
|
|
community_id,
|
2023-07-26 17:51:11 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.getPosts(form);
|
2021-10-15 14:37:33 +00:00
|
|
|
}
|
|
|
|
|
2023-09-20 09:56:13 +00:00
|
|
|
export function blockInstance(
|
2023-09-21 10:42:28 +00:00
|
|
|
api: LemmyHttp,
|
2023-09-20 09:56:13 +00:00
|
|
|
instance_id: InstanceId,
|
|
|
|
block: boolean,
|
2023-10-20 00:15:55 +00:00
|
|
|
): Promise<BlockInstanceResponse> {
|
2023-09-20 09:56:13 +00:00
|
|
|
let form: BlockInstance = {
|
|
|
|
instance_id,
|
|
|
|
block,
|
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
return api.blockInstance(form);
|
2023-09-20 09:56:13 +00:00
|
|
|
}
|
|
|
|
|
2023-11-09 11:03:25 +00:00
|
|
|
export function blockCommunity(
|
|
|
|
api: LemmyHttp,
|
|
|
|
community_id: CommunityId,
|
|
|
|
block: boolean,
|
|
|
|
): Promise<BlockCommunityResponse> {
|
|
|
|
let form: BlockCommunity = {
|
|
|
|
community_id,
|
|
|
|
block,
|
|
|
|
};
|
|
|
|
return api.blockCommunity(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
|
|
|
|
2024-03-26 16:06:11 +00:00
|
|
|
export async function deleteAllImages(api: LemmyHttp) {
|
|
|
|
const imagesRes = await api.listAllMedia({
|
|
|
|
limit: imageFetchLimit,
|
|
|
|
});
|
|
|
|
imagesRes.images;
|
|
|
|
|
|
|
|
for (const image of imagesRes.images) {
|
|
|
|
const form: DeleteImage = {
|
2024-04-16 23:20:44 +00:00
|
|
|
token: image.local_image.pictrs_delete_token,
|
|
|
|
filename: image.local_image.pictrs_alias,
|
2024-03-26 16:06:11 +00:00
|
|
|
};
|
|
|
|
await api.deleteImage(form);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-22 19:50:47 +00:00
|
|
|
export async function unfollows() {
|
2023-09-18 16:29:08 +00:00
|
|
|
await Promise.all([
|
|
|
|
unfollowRemotes(alpha),
|
2024-03-26 16:06:11 +00:00
|
|
|
unfollowRemotes(beta),
|
2023-09-18 16:29:08 +00:00
|
|
|
unfollowRemotes(gamma),
|
|
|
|
unfollowRemotes(delta),
|
|
|
|
unfollowRemotes(epsilon),
|
|
|
|
]);
|
2022-03-22 19:50:47 +00:00
|
|
|
}
|
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-12-13 14:29:10 +00:00
|
|
|
console.log(`Failed to extract comment parent id from ${comment.path}`);
|
2023-01-04 15:59:26 +00:00
|
|
|
return undefined;
|
2022-07-30 03:55:59 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-09 16:25:03 +00:00
|
|
|
|
|
|
|
export async function waitUntil<T>(
|
|
|
|
fetcher: () => Promise<T>,
|
|
|
|
checker: (t: T) => boolean,
|
|
|
|
retries = 10,
|
2023-09-18 16:49:55 +00:00
|
|
|
delaySeconds = [0.2, 0.5, 1, 2, 3],
|
2023-09-09 16:25:03 +00:00
|
|
|
) {
|
|
|
|
let retry = 0;
|
2023-09-18 19:19:40 +00:00
|
|
|
let result;
|
2023-09-09 16:25:03 +00:00
|
|
|
while (retry++ < retries) {
|
2023-09-18 19:19:40 +00:00
|
|
|
result = await fetcher();
|
2023-09-09 16:25:03 +00:00
|
|
|
if (checker(result)) return result;
|
2023-09-18 16:49:55 +00:00
|
|
|
await delay(
|
|
|
|
delaySeconds[Math.min(retry - 1, delaySeconds.length - 1)] * 1000,
|
|
|
|
);
|
2023-09-09 16:25:03 +00:00
|
|
|
}
|
2023-09-18 19:19:40 +00:00
|
|
|
console.error("result", result);
|
2023-09-09 16:25:03 +00:00
|
|
|
throw Error(
|
|
|
|
`Failed "${fetcher}": "${checker}" did not return true after ${retries} retries (delayed ${delaySeconds}s each)`,
|
|
|
|
);
|
|
|
|
}
|