2020-08-04 14:57:37 +00:00
|
|
|
import {
|
2020-12-20 21:16:57 +00:00
|
|
|
Login,
|
2020-08-04 14:57:37 +00:00
|
|
|
LoginResponse,
|
2020-12-20 21:16:57 +00:00
|
|
|
CreatePost,
|
|
|
|
EditPost,
|
|
|
|
CreateComment,
|
|
|
|
DeletePost,
|
|
|
|
RemovePost,
|
|
|
|
StickyPost,
|
|
|
|
LockPost,
|
2020-08-04 14:57:37 +00:00
|
|
|
PostResponse,
|
|
|
|
SearchResponse,
|
2020-12-20 21:16:57 +00:00
|
|
|
FollowCommunity,
|
2020-08-04 14:57:37 +00:00
|
|
|
CommunityResponse,
|
|
|
|
GetFollowedCommunitiesResponse,
|
|
|
|
GetPostResponse,
|
2020-12-20 21:16:57 +00:00
|
|
|
Register,
|
|
|
|
Comment,
|
|
|
|
EditComment,
|
|
|
|
DeleteComment,
|
|
|
|
RemoveComment,
|
|
|
|
Search,
|
2020-08-04 14:57:37 +00:00
|
|
|
CommentResponse,
|
2020-12-20 21:16:57 +00:00
|
|
|
GetCommunity,
|
|
|
|
CreateCommunity,
|
|
|
|
DeleteCommunity,
|
|
|
|
RemoveCommunity,
|
2021-03-12 19:09:03 +00:00
|
|
|
GetPersonMentions,
|
2020-12-20 21:16:57 +00:00
|
|
|
CreateCommentLike,
|
|
|
|
CreatePostLike,
|
|
|
|
EditPrivateMessage,
|
|
|
|
DeletePrivateMessage,
|
|
|
|
GetFollowedCommunities,
|
|
|
|
GetPrivateMessages,
|
|
|
|
GetSite,
|
|
|
|
GetPost,
|
2020-08-04 14:57:37 +00:00
|
|
|
PrivateMessageResponse,
|
|
|
|
PrivateMessagesResponse,
|
2021-03-12 19:09:03 +00:00
|
|
|
GetPersonMentionsResponse,
|
2020-12-20 21:16:57 +00:00
|
|
|
SaveUserSettings,
|
2020-08-04 15:06:27 +00:00
|
|
|
SortType,
|
|
|
|
ListingType,
|
|
|
|
GetSiteResponse,
|
2020-08-20 14:50:26 +00:00
|
|
|
SearchType,
|
|
|
|
LemmyHttp,
|
2021-03-12 19:09:03 +00:00
|
|
|
BanPersonResponse,
|
|
|
|
BanPerson,
|
2020-12-20 21:16:57 +00:00
|
|
|
BanFromCommunity,
|
2020-11-10 16:53:35 +00:00
|
|
|
BanFromCommunityResponse,
|
2020-12-20 21:16:57 +00:00
|
|
|
Post,
|
|
|
|
CreatePrivateMessage,
|
2020-08-20 14:50:26 +00:00
|
|
|
} from 'lemmy-js-client';
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
export interface API {
|
2020-08-20 14:50:26 +00:00
|
|
|
client: LemmyHttp;
|
2020-08-04 14:57:37 +00:00
|
|
|
auth?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export let alpha: API = {
|
2020-12-20 21:16:57 +00:00
|
|
|
client: new LemmyHttp('http://localhost:8541/api/v2'),
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export let beta: API = {
|
2020-12-20 21:16:57 +00:00
|
|
|
client: new LemmyHttp('http://localhost:8551/api/v2'),
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export let gamma: API = {
|
2020-12-20 21:16:57 +00:00
|
|
|
client: new LemmyHttp('http://localhost:8561/api/v2'),
|
2020-08-04 14:57:37 +00:00
|
|
|
};
|
|
|
|
|
2020-08-20 12:44:22 +00:00
|
|
|
export let delta: API = {
|
2020-12-20 21:16:57 +00:00
|
|
|
client: new LemmyHttp('http://localhost:8571/api/v2'),
|
2020-08-20 12:44:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export let epsilon: API = {
|
2020-12-20 21:16:57 +00:00
|
|
|
client: new LemmyHttp('http://localhost:8581/api/v2'),
|
2020-08-20 12:44:22 +00:00
|
|
|
};
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function setupLogins() {
|
2020-12-20 21:16:57 +00:00
|
|
|
let formAlpha: Login = {
|
2020-08-04 14:57:37 +00:00
|
|
|
username_or_email: 'lemmy_alpha',
|
|
|
|
password: 'lemmy',
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resAlpha = alpha.client.login(formAlpha);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-08-20 12:44:22 +00:00
|
|
|
let formBeta = {
|
2020-08-04 14:57:37 +00:00
|
|
|
username_or_email: 'lemmy_beta',
|
|
|
|
password: 'lemmy',
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resBeta = beta.client.login(formBeta);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-08-20 12:44:22 +00:00
|
|
|
let formGamma = {
|
2020-08-04 14:57:37 +00:00
|
|
|
username_or_email: 'lemmy_gamma',
|
|
|
|
password: 'lemmy',
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resGamma = gamma.client.login(formGamma);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-08-20 12:44:22 +00:00
|
|
|
let formDelta = {
|
|
|
|
username_or_email: 'lemmy_delta',
|
|
|
|
password: 'lemmy',
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resDelta = delta.client.login(formDelta);
|
2020-08-20 12:44:22 +00:00
|
|
|
|
|
|
|
let formEpsilon = {
|
|
|
|
username_or_email: 'lemmy_epsilon',
|
|
|
|
password: 'lemmy',
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
let resEpsilon = epsilon.client.login(formEpsilon);
|
2020-08-20 12:44:22 +00:00
|
|
|
|
|
|
|
let res = await Promise.all([
|
|
|
|
resAlpha,
|
|
|
|
resBeta,
|
|
|
|
resGamma,
|
|
|
|
resDelta,
|
|
|
|
resEpsilon,
|
|
|
|
]);
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
alpha.auth = res[0].jwt;
|
|
|
|
beta.auth = res[1].jwt;
|
|
|
|
gamma.auth = res[2].jwt;
|
2020-08-20 12:44:22 +00:00
|
|
|
delta.auth = res[3].jwt;
|
|
|
|
epsilon.auth = res[4].jwt;
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createPost(
|
|
|
|
api: API,
|
|
|
|
community_id: number
|
|
|
|
): Promise<PostResponse> {
|
2020-11-10 16:53:35 +00:00
|
|
|
let name = randomString(5);
|
|
|
|
let body = randomString(10);
|
2020-09-15 19:26:47 +00:00
|
|
|
let url = 'https://google.com/';
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: CreatePost = {
|
2020-08-04 14:57:37 +00:00
|
|
|
name,
|
2020-09-15 19:26:47 +00:00
|
|
|
url,
|
|
|
|
body,
|
2020-08-04 14:57:37 +00:00
|
|
|
auth: api.auth,
|
|
|
|
community_id,
|
|
|
|
nsfw: false,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.createPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
export async function editPost(api: API, post: Post): Promise<PostResponse> {
|
2020-08-04 14:57:37 +00:00
|
|
|
let name = 'A jest test federated post, updated';
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: EditPost = {
|
2020-08-04 14:57:37 +00:00
|
|
|
name,
|
2021-01-18 21:57:31 +00:00
|
|
|
post_id: post.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
auth: api.auth,
|
|
|
|
nsfw: false,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.editPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function deletePost(
|
|
|
|
api: API,
|
|
|
|
deleted: boolean,
|
|
|
|
post: Post
|
|
|
|
): Promise<PostResponse> {
|
2020-12-20 21:16:57 +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,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.deletePost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function removePost(
|
|
|
|
api: API,
|
|
|
|
removed: boolean,
|
|
|
|
post: Post
|
|
|
|
): Promise<PostResponse> {
|
2020-12-20 21:16:57 +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,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.removePost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function stickyPost(
|
|
|
|
api: API,
|
|
|
|
stickied: boolean,
|
|
|
|
post: Post
|
|
|
|
): Promise<PostResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: StickyPost = {
|
2021-01-18 21:57:31 +00:00
|
|
|
post_id: post.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
stickied,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.stickyPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function lockPost(
|
|
|
|
api: API,
|
|
|
|
locked: boolean,
|
|
|
|
post: Post
|
|
|
|
): Promise<PostResponse> {
|
2020-12-20 21:16:57 +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,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.lockPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function searchPost(
|
|
|
|
api: API,
|
|
|
|
post: Post
|
|
|
|
): Promise<SearchResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: Search = {
|
2020-08-20 14:50:26 +00:00
|
|
|
q: post.ap_id,
|
2020-08-31 13:48:02 +00:00
|
|
|
type_: SearchType.Posts,
|
2020-08-20 14:50:26 +00:00
|
|
|
sort: SortType.TopAll,
|
|
|
|
};
|
|
|
|
return api.client.search(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 16:53:35 +00:00
|
|
|
export async function searchPostLocal(
|
|
|
|
api: API,
|
|
|
|
post: Post
|
|
|
|
): Promise<SearchResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: Search = {
|
2020-11-10 16:53:35 +00:00
|
|
|
q: post.name,
|
|
|
|
type_: SearchType.Posts,
|
|
|
|
sort: SortType.TopAll,
|
|
|
|
};
|
|
|
|
return api.client.search(form);
|
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function getPost(
|
|
|
|
api: API,
|
|
|
|
post_id: number
|
|
|
|
): Promise<GetPostResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: GetPost = {
|
2020-08-20 14:50:26 +00:00
|
|
|
id: post_id,
|
|
|
|
};
|
|
|
|
return api.client.getPost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function searchComment(
|
|
|
|
api: API,
|
|
|
|
comment: Comment
|
|
|
|
): Promise<SearchResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: Search = {
|
2020-08-20 14:50:26 +00:00
|
|
|
q: comment.ap_id,
|
2020-08-31 13:48:02 +00:00
|
|
|
type_: SearchType.Comments,
|
2020-08-20 14:50:26 +00:00
|
|
|
sort: SortType.TopAll,
|
|
|
|
};
|
|
|
|
return api.client.search(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function searchForBetaCommunity(
|
|
|
|
api: API
|
|
|
|
): Promise<SearchResponse> {
|
|
|
|
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
|
|
|
|
// Use short-hand search url
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: Search = {
|
2020-09-15 19:26:47 +00:00
|
|
|
q: '!main@lemmy-beta:8551',
|
|
|
|
type_: SearchType.Communities,
|
|
|
|
sort: SortType.TopAll,
|
|
|
|
};
|
|
|
|
return api.client.search(form);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function searchForCommunity(
|
|
|
|
api: API,
|
2020-12-20 21:16:57 +00:00
|
|
|
q: string
|
2020-09-15 19:26:47 +00:00
|
|
|
): Promise<SearchResponse> {
|
|
|
|
// Use short-hand search url
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: Search = {
|
2020-09-15 19:26:47 +00:00
|
|
|
q,
|
2020-08-31 13:48:02 +00:00
|
|
|
type_: SearchType.Communities,
|
2020-08-20 14:50:26 +00:00
|
|
|
sort: SortType.TopAll,
|
|
|
|
};
|
|
|
|
return api.client.search(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 15:06:27 +00:00
|
|
|
export async function searchForUser(
|
|
|
|
api: API,
|
|
|
|
apShortname: string
|
|
|
|
): Promise<SearchResponse> {
|
|
|
|
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
|
|
|
|
// Use short-hand search url
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: Search = {
|
2020-08-20 14:50:26 +00:00
|
|
|
q: apShortname,
|
2020-08-31 13:48:02 +00:00
|
|
|
type_: SearchType.Users,
|
2020-08-20 14:50:26 +00:00
|
|
|
sort: SortType.TopAll,
|
|
|
|
};
|
|
|
|
return api.client.search(form);
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 19:09:03 +00:00
|
|
|
export async function banPersonFromSite(
|
2020-11-10 16:53:35 +00:00
|
|
|
api: API,
|
2021-03-12 19:09:03 +00:00
|
|
|
person_id: number,
|
2020-12-20 21:16:57 +00:00
|
|
|
ban: boolean
|
2021-03-12 19:09:03 +00:00
|
|
|
): Promise<BanPersonResponse> {
|
2020-11-10 16:53:35 +00:00
|
|
|
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
|
|
|
|
// Use short-hand search url
|
2021-03-12 19:09:03 +00:00
|
|
|
let form: BanPerson = {
|
|
|
|
person_id,
|
2020-11-10 16:53:35 +00:00
|
|
|
ban,
|
2020-12-20 21:16:57 +00:00
|
|
|
remove_data: false,
|
2020-11-10 16:53:35 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
2021-03-12 19:09:03 +00:00
|
|
|
return api.client.banPerson(form);
|
2020-11-10 16:53:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 19:09:03 +00:00
|
|
|
export async function banPersonFromCommunity(
|
2020-11-10 16:53:35 +00:00
|
|
|
api: API,
|
2021-03-12 19:09:03 +00:00
|
|
|
person_id: number,
|
2020-11-10 16:53:35 +00:00
|
|
|
community_id: number,
|
2020-12-20 21:16:57 +00:00
|
|
|
ban: boolean
|
2020-11-10 16:53:35 +00:00
|
|
|
): Promise<BanFromCommunityResponse> {
|
|
|
|
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
|
|
|
|
// Use short-hand search url
|
2020-12-20 21:16:57 +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,
|
2020-12-20 21:16:57 +00:00
|
|
|
remove_data: false,
|
2020-11-10 16:53:35 +00:00
|
|
|
ban,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
|
|
|
return api.client.banFromCommunity(form);
|
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function followCommunity(
|
|
|
|
api: API,
|
|
|
|
follow: boolean,
|
|
|
|
community_id: number
|
|
|
|
): Promise<CommunityResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: FollowCommunity = {
|
2020-08-04 14:57:37 +00:00
|
|
|
community_id,
|
|
|
|
follow,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.followCommunity(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function checkFollowedCommunities(
|
|
|
|
api: API
|
|
|
|
): Promise<GetFollowedCommunitiesResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: GetFollowedCommunities = {
|
2020-08-20 14:50:26 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
|
|
|
return api.client.getFollowedCommunities(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function likePost(
|
|
|
|
api: API,
|
|
|
|
score: number,
|
|
|
|
post: Post
|
|
|
|
): Promise<PostResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: CreatePostLike = {
|
2020-08-04 14:57:37 +00:00
|
|
|
post_id: post.id,
|
|
|
|
score: score,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
|
|
|
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.likePost(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createComment(
|
|
|
|
api: API,
|
|
|
|
post_id: number,
|
|
|
|
parent_id?: number,
|
|
|
|
content = 'a jest test comment'
|
|
|
|
): Promise<CommentResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: CreateComment = {
|
2020-08-04 14:57:37 +00:00
|
|
|
content,
|
|
|
|
post_id,
|
|
|
|
parent_id,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.createComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
export async function editComment(
|
2020-08-04 14:57:37 +00:00
|
|
|
api: API,
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id: number,
|
2020-08-04 14:57:37 +00:00
|
|
|
content = 'A jest test federated comment update'
|
|
|
|
): Promise<CommentResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: EditComment = {
|
2020-08-04 14:57:37 +00:00
|
|
|
content,
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.editComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function deleteComment(
|
|
|
|
api: API,
|
|
|
|
deleted: boolean,
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id: number
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<CommentResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: DeleteComment = {
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
deleted,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.deleteComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function removeComment(
|
|
|
|
api: API,
|
|
|
|
removed: boolean,
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id: number
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<CommentResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: RemoveComment = {
|
2021-01-18 21:57:31 +00:00
|
|
|
comment_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
removed,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.removeComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 19:09:03 +00:00
|
|
|
export async function getMentions(api: API): Promise<GetPersonMentionsResponse> {
|
|
|
|
let form: GetPersonMentions = {
|
2020-08-20 14:50:26 +00:00
|
|
|
sort: SortType.New,
|
|
|
|
unread_only: false,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2021-03-12 19:09:03 +00:00
|
|
|
return api.client.getPersonMentions(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function likeComment(
|
|
|
|
api: API,
|
|
|
|
score: number,
|
|
|
|
comment: Comment
|
|
|
|
): Promise<CommentResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: CreateCommentLike = {
|
2020-08-04 14:57:37 +00:00
|
|
|
comment_id: comment.id,
|
|
|
|
score,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.likeComment(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createCommunity(
|
|
|
|
api: API,
|
|
|
|
name_: string = randomString(5)
|
|
|
|
): Promise<CommunityResponse> {
|
2020-09-15 19:26:47 +00:00
|
|
|
let description = 'a sample description';
|
|
|
|
let icon = 'https://image.flaticon.com/icons/png/512/35/35896.png';
|
|
|
|
let banner = 'https://image.flaticon.com/icons/png/512/35/35896.png';
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: CreateCommunity = {
|
2020-08-04 14:57:37 +00:00
|
|
|
name: name_,
|
|
|
|
title: name_,
|
2020-09-15 19:26:47 +00:00
|
|
|
description,
|
|
|
|
icon,
|
|
|
|
banner,
|
2020-08-04 14:57:37 +00:00
|
|
|
nsfw: false,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.createCommunity(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 20:19:06 +00:00
|
|
|
export async function getCommunity(
|
|
|
|
api: API,
|
2020-12-20 21:16:57 +00:00
|
|
|
id: number
|
2020-11-05 20:19:06 +00:00
|
|
|
): Promise<CommunityResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: GetCommunity = {
|
2020-11-05 20:19:06 +00:00
|
|
|
id,
|
|
|
|
};
|
|
|
|
return api.client.getCommunity(form);
|
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function deleteCommunity(
|
|
|
|
api: API,
|
|
|
|
deleted: boolean,
|
2021-01-18 21:57:31 +00:00
|
|
|
community_id: number
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<CommunityResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: DeleteCommunity = {
|
2021-01-18 21:57:31 +00:00
|
|
|
community_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
deleted,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.deleteCommunity(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function removeCommunity(
|
|
|
|
api: API,
|
|
|
|
removed: boolean,
|
2021-01-18 21:57:31 +00:00
|
|
|
community_id: number
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<CommunityResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: RemoveCommunity = {
|
2021-01-18 21:57:31 +00:00
|
|
|
community_id,
|
2020-08-04 14:57:37 +00:00
|
|
|
removed,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.removeCommunity(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createPrivateMessage(
|
|
|
|
api: API,
|
|
|
|
recipient_id: number
|
|
|
|
): Promise<PrivateMessageResponse> {
|
|
|
|
let content = 'A jest test federated private message';
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: CreatePrivateMessage = {
|
2020-08-04 14:57:37 +00:00
|
|
|
content,
|
|
|
|
recipient_id,
|
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.createPrivateMessage(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
export async function editPrivateMessage(
|
2020-08-04 14:57:37 +00:00
|
|
|
api: API,
|
2021-01-18 21:57:31 +00:00
|
|
|
private_message_id: number
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<PrivateMessageResponse> {
|
|
|
|
let updatedContent = 'A jest test federated private message edited';
|
2020-12-20 21:16:57 +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,
|
2020-08-04 14:57:37 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.editPrivateMessage(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function deletePrivateMessage(
|
|
|
|
api: API,
|
|
|
|
deleted: boolean,
|
2021-01-18 21:57:31 +00:00
|
|
|
private_message_id: number
|
2020-08-04 14:57:37 +00:00
|
|
|
): Promise<PrivateMessageResponse> {
|
2020-12-20 21:16:57 +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,
|
2020-08-04 14:57:37 +00:00
|
|
|
auth: api.auth,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.deletePrivateMessage(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 15:06:27 +00:00
|
|
|
export async function registerUser(
|
|
|
|
api: API,
|
|
|
|
username: string = randomString(5)
|
|
|
|
): Promise<LoginResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: Register = {
|
2020-08-04 15:06:27 +00:00
|
|
|
username,
|
|
|
|
password: 'test',
|
|
|
|
password_verify: 'test',
|
|
|
|
show_nsfw: true,
|
|
|
|
};
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.register(form);
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function saveUserSettingsBio(
|
|
|
|
api: API,
|
|
|
|
auth: string
|
|
|
|
): Promise<LoginResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: SaveUserSettings = {
|
2020-08-04 15:06:27 +00:00
|
|
|
show_nsfw: true,
|
|
|
|
theme: 'darkly',
|
2021-01-04 19:09:53 +00:00
|
|
|
default_sort_type: Object.keys(SortType).indexOf(SortType.Active),
|
|
|
|
default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
|
2020-08-04 15:06:27 +00:00
|
|
|
lang: 'en',
|
|
|
|
show_avatars: true,
|
|
|
|
send_notifications_to_email: false,
|
|
|
|
bio: 'a changed bio',
|
|
|
|
auth,
|
|
|
|
};
|
2020-09-17 15:41:51 +00:00
|
|
|
return saveUserSettings(api, form);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function saveUserSettings(
|
|
|
|
api: API,
|
2020-12-20 21:16:57 +00:00
|
|
|
form: SaveUserSettings
|
2020-09-17 15:41:51 +00:00
|
|
|
): Promise<LoginResponse> {
|
2020-08-20 14:50:26 +00:00
|
|
|
return api.client.saveUserSettings(form);
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getSite(
|
|
|
|
api: API,
|
|
|
|
auth: string
|
|
|
|
): Promise<GetSiteResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: GetSite = {
|
2020-08-20 14:50:26 +00:00
|
|
|
auth,
|
|
|
|
};
|
|
|
|
return api.client.getSite(form);
|
2020-08-04 15:06:27 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
export async function listPrivateMessages(
|
|
|
|
api: API
|
|
|
|
): Promise<PrivateMessagesResponse> {
|
2020-12-20 21:16:57 +00:00
|
|
|
let form: GetPrivateMessages = {
|
2020-08-20 14:50:26 +00:00
|
|
|
auth: api.auth,
|
|
|
|
unread_only: false,
|
|
|
|
limit: 999,
|
|
|
|
};
|
|
|
|
return api.client.getPrivateMessages(form);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function unfollowRemotes(
|
|
|
|
api: API
|
|
|
|
): Promise<GetFollowedCommunitiesResponse> {
|
|
|
|
// Unfollow all remote communities
|
|
|
|
let followed = await checkFollowedCommunities(api);
|
|
|
|
let remoteFollowed = followed.communities.filter(
|
2020-12-20 21:16:57 +00:00
|
|
|
c => c.community.local == false
|
2020-08-04 14:57:37 +00:00
|
|
|
);
|
|
|
|
for (let cu of remoteFollowed) {
|
2020-12-20 21:16:57 +00:00
|
|
|
await followCommunity(api, false, cu.community.id);
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
let followed2 = await checkFollowedCommunities(api);
|
|
|
|
return followed2;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function followBeta(api: API): Promise<CommunityResponse> {
|
|
|
|
// Cache it
|
|
|
|
let search = await searchForBetaCommunity(api);
|
2020-12-20 21:16:57 +00:00
|
|
|
let com = search.communities.find(c => c.community.local == false);
|
|
|
|
if (com) {
|
|
|
|
let follow = await followCommunity(api, true, com.community.id);
|
2020-08-04 15:06:27 +00:00
|
|
|
return follow;
|
|
|
|
}
|
2020-08-04 14:57:37 +00:00
|
|
|
}
|
|
|
|
|
2020-10-01 13:32:01 +00:00
|
|
|
export function delay(millis: number = 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
function randomString(length: number): string {
|
|
|
|
var result = '';
|
|
|
|
var characters = 'abcdefghijklmnopqrstuvwxyz0123456789_';
|
|
|
|
var charactersLength = characters.length;
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|