SearchResponse,
FollowCommunity,
CommunityResponse,
- GetFollowedCommunitiesResponse,
GetPostResponse,
Register,
Comment,
CreateCommunity,
DeleteCommunity,
RemoveCommunity,
- GetUserMentions,
+ GetPersonMentions,
CreateCommentLike,
CreatePostLike,
EditPrivateMessage,
DeletePrivateMessage,
- GetFollowedCommunities,
GetPrivateMessages,
GetSite,
GetPost,
PrivateMessageResponse,
PrivateMessagesResponse,
- GetUserMentionsResponse,
+ GetPersonMentionsResponse,
SaveUserSettings,
SortType,
ListingType,
GetSiteResponse,
SearchType,
LemmyHttp,
- BanUserResponse,
- BanUser,
+ BanPersonResponse,
+ BanPerson,
BanFromCommunity,
BanFromCommunityResponse,
Post,
CreatePrivateMessage,
+ ResolveObjectResponse,
+ ResolveObject,
+ CreatePostReport,
+ ListPostReports,
+ PostReportResponse,
+ ListPostReportsResponse,
+ CreateCommentReport,
+ CommentReportResponse,
+ ListCommentReports,
+ ListCommentReportsResponse,
+ DeleteAccount,
+ DeleteAccountResponse
} from 'lemmy-js-client';
export interface API {
}
export let alpha: API = {
- client: new LemmyHttp('http://localhost:8541/api/v2'),
+ client: new LemmyHttp('http://127.0.0.1:8541'),
};
export let beta: API = {
- client: new LemmyHttp('http://localhost:8551/api/v2'),
+ client: new LemmyHttp('http://127.0.0.1:8551'),
};
export let gamma: API = {
- client: new LemmyHttp('http://localhost:8561/api/v2'),
+ client: new LemmyHttp('http://127.0.0.1:8561'),
};
export let delta: API = {
- client: new LemmyHttp('http://localhost:8571/api/v2'),
+ client: new LemmyHttp('http://127.0.0.1:8571'),
};
export let epsilon: API = {
- client: new LemmyHttp('http://localhost:8581/api/v2'),
+ client: new LemmyHttp('http://127.0.0.1:8581'),
};
+const password = 'lemmylemmy'
+
export async function setupLogins() {
let formAlpha: Login = {
username_or_email: 'lemmy_alpha',
- password: 'lemmy',
+ password,
};
let resAlpha = alpha.client.login(formAlpha);
let formBeta = {
username_or_email: 'lemmy_beta',
- password: 'lemmy',
+ password,
};
let resBeta = beta.client.login(formBeta);
let formGamma = {
username_or_email: 'lemmy_gamma',
- password: 'lemmy',
+ password,
};
let resGamma = gamma.client.login(formGamma);
let formDelta = {
username_or_email: 'lemmy_delta',
- password: 'lemmy',
+ password,
};
let resDelta = delta.client.login(formDelta);
let formEpsilon = {
username_or_email: 'lemmy_epsilon',
- password: 'lemmy',
+ password,
};
let resEpsilon = epsilon.client.login(formEpsilon);
gamma.auth = res[2].jwt;
delta.auth = res[3].jwt;
epsilon.auth = res[4].jwt;
+
+ // regstration applications are now enabled by default, need to disable them
+ await alpha.client.editSite({ require_application: false, auth: alpha.auth});
+ await beta.client.editSite({ require_application: false, auth: beta.auth});
+ await gamma.client.editSite({ require_application: false, auth: gamma.auth});
+ await delta.client.editSite({ require_application: false, auth: delta.auth});
+ await epsilon.client.editSite({ require_application: false, auth: epsilon.auth});
}
export async function createPost(
return api.client.lockPost(form);
}
-export async function searchPost(
+export async function resolvePost(
api: API,
post: Post
-): Promise<SearchResponse> {
- let form: Search = {
+): Promise<ResolveObjectResponse> {
+ let form: ResolveObject = {
q: post.ap_id,
- type_: SearchType.Posts,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
export async function searchPostLocal(
return api.client.getPost(form);
}
-export async function searchComment(
+export async function resolveComment(
api: API,
comment: Comment
-): Promise<SearchResponse> {
- let form: Search = {
+): Promise<ResolveObjectResponse> {
+ let form: ResolveObject = {
q: comment.ap_id,
- type_: SearchType.Comments,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
-export async function searchForBetaCommunity(
+export async function resolveBetaCommunity(
api: API
-): Promise<SearchResponse> {
- // Make sure lemmy-beta/c/main is cached on lemmy_alpha
+): Promise<ResolveObjectResponse> {
// Use short-hand search url
- let form: Search = {
+ let form: ResolveObject = {
q: '!main@lemmy-beta:8551',
- type_: SearchType.Communities,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
-export async function searchForCommunity(
+export async function resolveCommunity(
api: API,
q: string
-): Promise<SearchResponse> {
- // Use short-hand search url
- let form: Search = {
+): Promise<ResolveObjectResponse> {
+ let form: ResolveObject = {
q,
- type_: SearchType.Communities,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
-export async function searchForUser(
+export async function resolvePerson(
api: API,
apShortname: string
-): Promise<SearchResponse> {
- // Make sure lemmy-beta/c/main is cached on lemmy_alpha
- // Use short-hand search url
- let form: Search = {
+): Promise<ResolveObjectResponse> {
+ let form: ResolveObject = {
q: apShortname,
- type_: SearchType.Users,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
-export async function banUserFromSite(
+export async function banPersonFromSite(
api: API,
- user_id: number,
- ban: boolean
-): Promise<BanUserResponse> {
+ person_id: number,
+ ban: boolean,
+ remove_data: boolean,
+): Promise<BanPersonResponse> {
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
- // Use short-hand search url
- let form: BanUser = {
- user_id,
+ let form: BanPerson = {
+ person_id,
ban,
- remove_data: false,
+ remove_data,
auth: api.auth,
};
- return api.client.banUser(form);
+ return api.client.banPerson(form);
}
-export async function banUserFromCommunity(
+export async function banPersonFromCommunity(
api: API,
- user_id: number,
+ person_id: number,
community_id: number,
+ remove_data: boolean,
ban: boolean
): Promise<BanFromCommunityResponse> {
- // Make sure lemmy-beta/c/main is cached on lemmy_alpha
- // Use short-hand search url
let form: BanFromCommunity = {
- user_id,
+ person_id,
community_id,
- remove_data: false,
+ remove_data,
ban,
auth: api.auth,
};
return api.client.followCommunity(form);
}
-export async function checkFollowedCommunities(
- api: API
-): Promise<GetFollowedCommunitiesResponse> {
- let form: GetFollowedCommunities = {
- auth: api.auth,
- };
- return api.client.getFollowedCommunities(form);
-}
-
export async function likePost(
api: API,
score: number,
return api.client.removeComment(form);
}
-export async function getMentions(api: API): Promise<GetUserMentionsResponse> {
- let form: GetUserMentions = {
+export async function getMentions(api: API): Promise<GetPersonMentionsResponse> {
+ let form: GetPersonMentions = {
sort: SortType.New,
unread_only: false,
auth: api.auth,
};
- return api.client.getUserMentions(form);
+ return api.client.getPersonMentions(form);
}
export async function likeComment(
name_: string = randomString(5)
): Promise<CommunityResponse> {
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';
let form: CreateCommunity = {
name: name_,
title: name_,
description,
- icon,
- banner,
- category_id: 1,
nsfw: false,
auth: api.auth,
};
): Promise<LoginResponse> {
let form: Register = {
username,
- password: 'test',
- password_verify: 'test',
+ password,
+ password_verify: password,
show_nsfw: true,
};
return api.client.register(form);
}
export async function saveUserSettingsBio(
- api: API,
- auth: string
+ api: API
): Promise<LoginResponse> {
let form: SaveUserSettings = {
show_nsfw: true,
show_avatars: true,
send_notifications_to_email: false,
bio: 'a changed bio',
- auth,
+ auth: api.auth,
};
return saveUserSettings(api, form);
}
return api.client.saveUserSettings(form);
}
-export async function getSite(
+export async function deleteUser(
api: API,
- auth: string
+): Promise<DeleteAccountResponse> {
+ let form: DeleteAccount = {
+ auth: api.auth,
+ password
+ };
+ return api.client.deleteAccount(form);
+}
+
+export async function getSite(
+ api: API
): Promise<GetSiteResponse> {
let form: GetSite = {
- auth,
+ auth: api.auth,
};
return api.client.getSite(form);
}
export async function unfollowRemotes(
api: API
-): Promise<GetFollowedCommunitiesResponse> {
+): Promise<GetSiteResponse> {
// Unfollow all remote communities
- let followed = await checkFollowedCommunities(api);
- let remoteFollowed = followed.communities.filter(
+ let site = await getSite(api);
+ let remoteFollowed = site.my_user.follows.filter(
c => c.community.local == false
);
for (let cu of remoteFollowed) {
await followCommunity(api, false, cu.community.id);
}
- let followed2 = await checkFollowedCommunities(api);
- return followed2;
+ let siteRes = await getSite(api);
+ return siteRes;
}
export async function followBeta(api: API): Promise<CommunityResponse> {
- // Cache it
- let search = await searchForBetaCommunity(api);
- let com = search.communities.find(c => c.community.local == false);
- if (com) {
- let follow = await followCommunity(api, true, com.community.id);
+ let betaCommunity = (await resolveBetaCommunity(api)).community;
+ if (betaCommunity) {
+ let follow = await followCommunity(api, true, betaCommunity.community.id);
return follow;
}
}
+export async function reportPost(
+ api: API,
+ post_id: number,
+ reason: string,
+): Promise<PostReportResponse> {
+ let form: CreatePostReport = {
+ post_id,
+ reason,
+ auth: api.auth,
+ };
+ return api.client.createPostReport(form);
+}
+
+export async function listPostReports(api: API): Promise<ListPostReportsResponse> {
+ let form: ListPostReports = {
+ auth: api.auth,
+ };
+ return api.client.listPostReports(form);
+}
+
+export async function reportComment(
+ api: API,
+ comment_id: number,
+ reason: string,
+): Promise<CommentReportResponse> {
+ let form: CreateCommentReport = {
+ comment_id,
+ reason,
+ auth: api.auth,
+ };
+ return api.client.createCommentReport(form);
+}
+
+export async function listCommentReports(api: API): Promise<ListCommentReportsResponse> {
+ let form: ListCommentReports = {
+ auth: api.auth,
+ };
+ return api.client.listCommentReports(form);
+}
+
export function delay(millis: number = 500) {
return new Promise(resolve => setTimeout(resolve, millis));
}
return JSON.stringify(form);
}
-function randomString(length: number): string {
+export function randomString(length: number): string {
var result = '';
- var characters = 'abcdefghijklmnopqrstuvwxyz0123456789_';
+ var characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
+
+export async function unfollows() {
+ await unfollowRemotes(alpha);
+ await unfollowRemotes(gamma);
+ await unfollowRemotes(delta);
+ await unfollowRemotes(epsilon);
+}