@ -3,7 +3,6 @@ import {
BlockInstanceResponse ,
GetReplies ,
GetRepliesResponse ,
GetUnreadCount ,
GetUnreadCountResponse ,
InstanceId ,
LemmyHttp ,
@ -56,7 +55,6 @@ import { SaveUserSettings } from "lemmy-js-client/dist/types/SaveUserSettings";
import { DeleteAccount } from "lemmy-js-client/dist/types/DeleteAccount" ;
import { GetSiteResponse } from "lemmy-js-client/dist/types/GetSiteResponse" ;
import { DeleteAccountResponse } from "lemmy-js-client/dist/types/DeleteAccountResponse" ;
import { GetSite } from "lemmy-js-client/dist/types/GetSite" ;
import { PrivateMessagesResponse } from "lemmy-js-client/dist/types/PrivateMessagesResponse" ;
import { GetPrivateMessages } from "lemmy-js-client/dist/types/GetPrivateMessages" ;
import { PostReportResponse } from "lemmy-js-client/dist/types/PostReportResponse" ;
@ -73,35 +71,17 @@ import { GetPersonDetailsResponse } from "lemmy-js-client/dist/types/GetPersonDe
import { GetPersonDetails } from "lemmy-js-client/dist/types/GetPersonDetails" ;
import { ListingType } from "lemmy-js-client/dist/types/ListingType" ;
export interface API {
client : LemmyHttp ;
auth : string ;
}
export let alpha : API = {
client : new LemmyHttp ( "http://127.0.0.1:8541" ) ,
auth : "" ,
} ;
export let beta : API = {
client : new LemmyHttp ( "http://127.0.0.1:8551" ) ,
auth : "" ,
} ;
export let gamma : API = {
client : new LemmyHttp ( "http://127.0.0.1:8561" ) ,
auth : "" ,
} ;
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" ;
export let delta : API = {
client : new LemmyHttp ( "http://127.0.0.1:8571" ) ,
auth : "" ,
} ;
export let epsilon : API = {
client : new LemmyHttp ( "http://127.0.0.1:8581" ) ,
auth : "" ,
} ;
export let alpha = new LemmyHttp ( alphaUrl ) ;
export let beta = new LemmyHttp ( betaUrl ) ;
export let gamma = new LemmyHttp ( gammaUrl ) ;
export let delta = new LemmyHttp ( deltaUrl ) ;
export let epsilon = new LemmyHttp ( epsilonUrl ) ;
const password = "lemmylemmy" ;
@ -110,31 +90,31 @@ export async function setupLogins() {
username_or_email : "lemmy_alpha" ,
password ,
} ;
let resAlpha = alpha . client. login( formAlpha ) ;
let resAlpha = alpha . login( formAlpha ) ;
let formBeta : Login = {
username_or_email : "lemmy_beta" ,
password ,
} ;
let resBeta = beta . client. login( formBeta ) ;
let resBeta = beta . login( formBeta ) ;
let formGamma : Login = {
username_or_email : "lemmy_gamma" ,
password ,
} ;
let resGamma = gamma . client. login( formGamma ) ;
let resGamma = gamma . login( formGamma ) ;
let formDelta : Login = {
username_or_email : "lemmy_delta" ,
password ,
} ;
let resDelta = delta . client. login( formDelta ) ;
let resDelta = delta . login( formDelta ) ;
let formEpsilon : Login = {
username_or_email : "lemmy_epsilon" ,
password ,
} ;
let resEpsilon = epsilon . client. login( formEpsilon ) ;
let resEpsilon = epsilon . login( formEpsilon ) ;
let res = await Promise . all ( [
resAlpha ,
@ -143,12 +123,11 @@ export async function setupLogins() {
resDelta ,
resEpsilon ,
] ) ;
alpha . auth = res [ 0 ] . jwt ? ? "" ;
beta . auth = res [ 1 ] . jwt ? ? "" ;
gamma . auth = res [ 2 ] . jwt ? ? "" ;
delta . auth = res [ 3 ] . jwt ? ? "" ;
epsilon . auth = res [ 4 ] . jwt ? ? "" ;
alpha . setHeaders ( { auth : res [ 0 ] . jwt ? ? "" } ) ;
beta . setHeaders ( { auth : res [ 1 ] . jwt ? ? "" } ) ;
gamma . setHeaders ( { auth : res [ 2 ] . jwt ? ? "" } ) ;
delta . setHeaders ( { auth : res [ 3 ] . jwt ? ? "" } ) ;
epsilon . setHeaders ( { auth : res [ 4 ] . jwt ? ? "" } ) ;
// Registration applications are now enabled by default, need to disable them
let editSiteForm : EditSite = {
@ -159,45 +138,39 @@ export async function setupLogins() {
rate_limit_image : 999 ,
rate_limit_comment : 999 ,
rate_limit_search : 999 ,
auth : "" ,
} ;
// Set the blocks and auths for each
editSiteForm . auth = alpha . auth ;
editSiteForm . allowed_instances = [
"lemmy-beta" ,
"lemmy-gamma" ,
"lemmy-delta" ,
"lemmy-epsilon" ,
] ;
await alpha . client. editSite( editSiteForm ) ;
await alpha . editSite( editSiteForm ) ;
editSiteForm . auth = beta . auth ;
editSiteForm . allowed_instances = [
"lemmy-alpha" ,
"lemmy-gamma" ,
"lemmy-delta" ,
"lemmy-epsilon" ,
] ;
await beta . client. editSite( editSiteForm ) ;
await beta . editSite( editSiteForm ) ;
editSiteForm . auth = gamma . auth ;
editSiteForm . allowed_instances = [
"lemmy-alpha" ,
"lemmy-beta" ,
"lemmy-delta" ,
"lemmy-epsilon" ,
] ;
await gamma . client. editSite( editSiteForm ) ;
await gamma . editSite( editSiteForm ) ;
editSiteForm . allowed_instances = [ "lemmy-beta" ] ;
editSiteForm . auth = delta . auth ;
await delta . client . editSite ( editSiteForm ) ;
await delta . editSite ( editSiteForm ) ;
editSiteForm . auth = epsilon . auth ;
editSiteForm . allowed_instances = [ ] ;
editSiteForm . blocked_instances = [ "lemmy-alpha" ] ;
await epsilon . client. editSite( editSiteForm ) ;
await epsilon . editSite( editSiteForm ) ;
// Create the main alpha/beta communities
// Ignore thrown errors of duplicates
@ -215,7 +188,7 @@ export async function setupLogins() {
}
export async function createPost (
api : API ,
api : LemmyHttp ,
community_id : number ,
) : Promise < PostResponse > {
let name = randomString ( 5 ) ;
@ -227,50 +200,49 @@ export async function createPost(
name ,
url ,
body ,
auth : api.auth ,
community_id ,
} ;
return api . c lient. c reatePost( form ) ;
return api . c reatePost( form ) ;
}
export async function editPost ( api : API , post : Post ) : Promise < PostResponse > {
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 ,
auth : api.auth ,
} ;
return api . client. editPost( form ) ;
return api . editPost( form ) ;
}
export async function deletePost (
api : API ,
api : LemmyHttp ,
deleted : boolean ,
post : Post ,
) : Promise < PostResponse > {
let form : DeletePost = {
post_id : post.id ,
deleted : deleted ,
auth : api.auth ,
} ;
return api . client. deletePost( form ) ;
return api . deletePost( form ) ;
}
export async function removePost (
api : API ,
api : LemmyHttp ,
removed : boolean ,
post : Post ,
) : Promise < PostResponse > {
let form : RemovePost = {
post_id : post.id ,
removed ,
auth : api.auth ,
} ;
return api . client. removePost( form ) ;
return api . removePost( form ) ;
}
export async function featurePost (
api : API ,
api : LemmyHttp ,
featured : boolean ,
post : Post ,
) : Promise < PostResponse > {
@ -278,61 +250,56 @@ export async function featurePost(
post_id : post.id ,
featured ,
feature_type : "Community" ,
auth : api.auth ,
} ;
return api . client. featurePost( form ) ;
return api . featurePost( form ) ;
}
export async function lockPost (
api : API ,
api : LemmyHttp ,
locked : boolean ,
post : Post ,
) : Promise < PostResponse > {
let form : LockPost = {
post_id : post.id ,
locked ,
auth : api.auth ,
} ;
return api . client. lockPost( form ) ;
return api . lockPost( form ) ;
}
export async function resolvePost (
api : API ,
api : LemmyHttp ,
post : Post ,
) : Promise < ResolveObjectResponse > {
let form : ResolveObject = {
q : post.ap_id ,
auth : api.auth ,
} ;
return api . client. resolveObject( form ) ;
return api . resolveObject( form ) ;
}
export async function searchPostLocal (
api : API ,
api : LemmyHttp ,
post : Post ,
) : Promise < SearchResponse > {
let form : Search = {
q : post.name ,
type_ : "Posts" ,
sort : "TopAll" ,
auth : api.auth ,
} ;
return api . client. search( form ) ;
return api . search( form ) ;
}
export async function getPost (
api : API ,
api : LemmyHttp ,
post_id : number ,
) : Promise < GetPostResponse > {
let form : GetPost = {
id : post_id ,
auth : api.auth ,
} ;
return api . client. getPost( form ) ;
return api . getPost( form ) ;
}
export async function getComments (
api : API ,
api : LemmyHttp ,
post_id? : number ,
listingType : ListingType = "All" ,
) : Promise < GetCommentsResponse > {
@ -340,75 +307,66 @@ export async function getComments(
post_id : post_id ,
type_ : listingType ,
sort : "New" ,
auth : api.auth ,
} ;
return api . client. getComments( form ) ;
return api . getComments( form ) ;
}
export async function getUnreadCount (
api : API ,
api : LemmyHttp ,
) : Promise < GetUnreadCountResponse > {
let form : GetUnreadCount = {
auth : api.auth ,
} ;
return api . client . getUnreadCount ( form ) ;
return api . getUnreadCount ( ) ;
}
export async function getReplies ( api : API ) : Promise < GetRepliesResponse > {
export async function getReplies ( api : LemmyHttp ) : Promise < GetRepliesResponse > {
let form : GetReplies = {
sort : "New" ,
unread_only : false ,
auth : api.auth ,
} ;
return api . client. getReplies( form ) ;
return api . getReplies( form ) ;
}
export async function resolveComment (
api : API ,
api : LemmyHttp ,
comment : Comment ,
) : Promise < ResolveObjectResponse > {
let form : ResolveObject = {
q : comment.ap_id ,
auth : api.auth ,
} ;
return api . client. resolveObject( form ) ;
return api . resolveObject( form ) ;
}
export async function resolveBetaCommunity (
api : API ,
api : LemmyHttp ,
) : Promise < ResolveObjectResponse > {
// Use short-hand search url
let form : ResolveObject = {
q : "!main@lemmy-beta:8551" ,
auth : api.auth ,
} ;
return api . client. resolveObject( form ) ;
return api . resolveObject( form ) ;
}
export async function resolveCommunity (
api : API ,
api : LemmyHttp ,
q : string ,
) : Promise < ResolveObjectResponse > {
let form : ResolveObject = {
q ,
auth : api.auth ,
} ;
return api . client. resolveObject( form ) ;
return api . resolveObject( form ) ;
}
export async function resolvePerson (
api : API ,
api : LemmyHttp ,
apShortname : string ,
) : Promise < ResolveObjectResponse > {
let form : ResolveObject = {
q : apShortname ,
auth : api.auth ,
} ;
return api . client. resolveObject( form ) ;
return api . resolveObject( form ) ;
}
export async function banPersonFromSite (
api : API ,
api : LemmyHttp ,
person_id : number ,
ban : boolean ,
remove_data : boolean ,
@ -418,13 +376,12 @@ export async function banPersonFromSite(
person_id ,
ban ,
remove_data : remove_data ,
auth : api.auth ,
} ;
return api . client. banPerson( form ) ;
return api . banPerson( form ) ;
}
export async function banPersonFromCommunity (
api : API ,
api : LemmyHttp ,
person_id : number ,
community_id : number ,
remove_data : boolean ,
@ -435,40 +392,37 @@ export async function banPersonFromCommunity(
community_id ,
remove_data : remove_data ,
ban ,
auth : api.auth ,
} ;
return api . client. banFromCommunity( form ) ;
return api . banFromCommunity( form ) ;
}
export async function followCommunity (
api : API ,
api : LemmyHttp ,
follow : boolean ,
community_id : number ,
) : Promise < CommunityResponse > {
let form : FollowCommunity = {
community_id ,
follow ,
auth : api.auth ,
} ;
return api . client. followCommunity( form ) ;
return api . followCommunity( form ) ;
}
export async function likePost (
api : API ,
api : LemmyHttp ,
score : number ,
post : Post ,
) : Promise < PostResponse > {
let form : CreatePostLike = {
post_id : post.id ,
score : score ,
auth : api.auth ,
} ;
return api . client. likePost( form ) ;
return api . likePost( form ) ;
}
export async function createComment (
api : API ,
api : LemmyHttp ,
post_id : number ,
parent_id? : number ,
content = "a jest test comment" ,
@ -477,76 +431,70 @@ export async function createComment(
content ,
post_id ,
parent_id ,
auth : api.auth ,
} ;
return api . c lient. c reateComment( form ) ;
return api . c reateComment( form ) ;
}
export async function editComment (
api : API ,
api : LemmyHttp ,
comment_id : number ,
content = "A jest test federated comment update" ,
) : Promise < CommentResponse > {
let form : EditComment = {
content ,
comment_id ,
auth : api.auth ,
} ;
return api . client. editComment( form ) ;
return api . editComment( form ) ;
}
export async function deleteComment (
api : API ,
api : LemmyHttp ,
deleted : boolean ,
comment_id : number ,
) : Promise < CommentResponse > {
let form : DeleteComment = {
comment_id ,
deleted ,
auth : api.auth ,
} ;
return api . client. deleteComment( form ) ;
return api . deleteComment( form ) ;
}
export async function removeComment (
api : API ,
api : LemmyHttp ,
removed : boolean ,
comment_id : number ,
) : Promise < CommentResponse > {
let form : RemoveComment = {
comment_id ,
removed ,
auth : api.auth ,
} ;
return api . client. removeComment( form ) ;
return api . removeComment( form ) ;
}
export async function getMentions (
api : API ,
api : LemmyHttp ,
) : Promise < GetPersonMentionsResponse > {
let form : GetPersonMentions = {
sort : "New" ,
unread_only : false ,
auth : api.auth ,
} ;
return api . client. getPersonMentions( form ) ;
return api . getPersonMentions( form ) ;
}
export async function likeComment (
api : API ,
api : LemmyHttp ,
score : number ,
comment : Comment ,
) : Promise < CommentResponse > {
let form : CreateCommentLike = {
comment_id : comment.id ,
score ,
auth : api.auth ,
} ;
return api . client. likeComment( form ) ;
return api . likeComment( form ) ;
}
export async function createCommunity (
api : API ,
api : LemmyHttp ,
name_ : string = randomString ( 5 ) ,
) : Promise < CommunityResponse > {
let description = "a sample description" ;
@ -554,100 +502,92 @@ export async function createCommunity(
name : name_ ,
title : name_ ,
description ,
auth : api.auth ,
} ;
return api . c lient. c reateCommunity( form ) ;
return api . c reateCommunity( form ) ;
}
export async function getCommunity (
api : API ,
api : LemmyHttp ,
id : number ,
) : Promise < CommunityResponse > {
let form : GetCommunity = {
id ,
auth : api.auth ,
} ;
return api . client. getCommunity( form ) ;
return api . getCommunity( form ) ;
}
export async function getCommunityByName (
api : API ,
api : LemmyHttp ,
name : string ,
) : Promise < CommunityResponse > {
let form : GetCommunity = {
name ,
auth : api.auth ,
} ;
return api . client. getCommunity( form ) ;
return api . getCommunity( form ) ;
}
export async function deleteCommunity (
api : API ,
api : LemmyHttp ,
deleted : boolean ,
community_id : number ,
) : Promise < CommunityResponse > {
let form : DeleteCommunity = {
community_id ,
deleted ,
auth : api.auth ,
} ;
return api . client. deleteCommunity( form ) ;
return api . deleteCommunity( form ) ;
}
export async function removeCommunity (
api : API ,
api : LemmyHttp ,
removed : boolean ,
community_id : number ,
) : Promise < CommunityResponse > {
let form : RemoveCommunity = {
community_id ,
removed ,
auth : api.auth ,
} ;
return api . client. removeCommunity( form ) ;
return api . removeCommunity( form ) ;
}
export async function createPrivateMessage (
api : API ,
api : LemmyHttp ,
recipient_id : number ,
) : Promise < PrivateMessageResponse > {
let content = "A jest test federated private message" ;
let form : CreatePrivateMessage = {
content ,
recipient_id ,
auth : api.auth ,
} ;
return api . c lient. c reatePrivateMessage( form ) ;
return api . c reatePrivateMessage( form ) ;
}
export async function editPrivateMessage (
api : API ,
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 ,
auth : api.auth ,
} ;
return api . client. editPrivateMessage( form ) ;
return api . editPrivateMessage( form ) ;
}
export async function deletePrivateMessage (
api : API ,
api : LemmyHttp ,
deleted : boolean ,
private_message_id : number ,
) : Promise < PrivateMessageResponse > {
let form : DeletePrivateMessage = {
deleted ,
private_message_id ,
auth : api.auth ,
} ;
return api . client. deletePrivateMessage( form ) ;
return api . deletePrivateMessage( form ) ;
}
export async function registerUser (
api : API ,
api : LemmyHttp ,
username : string = randomString ( 5 ) ,
) : Promise < LoginResponse > {
let form : Register = {
@ -656,10 +596,12 @@ export async function registerUser(
password_verify : password ,
show_nsfw : true ,
} ;
return api . client. register( form ) ;
return api . register( form ) ;
}
export async function saveUserSettingsBio ( api : API ) : Promise < LoginResponse > {
export async function saveUserSettingsBio (
api : LemmyHttp ,
) : Promise < LoginResponse > {
let form : SaveUserSettings = {
show_nsfw : true ,
blur_nsfw : false ,
@ -671,13 +613,12 @@ export async function saveUserSettingsBio(api: API): Promise<LoginResponse> {
show_avatars : true ,
send_notifications_to_email : false ,
bio : "a changed bio" ,
auth : api.auth ,
} ;
return saveUserSettings ( api , form ) ;
}
export async function saveUserSettingsFederated (
api : API ,
api : LemmyHttp ,
) : Promise < LoginResponse > {
let avatar = "https://image.flaticon.com/icons/png/512/35/35896.png" ;
let banner = "https://image.flaticon.com/icons/png/512/36/35896.png" ;
@ -695,55 +636,52 @@ export async function saveUserSettingsFederated(
show_avatars : false ,
send_notifications_to_email : false ,
bio ,
auth : api.auth ,
} ;
return await saveUserSettings ( a lpha , form ) ;
return await saveUserSettings ( a pi , form ) ;
}
export async function saveUserSettings (
api : API ,
api : LemmyHttp ,
form : SaveUserSettings ,
) : Promise < LoginResponse > {
return api . client. saveUserSettings( form ) ;
return api . saveUserSettings( form ) ;
}
export async function getPersonDetails (
api : API ,
api : LemmyHttp ,
person_id : number ,
) : Promise < GetPersonDetailsResponse > {
let form : GetPersonDetails = {
auth : api.auth ,
person_id : person_id ,
} ;
return api . client. getPersonDetails( form ) ;
return api . getPersonDetails( form ) ;
}
export async function deleteUser ( api : API ) : Promise < DeleteAccountResponse > {
export async function deleteUser (
api : LemmyHttp ,
) : Promise < DeleteAccountResponse > {
let form : DeleteAccount = {
auth : api.auth ,
delete_content : true ,
password ,
} ;
return api . client. deleteAccount( form ) ;
return api . deleteAccount( form ) ;
}
export async function getSite ( api : API ) : Promise < GetSiteResponse > {
let form : GetSite = {
auth : api.auth ,
} ;
return api . client . getSite ( form ) ;
export async function getSite ( api : LemmyHttp ) : Promise < GetSiteResponse > {
return api . getSite ( ) ;
}
export async function listPrivateMessages (
api : API ,
api : LemmyHttp ,
) : Promise < PrivateMessagesResponse > {
let form : GetPrivateMessages = {
auth : api.auth ,
unread_only : false ,
} ;
return api . client. getPrivateMessages( form ) ;
return api . getPrivateMessages( form ) ;
}
export async function unfollowRemotes ( api : API ) : Promise < GetSiteResponse > {
export async function unfollowRemotes (
api : LemmyHttp ,
) : Promise < GetSiteResponse > {
// Unfollow all remote communities
let site = await getSite ( api ) ;
let remoteFollowed =
@ -755,7 +693,7 @@ export async function unfollowRemotes(api: API): Promise<GetSiteResponse> {
return siteRes ;
}
export async function followBeta ( api : API ) : Promise < CommunityResponse > {
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 ) ;
@ -766,71 +704,63 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
}
export async function reportPost (
api : API ,
api : LemmyHttp ,
post_id : number ,
reason : string ,
) : Promise < PostReportResponse > {
let form : CreatePostReport = {
post_id ,
reason ,
auth : api.auth ,
} ;
return api . c lient. c reatePostReport( form ) ;
return api . c reatePostReport( form ) ;
}
export async function listPostReports (
api : API ,
api : LemmyHttp ,
) : Promise < ListPostReportsResponse > {
let form : ListPostReports = {
auth : api.auth ,
} ;
return api . client . listPostReports ( form ) ;
let form : ListPostReports = { } ;
return api . listPostReports ( form ) ;
}
export async function reportComment (
api : API ,
api : LemmyHttp ,
comment_id : number ,
reason : string ,
) : Promise < CommentReportResponse > {
let form : CreateCommentReport = {
comment_id ,
reason ,
auth : api.auth ,
} ;
return api . c lient. c reateCommentReport( form ) ;
return api . c reateCommentReport( form ) ;
}
export async function listCommentReports (
api : API ,
api : LemmyHttp ,
) : Promise < ListCommentReportsResponse > {
let form : ListCommentReports = {
auth : api.auth ,
} ;
return api . client . listCommentReports ( form ) ;
let form : ListCommentReports = { } ;
return api . listCommentReports ( form ) ;
}
export function getPosts (
api : API ,
api : LemmyHttp ,
listingType? : ListingType ,
) : Promise < GetPostsResponse > {
let form : GetPosts = {
auth : api.auth ,
type_ : listingType ,
} ;
return api . client. getPosts( form ) ;
return api . getPosts( form ) ;
}
export function blockInstance (
api : API ,
api : LemmyHttp ,
instance_id : InstanceId ,
block : boolean ,
) : Promise < BlockInstanceResponse > {
let form : BlockInstance = {
instance_id ,
block ,
auth : api.auth ,
} ;
return api . client. blockInstance( form ) ;
return api . blockInstance( form ) ;
}
export function delay ( millis = 500 ) {