@ -1,4 +1,3 @@
import { None , Some , Option } from "@sniptt/monads" ;
import {
import {
Login ,
Login ,
LoginResponse ,
LoginResponse ,
@ -69,65 +68,65 @@ import {
export interface API {
export interface API {
client : LemmyHttp ;
client : LemmyHttp ;
auth : Option< string> ;
auth : string;
}
}
export let alpha : API = {
export let alpha : API = {
client : new LemmyHttp ( "http://127.0.0.1:8541" ) ,
client : new LemmyHttp ( "http://127.0.0.1:8541" ) ,
auth : None ,
auth : "" ,
} ;
} ;
export let beta : API = {
export let beta : API = {
client : new LemmyHttp ( "http://127.0.0.1:8551" ) ,
client : new LemmyHttp ( "http://127.0.0.1:8551" ) ,
auth : None ,
auth : "" ,
} ;
} ;
export let gamma : API = {
export let gamma : API = {
client : new LemmyHttp ( "http://127.0.0.1:8561" ) ,
client : new LemmyHttp ( "http://127.0.0.1:8561" ) ,
auth : None ,
auth : "" ,
} ;
} ;
export let delta : API = {
export let delta : API = {
client : new LemmyHttp ( "http://127.0.0.1:8571" ) ,
client : new LemmyHttp ( "http://127.0.0.1:8571" ) ,
auth : None ,
auth : "" ,
} ;
} ;
export let epsilon : API = {
export let epsilon : API = {
client : new LemmyHttp ( "http://127.0.0.1:8581" ) ,
client : new LemmyHttp ( "http://127.0.0.1:8581" ) ,
auth : None ,
auth : "" ,
} ;
} ;
const password = "lemmylemmy" ;
const password = "lemmylemmy" ;
export async function setupLogins() {
export async function setupLogins() {
let formAlpha = new Login ( {
let formAlpha : Login = {
username_or_email : "lemmy_alpha" ,
username_or_email : "lemmy_alpha" ,
password ,
password ,
} ) ;
} ;
let resAlpha = alpha . client . login ( formAlpha ) ;
let resAlpha = alpha . client . login ( formAlpha ) ;
let formBeta = new Login ( {
let formBeta : Login = {
username_or_email : "lemmy_beta" ,
username_or_email : "lemmy_beta" ,
password ,
password ,
} ) ;
} ;
let resBeta = beta . client . login ( formBeta ) ;
let resBeta = beta . client . login ( formBeta ) ;
let formGamma = new Login ( {
let formGamma : Login = {
username_or_email : "lemmy_gamma" ,
username_or_email : "lemmy_gamma" ,
password ,
password ,
} ) ;
} ;
let resGamma = gamma . client . login ( formGamma ) ;
let resGamma = gamma . client . login ( formGamma ) ;
let formDelta = new Login ( {
let formDelta : Login = {
username_or_email : "lemmy_delta" ,
username_or_email : "lemmy_delta" ,
password ,
password ,
} ) ;
} ;
let resDelta = delta . client . login ( formDelta ) ;
let resDelta = delta . client . login ( formDelta ) ;
let formEpsilon = new Login ( {
let formEpsilon : Login = {
username_or_email : "lemmy_epsilon" ,
username_or_email : "lemmy_epsilon" ,
password ,
password ,
} ) ;
} ;
let resEpsilon = epsilon . client . login ( formEpsilon ) ;
let resEpsilon = epsilon . client . login ( formEpsilon ) ;
let res = await Promise . all ( [
let res = await Promise . all ( [
@ -138,93 +137,60 @@ export async function setupLogins() {
resEpsilon ,
resEpsilon ,
] ) ;
] ) ;
alpha . auth = res [ 0 ] . jwt ;
alpha . auth = res [ 0 ] . jwt ? ? "" ;
beta . auth = res [ 1 ] . jwt ;
beta . auth = res [ 1 ] . jwt ? ? "" ;
gamma . auth = res [ 2 ] . jwt ;
gamma . auth = res [ 2 ] . jwt ? ? "" ;
delta . auth = res [ 3 ] . jwt ;
delta . auth = res [ 3 ] . jwt ? ? "" ;
epsilon . auth = res [ 4 ] . jwt ;
epsilon . auth = res [ 4 ] . jwt ? ? "" ;
// Registration applications are now enabled by default, need to disable them
// Registration applications are now enabled by default, need to disable them
let editSiteForm = new EditSite ( {
let editSiteForm : EditSite = {
require_application : Some ( false ) ,
require_application : false ,
federation_debug : Some ( true ) ,
federation_debug : true ,
name : None ,
rate_limit_message : 999 ,
sidebar : None ,
rate_limit_post : 999 ,
description : None ,
rate_limit_register : 999 ,
icon : None ,
rate_limit_image : 999 ,
banner : None ,
rate_limit_comment : 999 ,
enable_downvotes : None ,
rate_limit_search : 999 ,
open_registration : None ,
enable_nsfw : None ,
community_creation_admin_only : None ,
require_email_verification : None ,
application_question : None ,
private_instance : None ,
default_theme : None ,
default_post_listing_type : None ,
legal_information : None ,
application_email_admins : None ,
hide_modlog_mod_names : None ,
discussion_languages : None ,
slur_filter_regex : None ,
actor_name_max_length : None ,
rate_limit_message : Some ( 999 ) ,
rate_limit_message_per_second : None ,
rate_limit_post : Some ( 999 ) ,
rate_limit_post_per_second : None ,
rate_limit_register : Some ( 999 ) ,
rate_limit_register_per_second : None ,
rate_limit_image : Some ( 999 ) ,
rate_limit_image_per_second : None ,
rate_limit_comment : Some ( 999 ) ,
rate_limit_comment_per_second : None ,
rate_limit_search : Some ( 999 ) ,
rate_limit_search_per_second : None ,
federation_enabled : None ,
federation_worker_count : None ,
captcha_enabled : None ,
captcha_difficulty : None ,
allowed_instances : None ,
blocked_instances : None ,
auth : "" ,
auth : "" ,
taglines : None ,
} ;
} ) ;
// Set the blocks and auths for each
// Set the blocks and auths for each
editSiteForm . auth = alpha . auth .unwrap ( ) ;
editSiteForm . auth = alpha . auth ;
editSiteForm . allowed_instances = Some ( [
editSiteForm . allowed_instances = [
"lemmy-beta" ,
"lemmy-beta" ,
"lemmy-gamma" ,
"lemmy-gamma" ,
"lemmy-delta" ,
"lemmy-delta" ,
"lemmy-epsilon" ,
"lemmy-epsilon" ,
] ) ;
] ;
await alpha . client . editSite ( editSiteForm ) ;
await alpha . client . editSite ( editSiteForm ) ;
editSiteForm . auth = beta . auth .unwrap ( ) ;
editSiteForm . auth = beta . auth ;
editSiteForm . allowed_instances = Some ( [
editSiteForm . allowed_instances = [
"lemmy-alpha" ,
"lemmy-alpha" ,
"lemmy-gamma" ,
"lemmy-gamma" ,
"lemmy-delta" ,
"lemmy-delta" ,
"lemmy-epsilon" ,
"lemmy-epsilon" ,
] ) ;
] ;
await beta . client . editSite ( editSiteForm ) ;
await beta . client . editSite ( editSiteForm ) ;
editSiteForm . auth = gamma . auth .unwrap ( ) ;
editSiteForm . auth = gamma . auth ;
editSiteForm . allowed_instances = Some ( [
editSiteForm . allowed_instances = [
"lemmy-alpha" ,
"lemmy-alpha" ,
"lemmy-beta" ,
"lemmy-beta" ,
"lemmy-delta" ,
"lemmy-delta" ,
"lemmy-epsilon" ,
"lemmy-epsilon" ,
] ) ;
] ;
await gamma . client . editSite ( editSiteForm ) ;
await gamma . client . editSite ( editSiteForm ) ;
editSiteForm . allowed_instances = Some ( [ "lemmy-beta" ] ) ;
editSiteForm . allowed_instances = [ "lemmy-beta" ] ;
editSiteForm . auth = delta . auth .unwrap ( ) ;
editSiteForm . auth = delta . auth ;
await delta . client . editSite ( editSiteForm ) ;
await delta . client . editSite ( editSiteForm ) ;
editSiteForm . auth = epsilon . auth .unwrap ( ) ;
editSiteForm . auth = epsilon . auth ;
editSiteForm . allowed_instances = Some ( [ ] ) ;
editSiteForm . allowed_instances = [ ] ;
editSiteForm . blocked_instances = Some ( [ "lemmy-alpha" ] ) ;
editSiteForm . blocked_instances = [ "lemmy-alpha" ] ;
await epsilon . client . editSite ( editSiteForm ) ;
await epsilon . client . editSite ( editSiteForm ) ;
// Create the main alpha/beta communities
// Create the main alpha/beta communities
@ -237,32 +203,25 @@ export async function createPost(
community_id : number
community_id : number
) : Promise < PostResponse > {
) : Promise < PostResponse > {
let name = randomString ( 5 ) ;
let name = randomString ( 5 ) ;
let body = Some( randomString( 10 ) ) ;
let body = randomString( 10 ) ;
let url = Some ( "https://google.com/" ) ;
let url = "https://google.com/" ;
let form = new CreatePost ( {
let form : CreatePost = {
name ,
name ,
url ,
url ,
body ,
body ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
community_id ,
community_id ,
nsfw : None ,
} ;
honeypot : None ,
language_id : None ,
} ) ;
return api . client . createPost ( form ) ;
return api . client . createPost ( form ) ;
}
}
export async function editPost ( api : API , post : Post ) : Promise < PostResponse > {
export async function editPost ( api : API , post : Post ) : Promise < PostResponse > {
let name = Some ( "A jest test federated post, updated" ) ;
let name = "A jest test federated post, updated" ;
let form = new EditPost ( {
let form : EditPost = {
name ,
name ,
post_id : post.id ,
post_id : post.id ,
auth : api.auth.unwrap ( ) ,
auth : api.auth ,
nsfw : None ,
} ;
url : None ,
body : None ,
language_id : None ,
} ) ;
return api . client . editPost ( form ) ;
return api . client . editPost ( form ) ;
}
}
@ -271,11 +230,11 @@ export async function deletePost(
deleted : boolean ,
deleted : boolean ,
post : Post
post : Post
) : Promise < PostResponse > {
) : Promise < PostResponse > {
let form = new DeletePost ( {
let form : DeletePost = {
post_id : post.id ,
post_id : post.id ,
deleted : deleted ,
deleted : deleted ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
} ) ;
} ;
return api . client . deletePost ( form ) ;
return api . client . deletePost ( form ) ;
}
}
@ -284,12 +243,11 @@ export async function removePost(
removed : boolean ,
removed : boolean ,
post : Post
post : Post
) : Promise < PostResponse > {
) : Promise < PostResponse > {
let form = new RemovePost ( {
let form : RemovePost = {
post_id : post.id ,
post_id : post.id ,
removed ,
removed ,
auth : api.auth.unwrap ( ) ,
auth : api.auth ,
reason : None ,
} ;
} ) ;
return api . client . removePost ( form ) ;
return api . client . removePost ( form ) ;
}
}
@ -298,12 +256,12 @@ export async function featurePost(
featured : boolean ,
featured : boolean ,
post : Post
post : Post
) : Promise < PostResponse > {
) : Promise < PostResponse > {
let form = new FeaturePost ( {
let form : FeaturePost = {
post_id : post.id ,
post_id : post.id ,
featured ,
featured ,
feature_type : PostFeatureType.Community ,
feature_type : PostFeatureType.Community ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
} ) ;
} ;
return api . client . featurePost ( form ) ;
return api . client . featurePost ( form ) ;
}
}
@ -312,11 +270,11 @@ export async function lockPost(
locked : boolean ,
locked : boolean ,
post : Post
post : Post
) : Promise < PostResponse > {
) : Promise < PostResponse > {
let form = new LockPost ( {
let form : LockPost = {
post_id : post.id ,
post_id : post.id ,
locked ,
locked ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
} ) ;
} ;
return api . client . lockPost ( form ) ;
return api . client . lockPost ( form ) ;
}
}
@ -324,10 +282,10 @@ export async function resolvePost(
api : API ,
api : API ,
post : Post
post : Post
) : Promise < ResolveObjectResponse > {
) : Promise < ResolveObjectResponse > {
let form = new ResolveObject ( {
let form : ResolveObject = {
q : post.ap_id ,
q : post.ap_id ,
auth : api.auth ,
auth : api.auth ,
} ) ;
} ;
return api . client . resolveObject ( form ) ;
return api . client . resolveObject ( form ) ;
}
}
@ -335,18 +293,12 @@ export async function searchPostLocal(
api : API ,
api : API ,
post : Post
post : Post
) : Promise < SearchResponse > {
) : Promise < SearchResponse > {
let form = new Search ( {
let form : Search = {
q : post.name ,
q : post.name ,
type_ : Some ( SearchType . Posts ) ,
type_ : SearchType.Posts ,
sort : Some ( SortType . TopAll ) ,
sort : SortType.TopAll ,
community_id : None ,
auth : api.auth ,
community_name : None ,
} ;
creator_id : None ,
listing_type : None ,
page : None ,
limit : None ,
auth : api.auth ,
} ) ;
return api . client . search ( form ) ;
return api . client . search ( form ) ;
}
}
@ -354,11 +306,10 @@ export async function getPost(
api : API ,
api : API ,
post_id : number
post_id : number
) : Promise < GetPostResponse > {
) : Promise < GetPostResponse > {
let form = new GetPost ( {
let form : GetPost = {
id : Some ( post_id ) ,
id : post_id ,
comment_id : None ,
auth : api.auth ,
auth : api.auth ,
} ) ;
} ;
return api . client . getPost ( form ) ;
return api . client . getPost ( form ) ;
}
}
@ -366,19 +317,12 @@ export async function getComments(
api : API ,
api : API ,
post_id : number
post_id : number
) : Promise < GetCommentsResponse > {
) : Promise < GetCommentsResponse > {
let form = new GetComments ( {
let form : GetComments = {
post_id : Some ( post_id ) ,
post_id : post_id ,
type_ : Some ( ListingType . All ) ,
type_ : ListingType.All ,
sort : Some ( CommentSortType . New ) , // TODO this sort might be wrong
sort : CommentSortType.New ,
max_depth : None ,
auth : api.auth ,
page : None ,
} ;
limit : None ,
community_id : None ,
community_name : None ,
saved_only : None ,
parent_id : None ,
auth : api.auth ,
} ) ;
return api . client . getComments ( form ) ;
return api . client . getComments ( form ) ;
}
}
@ -386,10 +330,10 @@ export async function resolveComment(
api : API ,
api : API ,
comment : Comment
comment : Comment
) : Promise < ResolveObjectResponse > {
) : Promise < ResolveObjectResponse > {
let form = new ResolveObject ( {
let form : ResolveObject = {
q : comment.ap_id ,
q : comment.ap_id ,
auth : api.auth ,
auth : api.auth ,
} ) ;
} ;
return api . client . resolveObject ( form ) ;
return api . client . resolveObject ( form ) ;
}
}
@ -397,10 +341,10 @@ export async function resolveBetaCommunity(
api : API
api : API
) : Promise < ResolveObjectResponse > {
) : Promise < ResolveObjectResponse > {
// Use short-hand search url
// Use short-hand search url
let form = new ResolveObject ( {
let form : ResolveObject = {
q : "!main@lemmy-beta:8551" ,
q : "!main@lemmy-beta:8551" ,
auth : api.auth ,
auth : api.auth ,
} ) ;
} ;
return api . client . resolveObject ( form ) ;
return api . client . resolveObject ( form ) ;
}
}
@ -408,10 +352,10 @@ export async function resolveCommunity(
api : API ,
api : API ,
q : string
q : string
) : Promise < ResolveObjectResponse > {
) : Promise < ResolveObjectResponse > {
let form = new ResolveObject ( {
let form : ResolveObject = {
q ,
q ,
auth : api.auth ,
auth : api.auth ,
} ) ;
} ;
return api . client . resolveObject ( form ) ;
return api . client . resolveObject ( form ) ;
}
}
@ -419,10 +363,10 @@ export async function resolvePerson(
api : API ,
api : API ,
apShortname : string
apShortname : string
) : Promise < ResolveObjectResponse > {
) : Promise < ResolveObjectResponse > {
let form = new ResolveObject ( {
let form : ResolveObject = {
q : apShortname ,
q : apShortname ,
auth : api.auth ,
auth : api.auth ,
} ) ;
} ;
return api . client . resolveObject ( form ) ;
return api . client . resolveObject ( form ) ;
}
}
@ -433,14 +377,12 @@ export async function banPersonFromSite(
remove_data : boolean
remove_data : boolean
) : Promise < BanPersonResponse > {
) : Promise < BanPersonResponse > {
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
let form = new BanPerson ( {
let form : BanPerson = {
person_id ,
person_id ,
ban ,
ban ,
remove_data : Some ( remove_data ) ,
remove_data : remove_data ,
auth : api.auth.unwrap ( ) ,
auth : api.auth ,
reason : None ,
} ;
expires : None ,
} ) ;
return api . client . banPerson ( form ) ;
return api . client . banPerson ( form ) ;
}
}
@ -451,15 +393,13 @@ export async function banPersonFromCommunity(
remove_data : boolean ,
remove_data : boolean ,
ban : boolean
ban : boolean
) : Promise < BanFromCommunityResponse > {
) : Promise < BanFromCommunityResponse > {
let form = new BanFromCommunity ( {
let form : BanFromCommunity = {
person_id ,
person_id ,
community_id ,
community_id ,
remove_data : Some( remove_data) ,
remove_data : remove_data,
ban ,
ban ,
reason : None ,
auth : api.auth ,
expires : None ,
} ;
auth : api.auth.unwrap ( ) ,
} ) ;
return api . client . banFromCommunity ( form ) ;
return api . client . banFromCommunity ( form ) ;
}
}
@ -468,11 +408,11 @@ export async function followCommunity(
follow : boolean ,
follow : boolean ,
community_id : number
community_id : number
) : Promise < CommunityResponse > {
) : Promise < CommunityResponse > {
let form = new FollowCommunity ( {
let form : FollowCommunity = {
community_id ,
community_id ,
follow ,
follow ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
} ) ;
} ;
return api . client . followCommunity ( form ) ;
return api . client . followCommunity ( form ) ;
}
}
@ -481,11 +421,11 @@ export async function likePost(
score : number ,
score : number ,
post : Post
post : Post
) : Promise < PostResponse > {
) : Promise < PostResponse > {
let form = new CreatePostLike ( {
let form : CreatePostLike = {
post_id : post.id ,
post_id : post.id ,
score : score ,
score : score ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
} ) ;
} ;
return api . client . likePost ( form ) ;
return api . client . likePost ( form ) ;
}
}
@ -493,33 +433,28 @@ export async function likePost(
export async function createComment (
export async function createComment (
api : API ,
api : API ,
post_id : number ,
post_id : number ,
parent_id : Option< number> ,
parent_id ? : number,
content = "a jest test comment"
content = "a jest test comment"
) : Promise < CommentResponse > {
) : Promise < CommentResponse > {
let form = new CreateComment ( {
let form : CreateComment = {
content ,
content ,
post_id ,
post_id ,
parent_id ,
parent_id ,
form_id : None ,
auth : api.auth ,
language_id : None ,
} ;
auth : api.auth.unwrap ( ) ,
} ) ;
return api . client . createComment ( form ) ;
return api . client . createComment ( form ) ;
}
}
export async function editComment (
export async function editComment (
api : API ,
api : API ,
comment_id : number ,
comment_id : number ,
content = Some ( "A jest test federated comment update" )
content = "A jest test federated comment update"
) : Promise < CommentResponse > {
) : Promise < CommentResponse > {
let form = new EditComment ( {
let form : EditComment = {
content ,
content ,
comment_id ,
comment_id ,
form_id : None ,
auth : api.auth ,
language_id : None ,
} ;
distinguished : None ,
auth : api.auth.unwrap ( ) ,
} ) ;
return api . client . editComment ( form ) ;
return api . client . editComment ( form ) ;
}
}
@ -528,11 +463,11 @@ export async function deleteComment(
deleted : boolean ,
deleted : boolean ,
comment_id : number
comment_id : number
) : Promise < CommentResponse > {
) : Promise < CommentResponse > {
let form = new DeleteComment ( {
let form : DeleteComment = {
comment_id ,
comment_id ,
deleted ,
deleted ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
} ) ;
} ;
return api . client . deleteComment ( form ) ;
return api . client . deleteComment ( form ) ;
}
}
@ -541,25 +476,22 @@ export async function removeComment(
removed : boolean ,
removed : boolean ,
comment_id : number
comment_id : number
) : Promise < CommentResponse > {
) : Promise < CommentResponse > {
let form = new RemoveComment ( {
let form : RemoveComment = {
comment_id ,
comment_id ,
removed ,
removed ,
reason : None ,
auth : api.auth ,
auth : api.auth.unwrap ( ) ,
} ;
} ) ;
return api . client . removeComment ( form ) ;
return api . client . removeComment ( form ) ;
}
}
export async function getMentions (
export async function getMentions (
api : API
api : API
) : Promise < GetPersonMentionsResponse > {
) : Promise < GetPersonMentionsResponse > {
let form = new GetPersonMentions ( {
let form : GetPersonMentions = {
sort : Some ( CommentSortType . New ) ,
sort : CommentSortType.New ,
unread_only : Some ( false ) ,
unread_only : false ,
auth : api.auth.unwrap ( ) ,
auth : api.auth ,
page : None ,
} ;
limit : None ,
} ) ;
return api . client . getPersonMentions ( form ) ;
return api . client . getPersonMentions ( form ) ;
}
}
@ -568,11 +500,11 @@ export async function likeComment(
score : number ,
score : number ,
comment : Comment
comment : Comment
) : Promise < CommentResponse > {
) : Promise < CommentResponse > {
let form = new CreateCommentLike ( {
let form : CreateCommentLike = {
comment_id : comment.id ,
comment_id : comment.id ,
score ,
score ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
} ) ;
} ;
return api . client . likeComment ( form ) ;
return api . client . likeComment ( form ) ;
}
}
@ -580,17 +512,13 @@ export async function createCommunity(
api : API ,
api : API ,
name_ : string = randomString ( 5 )
name_ : string = randomString ( 5 )
) : Promise < CommunityResponse > {
) : Promise < CommunityResponse > {
let description = Some ( "a sample description" ) ;
let description = "a sample description" ;
let form = new CreateCommunity ( {
let form : CreateCommunity = {
name : name_ ,
name : name_ ,
title : name_ ,
title : name_ ,
description ,
description ,
nsfw : None ,
auth : api.auth ,
icon : None ,
} ;
banner : None ,
posting_restricted_to_mods : None ,
auth : api.auth.unwrap ( ) ,
} ) ;
return api . client . createCommunity ( form ) ;
return api . client . createCommunity ( form ) ;
}
}
@ -598,11 +526,10 @@ export async function getCommunity(
api : API ,
api : API ,
id : number
id : number
) : Promise < CommunityResponse > {
) : Promise < CommunityResponse > {
let form = new GetCommunity ( {
let form : GetCommunity = {
id : Some ( id ) ,
id ,
name : None ,
auth : api.auth ,
auth : api.auth ,
} ) ;
} ;
return api . client . getCommunity ( form ) ;
return api . client . getCommunity ( form ) ;
}
}
@ -611,11 +538,11 @@ export async function deleteCommunity(
deleted : boolean ,
deleted : boolean ,
community_id : number
community_id : number
) : Promise < CommunityResponse > {
) : Promise < CommunityResponse > {
let form = new DeleteCommunity ( {
let form : DeleteCommunity = {
community_id ,
community_id ,
deleted ,
deleted ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
} ) ;
} ;
return api . client . deleteCommunity ( form ) ;
return api . client . deleteCommunity ( form ) ;
}
}
@ -624,13 +551,11 @@ export async function removeCommunity(
removed : boolean ,
removed : boolean ,
community_id : number
community_id : number
) : Promise < CommunityResponse > {
) : Promise < CommunityResponse > {
let form = new RemoveCommunity ( {
let form : RemoveCommunity = {
community_id ,
community_id ,
removed ,
removed ,
reason : None ,
auth : api.auth ,
expires : None ,
} ;
auth : api.auth.unwrap ( ) ,
} ) ;
return api . client . removeCommunity ( form ) ;
return api . client . removeCommunity ( form ) ;
}
}
@ -639,11 +564,11 @@ export async function createPrivateMessage(
recipient_id : number
recipient_id : number
) : Promise < PrivateMessageResponse > {
) : Promise < PrivateMessageResponse > {
let content = "A jest test federated private message" ;
let content = "A jest test federated private message" ;
let form = new CreatePrivateMessage ( {
let form : CreatePrivateMessage = {
content ,
content ,
recipient_id ,
recipient_id ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
} ) ;
} ;
return api . client . createPrivateMessage ( form ) ;
return api . client . createPrivateMessage ( form ) ;
}
}
@ -652,11 +577,11 @@ export async function editPrivateMessage(
private_message_id : number
private_message_id : number
) : Promise < PrivateMessageResponse > {
) : Promise < PrivateMessageResponse > {
let updatedContent = "A jest test federated private message edited" ;
let updatedContent = "A jest test federated private message edited" ;
let form = new EditPrivateMessage ( {
let form : EditPrivateMessage = {
content : updatedContent ,
content : updatedContent ,
private_message_id ,
private_message_id ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
} ) ;
} ;
return api . client . editPrivateMessage ( form ) ;
return api . client . editPrivateMessage ( form ) ;
}
}
@ -665,11 +590,11 @@ export async function deletePrivateMessage(
deleted : boolean ,
deleted : boolean ,
private_message_id : number
private_message_id : number
) : Promise < PrivateMessageResponse > {
) : Promise < PrivateMessageResponse > {
let form = new DeletePrivateMessage ( {
let form : DeletePrivateMessage = {
deleted ,
deleted ,
private_message_id ,
private_message_id ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
} ) ;
} ;
return api . client . deletePrivateMessage ( form ) ;
return api . client . deletePrivateMessage ( form ) ;
}
}
@ -677,78 +602,49 @@ export async function registerUser(
api : API ,
api : API ,
username : string = randomString ( 5 )
username : string = randomString ( 5 )
) : Promise < LoginResponse > {
) : Promise < LoginResponse > {
let form = new Register ( {
let form : Register = {
username ,
username ,
password ,
password ,
password_verify : password ,
password_verify : password ,
show_nsfw : true ,
show_nsfw : true ,
email : None ,
} ;
captcha_uuid : None ,
captcha_answer : None ,
honeypot : None ,
answer : None ,
} ) ;
return api . client . register ( form ) ;
return api . client . register ( form ) ;
}
}
export async function saveUserSettingsBio ( api : API ) : Promise < LoginResponse > {
export async function saveUserSettingsBio ( api : API ) : Promise < LoginResponse > {
let form = new SaveUserSettings ( {
let form : SaveUserSettings = {
show_nsfw : Some ( true ) ,
show_nsfw : true ,
theme : Some ( "darkly" ) ,
theme : "darkly" ,
default_sort_type : Some ( Object . keys ( SortType ) . indexOf ( SortType . Active ) ) ,
default_sort_type : Object.keys ( SortType ) . indexOf ( SortType . Active ) ,
default_listing_type : Some (
default_listing_type : Object.keys ( ListingType ) . indexOf ( ListingType . All ) ,
Object . keys ( ListingType ) . indexOf ( ListingType . All )
interface_language : "en" ,
) ,
show_avatars : true ,
interface_language : Some ( "en" ) ,
send_notifications_to_email : false ,
show_avatars : Some ( true ) ,
bio : "a changed bio" ,
send_notifications_to_email : Some ( false ) ,
auth : api.auth ,
bio : Some ( "a changed bio" ) ,
} ;
avatar : None ,
banner : None ,
display_name : None ,
email : None ,
matrix_user_id : None ,
show_scores : None ,
show_read_posts : None ,
show_bot_accounts : None ,
show_new_post_notifs : None ,
bot_account : None ,
discussion_languages : None ,
auth : api.auth.unwrap ( ) ,
} ) ;
return saveUserSettings ( api , form ) ;
return saveUserSettings ( api , form ) ;
}
}
export async function saveUserSettingsFederated (
export async function saveUserSettingsFederated (
api : API
api : API
) : Promise < LoginResponse > {
) : Promise < LoginResponse > {
let avatar = Some ( "https://image.flaticon.com/icons/png/512/35/35896.png" ) ;
let avatar = "https://image.flaticon.com/icons/png/512/35/35896.png" ;
let banner = Some ( "https://image.flaticon.com/icons/png/512/36/35896.png" ) ;
let banner = "https://image.flaticon.com/icons/png/512/36/35896.png" ;
let bio = Some ( "a changed bio" ) ;
let bio = "a changed bio" ;
let form = new SaveUserSettings ( {
let form : SaveUserSettings = {
show_nsfw : Some ( false ) ,
show_nsfw : false ,
theme : Some ( "" ) ,
default_sort_type : Object.keys ( SortType ) . indexOf ( SortType . Hot ) ,
default_sort_type : Some ( Object . keys ( SortType ) . indexOf ( SortType . Hot ) ) ,
default_listing_type : Object.keys ( ListingType ) . indexOf ( ListingType . All ) ,
default_listing_type : Some (
interface_language : "" ,
Object . keys ( ListingType ) . indexOf ( ListingType . All )
) ,
interface_language : Some ( "" ) ,
avatar ,
avatar ,
banner ,
banner ,
display_name : Some ( "user321" ) ,
display_name : "user321" ,
show_avatars : Some( false) ,
show_avatars : false,
send_notifications_to_email : Some( false) ,
send_notifications_to_email : false,
bio ,
bio ,
email : None ,
auth : api.auth ,
show_scores : None ,
} ;
show_read_posts : None ,
matrix_user_id : None ,
bot_account : None ,
show_bot_accounts : None ,
show_new_post_notifs : None ,
discussion_languages : None ,
auth : api.auth.unwrap ( ) ,
} ) ;
return await saveUserSettings ( alpha , form ) ;
return await saveUserSettings ( alpha , form ) ;
}
}
@ -760,38 +656,35 @@ export async function saveUserSettings(
}
}
export async function deleteUser ( api : API ) : Promise < DeleteAccountResponse > {
export async function deleteUser ( api : API ) : Promise < DeleteAccountResponse > {
let form = new DeleteAccount ( {
let form : DeleteAccount = {
auth : api.auth .unwrap( ) ,
auth : api.auth ,
password ,
password ,
} ) ;
} ;
return api . client . deleteAccount ( form ) ;
return api . client . deleteAccount ( form ) ;
}
}
export async function getSite ( api : API ) : Promise < GetSiteResponse > {
export async function getSite ( api : API ) : Promise < GetSiteResponse > {
let form = new GetSite ( {
let form : GetSite = {
auth : api.auth ,
auth : api.auth ,
} ) ;
} ;
return api . client . getSite ( form ) ;
return api . client . getSite ( form ) ;
}
}
export async function listPrivateMessages (
export async function listPrivateMessages (
api : API
api : API
) : Promise < PrivateMessagesResponse > {
) : Promise < PrivateMessagesResponse > {
let form = new GetPrivateMessages ( {
let form : GetPrivateMessages = {
auth : api.auth.unwrap ( ) ,
auth : api.auth ,
unread_only : Some ( false ) ,
unread_only : false ,
page : None ,
} ;
limit : None ,
} ) ;
return api . client . getPrivateMessages ( form ) ;
return api . client . getPrivateMessages ( form ) ;
}
}
export async function unfollowRemotes ( api : API ) : Promise < GetSiteResponse > {
export async function unfollowRemotes ( api : API ) : Promise < GetSiteResponse > {
// Unfollow all remote communities
// Unfollow all remote communities
let site = await getSite ( api ) ;
let site = await getSite ( api ) ;
let remoteFollowed = site . my_user
let remoteFollowed =
. unwrap ( )
site . my_user ? . follows . filter ( c = > c . community . local == false ) ? ? [ ] ;
. follows . filter ( c = > c . community . local == false ) ;
for ( let cu of remoteFollowed ) {
for ( let cu of remoteFollowed ) {
await followCommunity ( api , false , cu . community . id ) ;
await followCommunity ( api , false , cu . community . id ) ;
}
}
@ -801,12 +694,8 @@ export async function unfollowRemotes(api: API): Promise<GetSiteResponse> {
export async function followBeta ( api : API ) : Promise < CommunityResponse > {
export async function followBeta ( api : API ) : Promise < CommunityResponse > {
let betaCommunity = ( await resolveBetaCommunity ( api ) ) . community ;
let betaCommunity = ( await resolveBetaCommunity ( api ) ) . community ;
if ( betaCommunity . isSome ( ) ) {
if ( betaCommunity ) {
let follow = await followCommunity (
let follow = await followCommunity ( api , true , betaCommunity . community . id ) ;
api ,
true ,
betaCommunity . unwrap ( ) . community . id
) ;
return follow ;
return follow ;
} else {
} else {
return Promise . reject ( "no community worked" ) ;
return Promise . reject ( "no community worked" ) ;
@ -818,24 +707,20 @@ export async function reportPost(
post_id : number ,
post_id : number ,
reason : string
reason : string
) : Promise < PostReportResponse > {
) : Promise < PostReportResponse > {
let form = new CreatePostReport ( {
let form : CreatePostReport = {
post_id ,
post_id ,
reason ,
reason ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
} ) ;
} ;
return api . client . createPostReport ( form ) ;
return api . client . createPostReport ( form ) ;
}
}
export async function listPostReports (
export async function listPostReports (
api : API
api : API
) : Promise < ListPostReportsResponse > {
) : Promise < ListPostReportsResponse > {
let form = new ListPostReports ( {
let form : ListPostReports = {
auth : api.auth.unwrap ( ) ,
auth : api.auth ,
page : None ,
} ;
limit : None ,
community_id : None ,
unresolved_only : None ,
} ) ;
return api . client . listPostReports ( form ) ;
return api . client . listPostReports ( form ) ;
}
}
@ -844,24 +729,20 @@ export async function reportComment(
comment_id : number ,
comment_id : number ,
reason : string
reason : string
) : Promise < CommentReportResponse > {
) : Promise < CommentReportResponse > {
let form = new CreateCommentReport ( {
let form : CreateCommentReport = {
comment_id ,
comment_id ,
reason ,
reason ,
auth : api.auth .unwrap( ) ,
auth : api.auth ,
} ) ;
} ;
return api . client . createCommentReport ( form ) ;
return api . client . createCommentReport ( form ) ;
}
}
export async function listCommentReports (
export async function listCommentReports (
api : API
api : API
) : Promise < ListCommentReportsResponse > {
) : Promise < ListCommentReportsResponse > {
let form = new ListCommentReports ( {
let form : ListCommentReports = {
page : None ,
auth : api.auth ,
limit : None ,
} ;
community_id : None ,
unresolved_only : None ,
auth : api.auth.unwrap ( ) ,
} ) ;
return api . client . listCommentReports ( form ) ;
return api . client . listCommentReports ( form ) ;
}
}
@ -895,14 +776,14 @@ export async function unfollows() {
await unfollowRemotes ( epsilon ) ;
await unfollowRemotes ( epsilon ) ;
}
}
export function getCommentParentId ( comment : Comment ) : Option < number > {
export function getCommentParentId ( comment : Comment ) : number | undefined {
let split = comment . path . split ( "." ) ;
let split = comment . path . split ( "." ) ;
// remove the 0
// remove the 0
split . shift ( ) ;
split . shift ( ) ;
if ( split . length > 1 ) {
if ( split . length > 1 ) {
return Some ( Number ( split [ split . length - 2 ] ) ) ;
return Number ( split [ split . length - 2 ] ) ;
} else {
} else {
return None ;
return undefined ;
}
}
}
}