lemmy/api_tests/src/shared.ts

976 lines
25 KiB
TypeScript
Raw Normal View History

Enhanced testing of comments. Validate reply notifications, mentions (#3686) * shared.ts first test of getReplies * comment testing now validates reply notifications and mentions, some code comment cleanup in other functions * comments revised * first use of getUnreadCount in testing * test notification of new comment replies, clarify usage of getReplies * killall moved earlier in bash script * api-test jest run does not need directory prefix, make consistent with other jest runs * do not put my testing system password into script * fix, killall exits script when no process found * killall now moved to parent script to release locks before database create * need to run killall a second time, before database drop * first use of getReplies getPosts saveUserSettings * accidental duplication of functions, removed * try to sync shared library with main * Nutomic feedback: Better to rename the var instead of putting a comment which can easily get outdated. * Correct logic to meet join-lemmy requirement, don't have closed signups. Allows Open and Applications. (#3761) Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> * Fix fetch instance software version from nodeinfo (#3772) Fixes #3771 * remove unused code, revert killall change --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: figure-0e <133478007+figure-0e@users.noreply.github.com> Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> Co-authored-by: Denis Dzyubenko <denis@ddenis.info> Co-authored-by: Felix Ableitner <me@nutomic.com>
2023-08-01 13:14:40 +00:00
import {
BlockCommunity,
BlockCommunityResponse,
BlockInstance,
BlockInstanceResponse,
CommunityId,
CreatePrivateMessageReport,
DeleteImage,
EditCommunity,
Enhanced testing of comments. Validate reply notifications, mentions (#3686) * shared.ts first test of getReplies * comment testing now validates reply notifications and mentions, some code comment cleanup in other functions * comments revised * first use of getUnreadCount in testing * test notification of new comment replies, clarify usage of getReplies * killall moved earlier in bash script * api-test jest run does not need directory prefix, make consistent with other jest runs * do not put my testing system password into script * fix, killall exits script when no process found * killall now moved to parent script to release locks before database create * need to run killall a second time, before database drop * first use of getReplies getPosts saveUserSettings * accidental duplication of functions, removed * try to sync shared library with main * Nutomic feedback: Better to rename the var instead of putting a comment which can easily get outdated. * Correct logic to meet join-lemmy requirement, don't have closed signups. Allows Open and Applications. (#3761) Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> * Fix fetch instance software version from nodeinfo (#3772) Fixes #3771 * remove unused code, revert killall change --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: figure-0e <133478007+figure-0e@users.noreply.github.com> Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> Co-authored-by: Denis Dzyubenko <denis@ddenis.info> Co-authored-by: Felix Ableitner <me@nutomic.com>
2023-08-01 13:14:40 +00:00
GetReplies,
GetRepliesResponse,
GetUnreadCountResponse,
InstanceId,
Enhanced testing of comments. Validate reply notifications, mentions (#3686) * shared.ts first test of getReplies * comment testing now validates reply notifications and mentions, some code comment cleanup in other functions * comments revised * first use of getUnreadCount in testing * test notification of new comment replies, clarify usage of getReplies * killall moved earlier in bash script * api-test jest run does not need directory prefix, make consistent with other jest runs * do not put my testing system password into script * fix, killall exits script when no process found * killall now moved to parent script to release locks before database create * need to run killall a second time, before database drop * first use of getReplies getPosts saveUserSettings * accidental duplication of functions, removed * try to sync shared library with main * Nutomic feedback: Better to rename the var instead of putting a comment which can easily get outdated. * Correct logic to meet join-lemmy requirement, don't have closed signups. Allows Open and Applications. (#3761) Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> * Fix fetch instance software version from nodeinfo (#3772) Fixes #3771 * remove unused code, revert killall change --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: figure-0e <133478007+figure-0e@users.noreply.github.com> Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> Co-authored-by: Denis Dzyubenko <denis@ddenis.info> Co-authored-by: Felix Ableitner <me@nutomic.com>
2023-08-01 13:14:40 +00:00
LemmyHttp,
PostView,
PrivateMessageReportResponse,
SuccessResponse,
Enhanced testing of comments. Validate reply notifications, mentions (#3686) * shared.ts first test of getReplies * comment testing now validates reply notifications and mentions, some code comment cleanup in other functions * comments revised * first use of getUnreadCount in testing * test notification of new comment replies, clarify usage of getReplies * killall moved earlier in bash script * api-test jest run does not need directory prefix, make consistent with other jest runs * do not put my testing system password into script * fix, killall exits script when no process found * killall now moved to parent script to release locks before database create * need to run killall a second time, before database drop * first use of getReplies getPosts saveUserSettings * accidental duplication of functions, removed * try to sync shared library with main * Nutomic feedback: Better to rename the var instead of putting a comment which can easily get outdated. * Correct logic to meet join-lemmy requirement, don't have closed signups. Allows Open and Applications. (#3761) Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> * Fix fetch instance software version from nodeinfo (#3772) Fixes #3771 * remove unused code, revert killall change --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: figure-0e <133478007+figure-0e@users.noreply.github.com> Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> Co-authored-by: Denis Dzyubenko <denis@ddenis.info> Co-authored-by: Felix Ableitner <me@nutomic.com>
2023-08-01 13:14:40 +00:00
} 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 { 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";
import { GetPostsResponse } from "lemmy-js-client/dist/types/GetPostsResponse";
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
import { GetPersonDetailsResponse } from "lemmy-js-client/dist/types/GetPersonDetailsResponse";
import { GetPersonDetails } from "lemmy-js-client/dist/types/GetPersonDetails";
import { ListingType } from "lemmy-js-client/dist/types/ListingType";
export const fetchFunction = fetch;
export const imageFetchLimit = 50;
export const sampleImage =
"https://i.pinimg.com/originals/df/5f/5b/df5f5b1b174a2b4b6026cc6c8f9395c1.jpg";
export const sampleSite = "https://yahoo.com";
export const alphaUrl = "http://127.0.0.1:8541";
export const betaUrl = "http://127.0.0.1:8551";
export const gammaUrl = "http://127.0.0.1:8561";
export const deltaUrl = "http://127.0.0.1:8571";
export const epsilonUrl = "http://127.0.0.1:8581";
export const alpha = new LemmyHttp(alphaUrl, { fetchFunction });
export const alphaImage = new LemmyHttp(alphaUrl);
export const beta = new LemmyHttp(betaUrl, { fetchFunction });
export const gamma = new LemmyHttp(gammaUrl, { fetchFunction });
export const delta = new LemmyHttp(deltaUrl, { fetchFunction });
export const epsilon = new LemmyHttp(epsilonUrl, { fetchFunction });
export const betaAllowedInstances = [
"lemmy-alpha",
"lemmy-gamma",
"lemmy-delta",
"lemmy-epsilon",
];
const password = "lemmylemmy";
2021-09-19 21:20:47 +00:00
export async function setupLogins() {
let formAlpha: Login = {
username_or_email: "lemmy_alpha",
2021-09-19 21:20:47 +00:00
password,
};
let resAlpha = alpha.login(formAlpha);
let formBeta: Login = {
username_or_email: "lemmy_beta",
2021-09-19 21:20:47 +00:00
password,
};
let resBeta = beta.login(formBeta);
let formGamma: Login = {
username_or_email: "lemmy_gamma",
2021-09-19 21:20:47 +00:00
password,
};
let resGamma = gamma.login(formGamma);
let formDelta: Login = {
username_or_email: "lemmy_delta",
2021-09-19 21:20:47 +00:00
password,
};
let resDelta = delta.login(formDelta);
let formEpsilon: Login = {
username_or_email: "lemmy_epsilon",
2021-09-19 21:20:47 +00:00
password,
};
let resEpsilon = epsilon.login(formEpsilon);
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 ?? ""}` });
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 ?? ""}` });
// Registration applications are now enabled by default, need to disable them
let editSiteForm: EditSite = {
registration_mode: "Open",
rate_limit_message: 999,
rate_limit_post: 999,
rate_limit_register: 999,
rate_limit_image: 999,
rate_limit_comment: 999,
rate_limit_search: 999,
};
// Set the blocks and auths for each
editSiteForm.allowed_instances = [
"lemmy-beta",
"lemmy-gamma",
"lemmy-delta",
"lemmy-epsilon",
];
await alpha.editSite(editSiteForm);
editSiteForm.allowed_instances = betaAllowedInstances;
await beta.editSite(editSiteForm);
editSiteForm.allowed_instances = [
"lemmy-alpha",
"lemmy-beta",
"lemmy-delta",
"lemmy-epsilon",
];
await gamma.editSite(editSiteForm);
// Setup delta allowed instance
editSiteForm.allowed_instances = ["lemmy-beta"];
await delta.editSite(editSiteForm);
// Create the main alpha/beta communities
// Ignore thrown errors of duplicates
try {
await createCommunity(alpha, "main");
await createCommunity(beta, "main");
Persistent, performant, reliable federation queue (#3605) * persistent activity queue * fixes * fixes * make federation workers function callable from outside * log federation instances * dead instance detection not needed here * taplo fmt * split federate bin/lib * minor fix * better logging * log * create struct to hold cancellable task for readability * use boxfuture for readability * reset submodule * fix * fix lint * swap * remove json column, use separate array columns instead * some review comments * make worker a struct for readability * minor readability * add local filter to community follower view * remove separate lemmy_federate entry point * fix remaining duration * address review comments mostly * fix lint * upgrade actitypub-fed to simpler interface * fix sql format * increase delays a bit * fixes after merge * remove selectable * fix instance selectable * add comment * start federation based on latest id at the time * rename federate process args * dead instances in one query * filter follow+report activities by local * remove synchronous federation remove activity sender queue * lint * fix federation tests by waiting for results to change * fix fed test * fix comment report * wait some more * Apply suggestions from code review Co-authored-by: SorteKanin <sortekanin@gmail.com> * fix most remaining tests * wait until private messages * fix community tests * fix community tests * move arg parse * use instance_id instead of domain in federation_queue_state table --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: SorteKanin <sortekanin@gmail.com>
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);
2024-08-01 21:04:28 +00:00
} catch {
console.log("Communities already exist");
}
}
export async function createPost(
api: LemmyHttp,
community_id: number,
url: string = "https://example.com/",
Rewrite images to use local proxy (#4035) * Add markdown rule to add rel=nofollow for all links * Add markdown image rule to add local image proxy (fixes #1036) * comments * rewrite markdown image links working * add comment * perform markdown image processing in api/apub receivers * clippy * add db table to validate proxied links * rewrite link fields for avatar, banner etc * sql fmt * proxy links received over federation * add config option * undo post.url rewriting, move http route definition * add tests * proxy images through pictrs * testing * cleanup request.rs file * more cleanup (fixes #2611) * include url content type when sending post over apub (fixes #2611) * store post url content type in db * should be media_type * get rid of cache_remote_thumbnails setting, instead automatically take thumbnail from federation data if available. * fix tests * add setting disable_external_link_previews * federate post url as image depending on mime type * change setting again * machete * invert * support custom emoji * clippy * update defaults * add image proxy test, fix test * fix test * clippy * revert accidental changes * address review * clippy * Markdown link rule-dess (#4356) * Extracting opengraph_data to its own type. * A few additions for markdown-link-rule. --------- Co-authored-by: Nutomic <me@nutomic.com> * fix setting * use enum for image proxy setting * fix test configs * add config backwards compat * clippy * machete --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2024-01-25 14:22:11 +00:00
body = randomString(10),
// use example.com for consistent title and embed description
name: string = randomString(5),
alt_text = randomString(10),
custom_thumbnail: string | undefined = undefined,
): Promise<PostResponse> {
let form: CreatePost = {
name,
url,
body,
alt_text,
community_id,
custom_thumbnail,
};
return api.createPost(form);
}
export async function editPost(
api: LemmyHttp,
post: Post,
): Promise<PostResponse> {
let name = "A jest test federated post, updated";
let form: EditPost = {
name,
post_id: post.id,
};
return api.editPost(form);
}
export async function createPostWithThumbnail(
api: LemmyHttp,
community_id: number,
url: string,
custom_thumbnail: string,
): Promise<PostResponse> {
let form: CreatePost = {
name: randomString(10),
url,
community_id,
custom_thumbnail,
};
return api.createPost(form);
}
export async function deletePost(
api: LemmyHttp,
deleted: boolean,
post: Post,
): Promise<PostResponse> {
let form: DeletePost = {
post_id: post.id,
deleted: deleted,
};
return api.deletePost(form);
}
export async function removePost(
api: LemmyHttp,
removed: boolean,
post: Post,
): Promise<PostResponse> {
let form: RemovePost = {
post_id: post.id,
removed,
};
return api.removePost(form);
}
export async function featurePost(
api: LemmyHttp,
featured: boolean,
post: Post,
): Promise<PostResponse> {
let form: FeaturePost = {
post_id: post.id,
featured,
feature_type: "Community",
};
return api.featurePost(form);
}
export async function lockPost(
api: LemmyHttp,
locked: boolean,
post: Post,
): Promise<PostResponse> {
let form: LockPost = {
post_id: post.id,
locked,
};
return api.lockPost(form);
}
export async function resolvePost(
api: LemmyHttp,
post: Post,
): Promise<ResolveObjectResponse> {
let form: ResolveObject = {
q: post.ap_id,
};
return api.resolveObject(form);
}
export async function searchPostLocal(
api: LemmyHttp,
post: Post,
): Promise<SearchResponse> {
let form: Search = {
q: post.name,
type_: "Posts",
sort: "TopAll",
listing_type: "All",
};
return api.search(form);
}
/// wait for a post to appear locally without pulling it
export async function waitForPost(
2023-09-21 12:32:41 +00:00
api: LemmyHttp,
post: Post,
2023-09-20 11:21:47 +00:00
checker: (t: PostView | undefined) => boolean = p => !!p,
) {
2023-09-20 11:21:47 +00:00
return waitUntil<PostView>(
() => searchPostLocal(api, post).then(p => p.posts[0]),
checker,
);
}
export async function getPost(
api: LemmyHttp,
post_id: number,
): Promise<GetPostResponse> {
let form: GetPost = {
id: post_id,
};
return api.getPost(form);
}
export async function getComments(
api: LemmyHttp,
post_id?: number,
listingType: ListingType = "All",
): Promise<GetCommentsResponse> {
let form: GetComments = {
post_id: post_id,
type_: listingType,
sort: "New",
limit: 50,
};
return api.getComments(form);
}
Enhanced testing of comments. Validate reply notifications, mentions (#3686) * shared.ts first test of getReplies * comment testing now validates reply notifications and mentions, some code comment cleanup in other functions * comments revised * first use of getUnreadCount in testing * test notification of new comment replies, clarify usage of getReplies * killall moved earlier in bash script * api-test jest run does not need directory prefix, make consistent with other jest runs * do not put my testing system password into script * fix, killall exits script when no process found * killall now moved to parent script to release locks before database create * need to run killall a second time, before database drop * first use of getReplies getPosts saveUserSettings * accidental duplication of functions, removed * try to sync shared library with main * Nutomic feedback: Better to rename the var instead of putting a comment which can easily get outdated. * Correct logic to meet join-lemmy requirement, don't have closed signups. Allows Open and Applications. (#3761) Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> * Fix fetch instance software version from nodeinfo (#3772) Fixes #3771 * remove unused code, revert killall change --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: figure-0e <133478007+figure-0e@users.noreply.github.com> Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> Co-authored-by: Denis Dzyubenko <denis@ddenis.info> Co-authored-by: Felix Ableitner <me@nutomic.com>
2023-08-01 13:14:40 +00:00
export async function getUnreadCount(
api: LemmyHttp,
Enhanced testing of comments. Validate reply notifications, mentions (#3686) * shared.ts first test of getReplies * comment testing now validates reply notifications and mentions, some code comment cleanup in other functions * comments revised * first use of getUnreadCount in testing * test notification of new comment replies, clarify usage of getReplies * killall moved earlier in bash script * api-test jest run does not need directory prefix, make consistent with other jest runs * do not put my testing system password into script * fix, killall exits script when no process found * killall now moved to parent script to release locks before database create * need to run killall a second time, before database drop * first use of getReplies getPosts saveUserSettings * accidental duplication of functions, removed * try to sync shared library with main * Nutomic feedback: Better to rename the var instead of putting a comment which can easily get outdated. * Correct logic to meet join-lemmy requirement, don't have closed signups. Allows Open and Applications. (#3761) Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> * Fix fetch instance software version from nodeinfo (#3772) Fixes #3771 * remove unused code, revert killall change --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: figure-0e <133478007+figure-0e@users.noreply.github.com> Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> Co-authored-by: Denis Dzyubenko <denis@ddenis.info> Co-authored-by: Felix Ableitner <me@nutomic.com>
2023-08-01 13:14:40 +00:00
): Promise<GetUnreadCountResponse> {
return api.getUnreadCount();
Enhanced testing of comments. Validate reply notifications, mentions (#3686) * shared.ts first test of getReplies * comment testing now validates reply notifications and mentions, some code comment cleanup in other functions * comments revised * first use of getUnreadCount in testing * test notification of new comment replies, clarify usage of getReplies * killall moved earlier in bash script * api-test jest run does not need directory prefix, make consistent with other jest runs * do not put my testing system password into script * fix, killall exits script when no process found * killall now moved to parent script to release locks before database create * need to run killall a second time, before database drop * first use of getReplies getPosts saveUserSettings * accidental duplication of functions, removed * try to sync shared library with main * Nutomic feedback: Better to rename the var instead of putting a comment which can easily get outdated. * Correct logic to meet join-lemmy requirement, don't have closed signups. Allows Open and Applications. (#3761) Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> * Fix fetch instance software version from nodeinfo (#3772) Fixes #3771 * remove unused code, revert killall change --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: figure-0e <133478007+figure-0e@users.noreply.github.com> Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> Co-authored-by: Denis Dzyubenko <denis@ddenis.info> Co-authored-by: Felix Ableitner <me@nutomic.com>
2023-08-01 13:14:40 +00:00
}
export async function getReplies(
api: LemmyHttp,
unread_only: boolean = false,
): Promise<GetRepliesResponse> {
Enhanced testing of comments. Validate reply notifications, mentions (#3686) * shared.ts first test of getReplies * comment testing now validates reply notifications and mentions, some code comment cleanup in other functions * comments revised * first use of getUnreadCount in testing * test notification of new comment replies, clarify usage of getReplies * killall moved earlier in bash script * api-test jest run does not need directory prefix, make consistent with other jest runs * do not put my testing system password into script * fix, killall exits script when no process found * killall now moved to parent script to release locks before database create * need to run killall a second time, before database drop * first use of getReplies getPosts saveUserSettings * accidental duplication of functions, removed * try to sync shared library with main * Nutomic feedback: Better to rename the var instead of putting a comment which can easily get outdated. * Correct logic to meet join-lemmy requirement, don't have closed signups. Allows Open and Applications. (#3761) Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> * Fix fetch instance software version from nodeinfo (#3772) Fixes #3771 * remove unused code, revert killall change --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: figure-0e <133478007+figure-0e@users.noreply.github.com> Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> Co-authored-by: Denis Dzyubenko <denis@ddenis.info> Co-authored-by: Felix Ableitner <me@nutomic.com>
2023-08-01 13:14:40 +00:00
let form: GetReplies = {
sort: "New",
unread_only,
Enhanced testing of comments. Validate reply notifications, mentions (#3686) * shared.ts first test of getReplies * comment testing now validates reply notifications and mentions, some code comment cleanup in other functions * comments revised * first use of getUnreadCount in testing * test notification of new comment replies, clarify usage of getReplies * killall moved earlier in bash script * api-test jest run does not need directory prefix, make consistent with other jest runs * do not put my testing system password into script * fix, killall exits script when no process found * killall now moved to parent script to release locks before database create * need to run killall a second time, before database drop * first use of getReplies getPosts saveUserSettings * accidental duplication of functions, removed * try to sync shared library with main * Nutomic feedback: Better to rename the var instead of putting a comment which can easily get outdated. * Correct logic to meet join-lemmy requirement, don't have closed signups. Allows Open and Applications. (#3761) Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> * Fix fetch instance software version from nodeinfo (#3772) Fixes #3771 * remove unused code, revert killall change --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: figure-0e <133478007+figure-0e@users.noreply.github.com> Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> Co-authored-by: Denis Dzyubenko <denis@ddenis.info> Co-authored-by: Felix Ableitner <me@nutomic.com>
2023-08-01 13:14:40 +00:00
};
return api.getReplies(form);
Enhanced testing of comments. Validate reply notifications, mentions (#3686) * shared.ts first test of getReplies * comment testing now validates reply notifications and mentions, some code comment cleanup in other functions * comments revised * first use of getUnreadCount in testing * test notification of new comment replies, clarify usage of getReplies * killall moved earlier in bash script * api-test jest run does not need directory prefix, make consistent with other jest runs * do not put my testing system password into script * fix, killall exits script when no process found * killall now moved to parent script to release locks before database create * need to run killall a second time, before database drop * first use of getReplies getPosts saveUserSettings * accidental duplication of functions, removed * try to sync shared library with main * Nutomic feedback: Better to rename the var instead of putting a comment which can easily get outdated. * Correct logic to meet join-lemmy requirement, don't have closed signups. Allows Open and Applications. (#3761) Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> * Fix fetch instance software version from nodeinfo (#3772) Fixes #3771 * remove unused code, revert killall change --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: figure-0e <133478007+figure-0e@users.noreply.github.com> Co-authored-by: Josh Bernardini <josh.bernardini@cologix.com> Co-authored-by: Denis Dzyubenko <denis@ddenis.info> Co-authored-by: Felix Ableitner <me@nutomic.com>
2023-08-01 13:14:40 +00:00
}
export async function resolveComment(
api: LemmyHttp,
comment: Comment,
): Promise<ResolveObjectResponse> {
let form: ResolveObject = {
q: comment.ap_id,
};
return api.resolveObject(form);
}
export async function resolveBetaCommunity(
api: LemmyHttp,
): Promise<ResolveObjectResponse> {
// Use short-hand search url
let form: ResolveObject = {
q: "!main@lemmy-beta:8551",
};
return api.resolveObject(form);
}
export async function resolveCommunity(
api: LemmyHttp,
q: string,
): Promise<ResolveObjectResponse> {
let form: ResolveObject = {
q,
};
return api.resolveObject(form);
}
export async function resolvePerson(
api: LemmyHttp,
apShortname: string,
): Promise<ResolveObjectResponse> {
let form: ResolveObject = {
q: apShortname,
};
return api.resolveObject(form);
}
2021-03-12 19:09:03 +00:00
export async function banPersonFromSite(
api: LemmyHttp,
2021-03-12 19:09:03 +00:00
person_id: number,
ban: boolean,
remove_or_restore_data: boolean,
): Promise<BanPersonResponse> {
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
let form: BanPerson = {
2021-03-12 19:09:03 +00:00
person_id,
ban,
remove_or_restore_data,
};
return api.banPerson(form);
}
2021-03-12 19:09:03 +00:00
export async function banPersonFromCommunity(
api: LemmyHttp,
2021-03-12 19:09:03 +00:00
person_id: number,
community_id: number,
remove_or_restore_data: boolean,
ban: boolean,
): Promise<BanFromCommunityResponse> {
let form: BanFromCommunity = {
2021-03-12 19:09:03 +00:00
person_id,
community_id,
remove_or_restore_data,
ban,
};
return api.banFromCommunity(form);
}
export async function followCommunity(
api: LemmyHttp,
follow: boolean,
community_id: number,
): Promise<CommunityResponse> {
let form: FollowCommunity = {
community_id,
follow,
};
const res = await api.followCommunity(form);
2023-09-18 16:29:08 +00:00
await waitUntil(
() => 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;
}
export async function likePost(
api: LemmyHttp,
score: number,
post: Post,
): Promise<PostResponse> {
let form: CreatePostLike = {
post_id: post.id,
score: score,
};
return api.likePost(form);
}
export async function createComment(
api: LemmyHttp,
post_id: number,
parent_id?: number,
content = "a jest test comment",
): Promise<CommentResponse> {
let form: CreateComment = {
content,
post_id,
parent_id,
};
return api.createComment(form);
}
2020-12-20 21:16:57 +00:00
export async function editComment(
api: LemmyHttp,
comment_id: number,
content = "A jest test federated comment update",
): Promise<CommentResponse> {
let form: EditComment = {
content,
comment_id,
};
return api.editComment(form);
}
export async function deleteComment(
api: LemmyHttp,
deleted: boolean,
comment_id: number,
): Promise<CommentResponse> {
let form: DeleteComment = {
comment_id,
deleted,
};
return api.deleteComment(form);
}
export async function removeComment(
api: LemmyHttp,
removed: boolean,
comment_id: number,
): Promise<CommentResponse> {
let form: RemoveComment = {
comment_id,
removed,
};
return api.removeComment(form);
}
export async function getMentions(
api: LemmyHttp,
): Promise<GetPersonMentionsResponse> {
let form: GetPersonMentions = {
sort: "New",
unread_only: false,
};
return api.getPersonMentions(form);
}
export async function likeComment(
api: LemmyHttp,
score: number,
comment: Comment,
): Promise<CommentResponse> {
let form: CreateCommentLike = {
comment_id: comment.id,
score,
};
return api.likeComment(form);
}
export async function createCommunity(
api: LemmyHttp,
Rewrite images to use local proxy (#4035) * Add markdown rule to add rel=nofollow for all links * Add markdown image rule to add local image proxy (fixes #1036) * comments * rewrite markdown image links working * add comment * perform markdown image processing in api/apub receivers * clippy * add db table to validate proxied links * rewrite link fields for avatar, banner etc * sql fmt * proxy links received over federation * add config option * undo post.url rewriting, move http route definition * add tests * proxy images through pictrs * testing * cleanup request.rs file * more cleanup (fixes #2611) * include url content type when sending post over apub (fixes #2611) * store post url content type in db * should be media_type * get rid of cache_remote_thumbnails setting, instead automatically take thumbnail from federation data if available. * fix tests * add setting disable_external_link_previews * federate post url as image depending on mime type * change setting again * machete * invert * support custom emoji * clippy * update defaults * add image proxy test, fix test * fix test * clippy * revert accidental changes * address review * clippy * Markdown link rule-dess (#4356) * Extracting opengraph_data to its own type. * A few additions for markdown-link-rule. --------- Co-authored-by: Nutomic <me@nutomic.com> * fix setting * use enum for image proxy setting * fix test configs * add config backwards compat * clippy * machete --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2024-01-25 14:22:11 +00:00
name_: string = randomString(10),
): Promise<CommunityResponse> {
let description = "a sample description";
let form: CreateCommunity = {
name: name_,
title: name_,
description,
};
return api.createCommunity(form);
}
export async function editCommunity(
api: LemmyHttp,
form: EditCommunity,
): Promise<CommunityResponse> {
return api.editCommunity(form);
}
export async function getCommunity(
api: LemmyHttp,
id: number,
): Promise<CommunityResponse> {
let form: GetCommunity = {
id,
};
return api.getCommunity(form);
}
export async function getCommunityByName(
api: LemmyHttp,
name: string,
): Promise<CommunityResponse> {
let form: GetCommunity = {
name,
};
return api.getCommunity(form);
}
export async function deleteCommunity(
api: LemmyHttp,
deleted: boolean,
community_id: number,
): Promise<CommunityResponse> {
let form: DeleteCommunity = {
community_id,
deleted,
};
return api.deleteCommunity(form);
}
export async function removeCommunity(
api: LemmyHttp,
removed: boolean,
community_id: number,
): Promise<CommunityResponse> {
let form: RemoveCommunity = {
community_id,
removed,
};
return api.removeCommunity(form);
}
export async function createPrivateMessage(
api: LemmyHttp,
recipient_id: number,
): Promise<PrivateMessageResponse> {
let content = "A jest test federated private message";
let form: CreatePrivateMessage = {
content,
recipient_id,
};
return api.createPrivateMessage(form);
}
2020-12-20 21:16:57 +00:00
export async function editPrivateMessage(
api: LemmyHttp,
private_message_id: number,
): Promise<PrivateMessageResponse> {
let updatedContent = "A jest test federated private message edited";
let form: EditPrivateMessage = {
content: updatedContent,
private_message_id,
};
return api.editPrivateMessage(form);
}
export async function deletePrivateMessage(
api: LemmyHttp,
deleted: boolean,
private_message_id: number,
): Promise<PrivateMessageResponse> {
let form: DeletePrivateMessage = {
deleted,
private_message_id,
};
return api.deletePrivateMessage(form);
}
export async function registerUser(
api: LemmyHttp,
url: string,
username: string = randomString(5),
): Promise<LemmyHttp> {
let form: Register = {
username,
2021-09-19 21:20:47 +00:00
password,
password_verify: password,
show_nsfw: true,
};
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;
}
export async function loginUser(
api: LemmyHttp,
username: string,
): Promise<LoginResponse> {
let form: Login = {
username_or_email: username,
password: password,
};
return api.login(form);
}
export async function saveUserSettingsBio(
api: LemmyHttp,
): Promise<SuccessResponse> {
let form: SaveUserSettings = {
show_nsfw: true,
blur_nsfw: false,
auto_expand: true,
theme: "darkly",
default_sort_type: "Active",
default_listing_type: "All",
interface_language: "en",
show_avatars: true,
send_notifications_to_email: false,
bio: "a changed bio",
};
return saveUserSettings(api, form);
}
export async function saveUserSettingsFederated(
api: LemmyHttp,
): Promise<SuccessResponse> {
let avatar = sampleImage;
let banner = sampleImage;
let bio = "a changed bio";
let form: SaveUserSettings = {
show_nsfw: false,
blur_nsfw: true,
auto_expand: false,
default_sort_type: "Hot",
default_listing_type: "All",
interface_language: "",
avatar,
banner,
display_name: "user321",
show_avatars: false,
send_notifications_to_email: false,
bio,
};
return await saveUserSettings(api, form);
}
export async function saveUserSettings(
api: LemmyHttp,
form: SaveUserSettings,
): Promise<SuccessResponse> {
return api.saveUserSettings(form);
}
export async function getPersonDetails(
api: LemmyHttp,
person_id: number,
): Promise<GetPersonDetailsResponse> {
let form: GetPersonDetails = {
person_id: person_id,
};
return api.getPersonDetails(form);
}
export async function deleteUser(api: LemmyHttp): Promise<SuccessResponse> {
let form: DeleteAccount = {
delete_content: true,
password,
};
return api.deleteAccount(form);
}
export async function getSite(api: LemmyHttp): Promise<GetSiteResponse> {
return api.getSite();
}
export async function listPrivateMessages(
api: LemmyHttp,
): Promise<PrivateMessagesResponse> {
let form: GetPrivateMessages = {
unread_only: false,
};
return api.getPrivateMessages(form);
}
export async function unfollowRemotes(
api: LemmyHttp,
): Promise<GetSiteResponse> {
// Unfollow all remote communities
let site = await getSite(api);
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)),
);
let siteRes = await getSite(api);
return siteRes;
}
export async function followBeta(api: LemmyHttp): Promise<CommunityResponse> {
let betaCommunity = (await resolveBetaCommunity(api)).community;
if (betaCommunity) {
let follow = await followCommunity(api, true, betaCommunity.community.id);
return follow;
} else {
return Promise.reject("no community worked");
}
}
export async function reportPost(
api: LemmyHttp,
post_id: number,
reason: string,
): Promise<PostReportResponse> {
let form: CreatePostReport = {
post_id,
reason,
};
return api.createPostReport(form);
}
export async function listPostReports(
api: LemmyHttp,
): Promise<ListPostReportsResponse> {
let form: ListPostReports = {};
return api.listPostReports(form);
}
export async function reportComment(
api: LemmyHttp,
comment_id: number,
reason: string,
): Promise<CommentReportResponse> {
let form: CreateCommentReport = {
comment_id,
reason,
};
return api.createCommentReport(form);
}
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);
}
export async function listCommentReports(
api: LemmyHttp,
): Promise<ListCommentReportsResponse> {
let form: ListCommentReports = {};
return api.listCommentReports(form);
}
export function getPosts(
api: LemmyHttp,
listingType?: ListingType,
community_id?: number,
): Promise<GetPostsResponse> {
let form: GetPosts = {
type_: listingType,
limit: 50,
community_id,
};
return api.getPosts(form);
}
export function blockInstance(
api: LemmyHttp,
instance_id: InstanceId,
block: boolean,
): Promise<BlockInstanceResponse> {
let form: BlockInstance = {
instance_id,
block,
};
return api.blockInstance(form);
}
export function blockCommunity(
api: LemmyHttp,
community_id: CommunityId,
block: boolean,
): Promise<BlockCommunityResponse> {
let form: BlockCommunity = {
community_id,
block,
};
return api.blockCommunity(form);
}
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);
}
export function wrapper(form: any): string {
return JSON.stringify(form);
}
export function randomString(length: number): string {
var result = "";
var characters =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
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 deleteAllImages(api: LemmyHttp) {
const imagesRes = await api.listAllMedia({
limit: imageFetchLimit,
});
Promise.all(
imagesRes.images
.map(image => {
const form: DeleteImage = {
token: image.local_image.pictrs_delete_token,
filename: image.local_image.pictrs_alias,
};
return form;
})
.map(form => 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),
unfollowRemotes(beta),
2023-09-18 16:29:08 +00:00
unfollowRemotes(gamma),
unfollowRemotes(delta),
unfollowRemotes(epsilon),
]);
await Promise.all([
purgeAllPosts(alpha),
purgeAllPosts(beta),
purgeAllPosts(gamma),
purgeAllPosts(delta),
purgeAllPosts(epsilon),
]);
}
export async function purgeAllPosts(api: LemmyHttp) {
// The best way to get all federated items, is to find the posts
let res = await api.getPosts({ type_: "All", limit: 50 });
await Promise.all(
Array.from(new Set(res.posts.map(p => p.post.id)))
.map(post_id => api.purgePost({ post_id }))
// Ignore errors
.map(p => p.catch(e => e)),
);
2022-03-22 19:50:47 +00:00
}
export function getCommentParentId(comment: Comment): number | undefined {
let split = comment.path.split(".");
// remove the 0
split.shift();
if (split.length > 1) {
return Number(split[split.length - 2]);
} else {
console.log(`Failed to extract comment parent id from ${comment.path}`);
return undefined;
}
}
Persistent, performant, reliable federation queue (#3605) * persistent activity queue * fixes * fixes * make federation workers function callable from outside * log federation instances * dead instance detection not needed here * taplo fmt * split federate bin/lib * minor fix * better logging * log * create struct to hold cancellable task for readability * use boxfuture for readability * reset submodule * fix * fix lint * swap * remove json column, use separate array columns instead * some review comments * make worker a struct for readability * minor readability * add local filter to community follower view * remove separate lemmy_federate entry point * fix remaining duration * address review comments mostly * fix lint * upgrade actitypub-fed to simpler interface * fix sql format * increase delays a bit * fixes after merge * remove selectable * fix instance selectable * add comment * start federation based on latest id at the time * rename federate process args * dead instances in one query * filter follow+report activities by local * remove synchronous federation remove activity sender queue * lint * fix federation tests by waiting for results to change * fix fed test * fix comment report * wait some more * Apply suggestions from code review Co-authored-by: SorteKanin <sortekanin@gmail.com> * fix most remaining tests * wait until private messages * fix community tests * fix community tests * move arg parse * use instance_id instead of domain in federation_queue_state table --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: SorteKanin <sortekanin@gmail.com>
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],
Persistent, performant, reliable federation queue (#3605) * persistent activity queue * fixes * fixes * make federation workers function callable from outside * log federation instances * dead instance detection not needed here * taplo fmt * split federate bin/lib * minor fix * better logging * log * create struct to hold cancellable task for readability * use boxfuture for readability * reset submodule * fix * fix lint * swap * remove json column, use separate array columns instead * some review comments * make worker a struct for readability * minor readability * add local filter to community follower view * remove separate lemmy_federate entry point * fix remaining duration * address review comments mostly * fix lint * upgrade actitypub-fed to simpler interface * fix sql format * increase delays a bit * fixes after merge * remove selectable * fix instance selectable * add comment * start federation based on latest id at the time * rename federate process args * dead instances in one query * filter follow+report activities by local * remove synchronous federation remove activity sender queue * lint * fix federation tests by waiting for results to change * fix fed test * fix comment report * wait some more * Apply suggestions from code review Co-authored-by: SorteKanin <sortekanin@gmail.com> * fix most remaining tests * wait until private messages * fix community tests * fix community tests * move arg parse * use instance_id instead of domain in federation_queue_state table --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: SorteKanin <sortekanin@gmail.com>
2023-09-09 16:25:03 +00:00
) {
let retry = 0;
2023-09-18 19:19:40 +00:00
let result;
Persistent, performant, reliable federation queue (#3605) * persistent activity queue * fixes * fixes * make federation workers function callable from outside * log federation instances * dead instance detection not needed here * taplo fmt * split federate bin/lib * minor fix * better logging * log * create struct to hold cancellable task for readability * use boxfuture for readability * reset submodule * fix * fix lint * swap * remove json column, use separate array columns instead * some review comments * make worker a struct for readability * minor readability * add local filter to community follower view * remove separate lemmy_federate entry point * fix remaining duration * address review comments mostly * fix lint * upgrade actitypub-fed to simpler interface * fix sql format * increase delays a bit * fixes after merge * remove selectable * fix instance selectable * add comment * start federation based on latest id at the time * rename federate process args * dead instances in one query * filter follow+report activities by local * remove synchronous federation remove activity sender queue * lint * fix federation tests by waiting for results to change * fix fed test * fix comment report * wait some more * Apply suggestions from code review Co-authored-by: SorteKanin <sortekanin@gmail.com> * fix most remaining tests * wait until private messages * fix community tests * fix community tests * move arg parse * use instance_id instead of domain in federation_queue_state table --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: SorteKanin <sortekanin@gmail.com>
2023-09-09 16:25:03 +00:00
while (retry++ < retries) {
2023-09-18 19:19:40 +00:00
result = await fetcher();
Persistent, performant, reliable federation queue (#3605) * persistent activity queue * fixes * fixes * make federation workers function callable from outside * log federation instances * dead instance detection not needed here * taplo fmt * split federate bin/lib * minor fix * better logging * log * create struct to hold cancellable task for readability * use boxfuture for readability * reset submodule * fix * fix lint * swap * remove json column, use separate array columns instead * some review comments * make worker a struct for readability * minor readability * add local filter to community follower view * remove separate lemmy_federate entry point * fix remaining duration * address review comments mostly * fix lint * upgrade actitypub-fed to simpler interface * fix sql format * increase delays a bit * fixes after merge * remove selectable * fix instance selectable * add comment * start federation based on latest id at the time * rename federate process args * dead instances in one query * filter follow+report activities by local * remove synchronous federation remove activity sender queue * lint * fix federation tests by waiting for results to change * fix fed test * fix comment report * wait some more * Apply suggestions from code review Co-authored-by: SorteKanin <sortekanin@gmail.com> * fix most remaining tests * wait until private messages * fix community tests * fix community tests * move arg parse * use instance_id instead of domain in federation_queue_state table --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: SorteKanin <sortekanin@gmail.com>
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,
);
Persistent, performant, reliable federation queue (#3605) * persistent activity queue * fixes * fixes * make federation workers function callable from outside * log federation instances * dead instance detection not needed here * taplo fmt * split federate bin/lib * minor fix * better logging * log * create struct to hold cancellable task for readability * use boxfuture for readability * reset submodule * fix * fix lint * swap * remove json column, use separate array columns instead * some review comments * make worker a struct for readability * minor readability * add local filter to community follower view * remove separate lemmy_federate entry point * fix remaining duration * address review comments mostly * fix lint * upgrade actitypub-fed to simpler interface * fix sql format * increase delays a bit * fixes after merge * remove selectable * fix instance selectable * add comment * start federation based on latest id at the time * rename federate process args * dead instances in one query * filter follow+report activities by local * remove synchronous federation remove activity sender queue * lint * fix federation tests by waiting for results to change * fix fed test * fix comment report * wait some more * Apply suggestions from code review Co-authored-by: SorteKanin <sortekanin@gmail.com> * fix most remaining tests * wait until private messages * fix community tests * fix community tests * move arg parse * use instance_id instead of domain in federation_queue_state table --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: SorteKanin <sortekanin@gmail.com>
2023-09-09 16:25:03 +00:00
}
2023-09-18 19:19:40 +00:00
console.error("result", result);
Persistent, performant, reliable federation queue (#3605) * persistent activity queue * fixes * fixes * make federation workers function callable from outside * log federation instances * dead instance detection not needed here * taplo fmt * split federate bin/lib * minor fix * better logging * log * create struct to hold cancellable task for readability * use boxfuture for readability * reset submodule * fix * fix lint * swap * remove json column, use separate array columns instead * some review comments * make worker a struct for readability * minor readability * add local filter to community follower view * remove separate lemmy_federate entry point * fix remaining duration * address review comments mostly * fix lint * upgrade actitypub-fed to simpler interface * fix sql format * increase delays a bit * fixes after merge * remove selectable * fix instance selectable * add comment * start federation based on latest id at the time * rename federate process args * dead instances in one query * filter follow+report activities by local * remove synchronous federation remove activity sender queue * lint * fix federation tests by waiting for results to change * fix fed test * fix comment report * wait some more * Apply suggestions from code review Co-authored-by: SorteKanin <sortekanin@gmail.com> * fix most remaining tests * wait until private messages * fix community tests * fix community tests * move arg parse * use instance_id instead of domain in federation_queue_state table --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: SorteKanin <sortekanin@gmail.com>
2023-09-09 16:25:03 +00:00
throw Error(
`Failed "${fetcher}": "${checker}" did not return true after ${retries} retries (delayed ${delaySeconds}s each)`,
);
}