]> Untitled Git - lemmy.git/blobdiff - api_tests/src/shared.ts
Adding diesel enums for SortType and ListingType (#2808)
[lemmy.git] / api_tests / src / shared.ts
index 9bf232065e0a71988e71d08d0d9c9a6505b24235..b8e97db0d37215979e29c3c33271674bd433bc33 100644 (file)
@@ -1,4 +1,3 @@
-import { None, Some, Option } from "@sniptt/monads";
 import {
   Login,
   LoginResponse,
@@ -7,7 +6,6 @@ import {
   CreateComment,
   DeletePost,
   RemovePost,
-  StickyPost,
   LockPost,
   PostResponse,
   SearchResponse,
@@ -64,69 +62,72 @@ import {
   CommentSortType,
   GetComments,
   GetCommentsResponse,
+  FeaturePost,
+  PostFeatureType,
+  RegistrationMode,
 } from "lemmy-js-client";
 
 export interface API {
   client: LemmyHttp;
-  auth: Option<string>;
+  auth: string;
 }
 
 export let alpha: API = {
   client: new LemmyHttp("http://127.0.0.1:8541"),
-  auth: None,
+  auth: "",
 };
 
 export let beta: API = {
   client: new LemmyHttp("http://127.0.0.1:8551"),
-  auth: None,
+  auth: "",
 };
 
 export let gamma: API = {
   client: new LemmyHttp("http://127.0.0.1:8561"),
-  auth: None,
+  auth: "",
 };
 
 export let delta: API = {
   client: new LemmyHttp("http://127.0.0.1:8571"),
-  auth: None,
+  auth: "",
 };
 
 export let epsilon: API = {
   client: new LemmyHttp("http://127.0.0.1:8581"),
-  auth: None,
+  auth: "",
 };
 
 const password = "lemmylemmy";
 
 export async function setupLogins() {
-  let formAlpha = new Login({
+  let formAlpha: Login = {
     username_or_email: "lemmy_alpha",
     password,
-  });
+  };
   let resAlpha = alpha.client.login(formAlpha);
 
-  let formBeta = new Login({
+  let formBeta: Login = {
     username_or_email: "lemmy_beta",
     password,
-  });
+  };
   let resBeta = beta.client.login(formBeta);
 
-  let formGamma = new Login({
+  let formGamma: Login = {
     username_or_email: "lemmy_gamma",
     password,
-  });
+  };
   let resGamma = gamma.client.login(formGamma);
 
-  let formDelta = new Login({
+  let formDelta: Login = {
     username_or_email: "lemmy_delta",
     password,
-  });
+  };
   let resDelta = delta.client.login(formDelta);
 
-  let formEpsilon = new Login({
+  let formEpsilon: Login = {
     username_or_email: "lemmy_epsilon",
     password,
-  });
+  };
   let resEpsilon = epsilon.client.login(formEpsilon);
 
   let res = await Promise.all([
@@ -137,94 +138,59 @@ export async function setupLogins() {
     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.auth = res[0].jwt ?? "";
+  beta.auth = res[1].jwt ?? "";
+  gamma.auth = res[2].jwt ?? "";
+  delta.auth = res[3].jwt ?? "";
+  epsilon.auth = res[4].jwt ?? "";
 
   // Registration applications are now enabled by default, need to disable them
-  let editSiteForm = new EditSite({
-    require_application: Some(false),
-    federation_debug: Some(true),
-    name: None,
-    sidebar: None,
-    description: None,
-    icon: None,
-    banner: None,
-    enable_downvotes: None,
-    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_strict_allowlist: None,
-    federation_http_fetch_retry_limit: None,
-    federation_worker_count: None,
-    captcha_enabled: None,
-    captcha_difficulty: None,
-    allowed_instances: None,
-    blocked_instances: None,
+  let editSiteForm: EditSite = {
+    registration_mode: RegistrationMode.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,
     auth: "",
-  });
+  };
 
   // Set the blocks and auths for each
-  editSiteForm.auth = alpha.auth.unwrap();
-  editSiteForm.allowed_instances = Some([
+  editSiteForm.auth = alpha.auth;
+  editSiteForm.allowed_instances = [
     "lemmy-beta",
     "lemmy-gamma",
     "lemmy-delta",
     "lemmy-epsilon",
-  ]);
+  ];
   await alpha.client.editSite(editSiteForm);
 
-  editSiteForm.auth = beta.auth.unwrap();
-  editSiteForm.allowed_instances = Some([
+  editSiteForm.auth = beta.auth;
+  editSiteForm.allowed_instances = [
     "lemmy-alpha",
     "lemmy-gamma",
     "lemmy-delta",
     "lemmy-epsilon",
-  ]);
+  ];
   await beta.client.editSite(editSiteForm);
 
-  editSiteForm.auth = gamma.auth.unwrap();
-  editSiteForm.allowed_instances = Some([
+  editSiteForm.auth = gamma.auth;
+  editSiteForm.allowed_instances = [
     "lemmy-alpha",
     "lemmy-beta",
     "lemmy-delta",
     "lemmy-epsilon",
-  ]);
+  ];
   await gamma.client.editSite(editSiteForm);
 
-  editSiteForm.allowed_instances = Some(["lemmy-beta"]);
-  editSiteForm.auth = delta.auth.unwrap();
+  editSiteForm.allowed_instances = ["lemmy-beta"];
+  editSiteForm.auth = delta.auth;
   await delta.client.editSite(editSiteForm);
 
-  editSiteForm.auth = epsilon.auth.unwrap();
-  editSiteForm.allowed_instances = Some([]);
-  editSiteForm.blocked_instances = Some(["lemmy-alpha"]);
+  editSiteForm.auth = epsilon.auth;
+  editSiteForm.allowed_instances = [];
+  editSiteForm.blocked_instances = ["lemmy-alpha"];
   await epsilon.client.editSite(editSiteForm);
 
   // Create the main alpha/beta communities
@@ -237,32 +203,25 @@ export async function createPost(
   community_id: number
 ): Promise<PostResponse> {
   let name = randomString(5);
-  let body = Some(randomString(10));
-  let url = Some("https://google.com/");
-  let form = new CreatePost({
+  let body = randomString(10);
+  let url = "https://google.com/";
+  let form: CreatePost = {
     name,
     url,
     body,
-    auth: api.auth.unwrap(),
+    auth: api.auth,
     community_id,
-    nsfw: None,
-    honeypot: None,
-    language_id: None,
-  });
+  };
   return api.client.createPost(form);
 }
 
 export async function editPost(api: API, post: Post): Promise<PostResponse> {
-  let name = Some("A jest test federated post, updated");
-  let form = new EditPost({
+  let name = "A jest test federated post, updated";
+  let form: EditPost = {
     name,
     post_id: post.id,
-    auth: api.auth.unwrap(),
-    nsfw: None,
-    url: None,
-    body: None,
-    language_id: None,
-  });
+    auth: api.auth,
+  };
   return api.client.editPost(form);
 }
 
@@ -271,11 +230,11 @@ export async function deletePost(
   deleted: boolean,
   post: Post
 ): Promise<PostResponse> {
-  let form = new DeletePost({
+  let form: DeletePost = {
     post_id: post.id,
     deleted: deleted,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.deletePost(form);
 }
 
@@ -284,26 +243,26 @@ export async function removePost(
   removed: boolean,
   post: Post
 ): Promise<PostResponse> {
-  let form = new RemovePost({
+  let form: RemovePost = {
     post_id: post.id,
     removed,
-    auth: api.auth.unwrap(),
-    reason: None,
-  });
+    auth: api.auth,
+  };
   return api.client.removePost(form);
 }
 
-export async function stickyPost(
+export async function featurePost(
   api: API,
-  stickied: boolean,
+  featured: boolean,
   post: Post
 ): Promise<PostResponse> {
-  let form = new StickyPost({
+  let form: FeaturePost = {
     post_id: post.id,
-    stickied,
-    auth: api.auth.unwrap(),
-  });
-  return api.client.stickyPost(form);
+    featured,
+    feature_type: PostFeatureType.Community,
+    auth: api.auth,
+  };
+  return api.client.featurePost(form);
 }
 
 export async function lockPost(
@@ -311,11 +270,11 @@ export async function lockPost(
   locked: boolean,
   post: Post
 ): Promise<PostResponse> {
-  let form = new LockPost({
+  let form: LockPost = {
     post_id: post.id,
     locked,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.lockPost(form);
 }
 
@@ -323,10 +282,10 @@ export async function resolvePost(
   api: API,
   post: Post
 ): Promise<ResolveObjectResponse> {
-  let form = new ResolveObject({
+  let form: ResolveObject = {
     q: post.ap_id,
     auth: api.auth,
-  });
+  };
   return api.client.resolveObject(form);
 }
 
@@ -334,18 +293,12 @@ export async function searchPostLocal(
   api: API,
   post: Post
 ): Promise<SearchResponse> {
-  let form = new Search({
+  let form: Search = {
     q: post.name,
-    type_: Some(SearchType.Posts),
-    sort: Some(SortType.TopAll),
-    community_id: None,
-    community_name: None,
-    creator_id: None,
-    listing_type: None,
-    page: None,
-    limit: None,
-    auth: api.auth,
-  });
+    type_: SearchType.Posts,
+    sort: SortType.TopAll,
+    auth: api.auth,
+  };
   return api.client.search(form);
 }
 
@@ -353,11 +306,10 @@ export async function getPost(
   api: API,
   post_id: number
 ): Promise<GetPostResponse> {
-  let form = new GetPost({
-    id: Some(post_id),
-    comment_id: None,
+  let form: GetPost = {
+    id: post_id,
     auth: api.auth,
-  });
+  };
   return api.client.getPost(form);
 }
 
@@ -365,19 +317,12 @@ export async function getComments(
   api: API,
   post_id: number
 ): Promise<GetCommentsResponse> {
-  let form = new GetComments({
-    post_id: Some(post_id),
-    type_: Some(ListingType.All),
-    sort: Some(CommentSortType.New), // TODO this sort might be wrong
-    max_depth: None,
-    page: None,
-    limit: None,
-    community_id: None,
-    community_name: None,
-    saved_only: None,
-    parent_id: None,
-    auth: api.auth,
-  });
+  let form: GetComments = {
+    post_id: post_id,
+    type_: ListingType.All,
+    sort: CommentSortType.New,
+    auth: api.auth,
+  };
   return api.client.getComments(form);
 }
 
@@ -385,10 +330,10 @@ export async function resolveComment(
   api: API,
   comment: Comment
 ): Promise<ResolveObjectResponse> {
-  let form = new ResolveObject({
+  let form: ResolveObject = {
     q: comment.ap_id,
     auth: api.auth,
-  });
+  };
   return api.client.resolveObject(form);
 }
 
@@ -396,10 +341,10 @@ export async function resolveBetaCommunity(
   api: API
 ): Promise<ResolveObjectResponse> {
   // Use short-hand search url
-  let form = new ResolveObject({
+  let form: ResolveObject = {
     q: "!main@lemmy-beta:8551",
     auth: api.auth,
-  });
+  };
   return api.client.resolveObject(form);
 }
 
@@ -407,10 +352,10 @@ export async function resolveCommunity(
   api: API,
   q: string
 ): Promise<ResolveObjectResponse> {
-  let form = new ResolveObject({
+  let form: ResolveObject = {
     q,
     auth: api.auth,
-  });
+  };
   return api.client.resolveObject(form);
 }
 
@@ -418,10 +363,10 @@ export async function resolvePerson(
   api: API,
   apShortname: string
 ): Promise<ResolveObjectResponse> {
-  let form = new ResolveObject({
+  let form: ResolveObject = {
     q: apShortname,
     auth: api.auth,
-  });
+  };
   return api.client.resolveObject(form);
 }
 
@@ -432,14 +377,12 @@ export async function banPersonFromSite(
   remove_data: boolean
 ): Promise<BanPersonResponse> {
   // Make sure lemmy-beta/c/main is cached on lemmy_alpha
-  let form = new BanPerson({
+  let form: BanPerson = {
     person_id,
     ban,
-    remove_data: Some(remove_data),
-    auth: api.auth.unwrap(),
-    reason: None,
-    expires: None,
-  });
+    remove_data: remove_data,
+    auth: api.auth,
+  };
   return api.client.banPerson(form);
 }
 
@@ -450,15 +393,13 @@ export async function banPersonFromCommunity(
   remove_data: boolean,
   ban: boolean
 ): Promise<BanFromCommunityResponse> {
-  let form = new BanFromCommunity({
+  let form: BanFromCommunity = {
     person_id,
     community_id,
-    remove_data: Some(remove_data),
+    remove_data: remove_data,
     ban,
-    reason: None,
-    expires: None,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.banFromCommunity(form);
 }
 
@@ -467,11 +408,11 @@ export async function followCommunity(
   follow: boolean,
   community_id: number
 ): Promise<CommunityResponse> {
-  let form = new FollowCommunity({
+  let form: FollowCommunity = {
     community_id,
     follow,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.followCommunity(form);
 }
 
@@ -480,11 +421,11 @@ export async function likePost(
   score: number,
   post: Post
 ): Promise<PostResponse> {
-  let form = new CreatePostLike({
+  let form: CreatePostLike = {
     post_id: post.id,
     score: score,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
 
   return api.client.likePost(form);
 }
@@ -492,33 +433,28 @@ export async function likePost(
 export async function createComment(
   api: API,
   post_id: number,
-  parent_id: Option<number>,
+  parent_id?: number,
   content = "a jest test comment"
 ): Promise<CommentResponse> {
-  let form = new CreateComment({
+  let form: CreateComment = {
     content,
     post_id,
     parent_id,
-    form_id: None,
-    language_id: None,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.createComment(form);
 }
 
 export async function editComment(
   api: API,
   comment_id: number,
-  content = Some("A jest test federated comment update")
+  content = "A jest test federated comment update"
 ): Promise<CommentResponse> {
-  let form = new EditComment({
+  let form: EditComment = {
     content,
     comment_id,
-    form_id: None,
-    language_id: None,
-    distinguished: None,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.editComment(form);
 }
 
@@ -527,11 +463,11 @@ export async function deleteComment(
   deleted: boolean,
   comment_id: number
 ): Promise<CommentResponse> {
-  let form = new DeleteComment({
+  let form: DeleteComment = {
     comment_id,
     deleted,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.deleteComment(form);
 }
 
@@ -540,25 +476,22 @@ export async function removeComment(
   removed: boolean,
   comment_id: number
 ): Promise<CommentResponse> {
-  let form = new RemoveComment({
+  let form: RemoveComment = {
     comment_id,
     removed,
-    reason: None,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.removeComment(form);
 }
 
 export async function getMentions(
   api: API
 ): Promise<GetPersonMentionsResponse> {
-  let form = new GetPersonMentions({
-    sort: Some(CommentSortType.New),
-    unread_only: Some(false),
-    auth: api.auth.unwrap(),
-    page: None,
-    limit: None,
-  });
+  let form: GetPersonMentions = {
+    sort: CommentSortType.New,
+    unread_only: false,
+    auth: api.auth,
+  };
   return api.client.getPersonMentions(form);
 }
 
@@ -567,11 +500,11 @@ export async function likeComment(
   score: number,
   comment: Comment
 ): Promise<CommentResponse> {
-  let form = new CreateCommentLike({
+  let form: CreateCommentLike = {
     comment_id: comment.id,
     score,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.likeComment(form);
 }
 
@@ -579,17 +512,13 @@ export async function createCommunity(
   api: API,
   name_: string = randomString(5)
 ): Promise<CommunityResponse> {
-  let description = Some("a sample description");
-  let form = new CreateCommunity({
+  let description = "a sample description";
+  let form: CreateCommunity = {
     name: name_,
     title: name_,
     description,
-    nsfw: None,
-    icon: None,
-    banner: None,
-    posting_restricted_to_mods: None,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.createCommunity(form);
 }
 
@@ -597,11 +526,10 @@ export async function getCommunity(
   api: API,
   id: number
 ): Promise<CommunityResponse> {
-  let form = new GetCommunity({
-    id: Some(id),
-    name: None,
+  let form: GetCommunity = {
+    id,
     auth: api.auth,
-  });
+  };
   return api.client.getCommunity(form);
 }
 
@@ -610,11 +538,11 @@ export async function deleteCommunity(
   deleted: boolean,
   community_id: number
 ): Promise<CommunityResponse> {
-  let form = new DeleteCommunity({
+  let form: DeleteCommunity = {
     community_id,
     deleted,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.deleteCommunity(form);
 }
 
@@ -623,13 +551,11 @@ export async function removeCommunity(
   removed: boolean,
   community_id: number
 ): Promise<CommunityResponse> {
-  let form = new RemoveCommunity({
+  let form: RemoveCommunity = {
     community_id,
     removed,
-    reason: None,
-    expires: None,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.removeCommunity(form);
 }
 
@@ -638,11 +564,11 @@ export async function createPrivateMessage(
   recipient_id: number
 ): Promise<PrivateMessageResponse> {
   let content = "A jest test federated private message";
-  let form = new CreatePrivateMessage({
+  let form: CreatePrivateMessage = {
     content,
     recipient_id,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.createPrivateMessage(form);
 }
 
@@ -651,11 +577,11 @@ export async function editPrivateMessage(
   private_message_id: number
 ): Promise<PrivateMessageResponse> {
   let updatedContent = "A jest test federated private message edited";
-  let form = new EditPrivateMessage({
+  let form: EditPrivateMessage = {
     content: updatedContent,
     private_message_id,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.editPrivateMessage(form);
 }
 
@@ -664,11 +590,11 @@ export async function deletePrivateMessage(
   deleted: boolean,
   private_message_id: number
 ): Promise<PrivateMessageResponse> {
-  let form = new DeletePrivateMessage({
+  let form: DeletePrivateMessage = {
     deleted,
     private_message_id,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.deletePrivateMessage(form);
 }
 
@@ -676,78 +602,49 @@ export async function registerUser(
   api: API,
   username: string = randomString(5)
 ): Promise<LoginResponse> {
-  let form = new Register({
+  let form: Register = {
     username,
     password,
     password_verify: password,
     show_nsfw: true,
-    email: None,
-    captcha_uuid: None,
-    captcha_answer: None,
-    honeypot: None,
-    answer: None,
-  });
+  };
   return api.client.register(form);
 }
 
 export async function saveUserSettingsBio(api: API): Promise<LoginResponse> {
-  let form = new SaveUserSettings({
-    show_nsfw: Some(true),
-    theme: Some("darkly"),
-    default_sort_type: Some(Object.keys(SortType).indexOf(SortType.Active)),
-    default_listing_type: Some(
-      Object.keys(ListingType).indexOf(ListingType.All)
-    ),
-    interface_language: Some("en"),
-    show_avatars: Some(true),
-    send_notifications_to_email: Some(false),
-    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(),
-  });
+  let form: SaveUserSettings = {
+    show_nsfw: true,
+    theme: "darkly",
+    default_sort_type: SortType.Active,
+    default_listing_type: ListingType.All,
+    interface_language: "en",
+    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
 ): Promise<LoginResponse> {
-  let avatar = Some("https://image.flaticon.com/icons/png/512/35/35896.png");
-  let banner = Some("https://image.flaticon.com/icons/png/512/36/35896.png");
-  let bio = Some("a changed bio");
-  let form = new SaveUserSettings({
-    show_nsfw: Some(false),
-    theme: Some(""),
-    default_sort_type: Some(Object.keys(SortType).indexOf(SortType.Hot)),
-    default_listing_type: Some(
-      Object.keys(ListingType).indexOf(ListingType.All)
-    ),
-    interface_language: Some(""),
+  let avatar = "https://image.flaticon.com/icons/png/512/35/35896.png";
+  let banner = "https://image.flaticon.com/icons/png/512/36/35896.png";
+  let bio = "a changed bio";
+  let form: SaveUserSettings = {
+    show_nsfw: false,
+    default_sort_type: SortType.Hot,
+    default_listing_type: ListingType.All,
+    interface_language: "",
     avatar,
     banner,
-    display_name: Some("user321"),
-    show_avatars: Some(false),
-    send_notifications_to_email: Some(false),
+    display_name: "user321",
+    show_avatars: false,
+    send_notifications_to_email: false,
     bio,
-    email: None,
-    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(),
-  });
+    auth: api.auth,
+  };
   return await saveUserSettings(alpha, form);
 }
 
@@ -759,38 +656,35 @@ export async function saveUserSettings(
 }
 
 export async function deleteUser(api: API): Promise<DeleteAccountResponse> {
-  let form = new DeleteAccount({
-    auth: api.auth.unwrap(),
+  let form: DeleteAccount = {
+    auth: api.auth,
     password,
-  });
+  };
   return api.client.deleteAccount(form);
 }
 
 export async function getSite(api: API): Promise<GetSiteResponse> {
-  let form = new GetSite({
+  let form: GetSite = {
     auth: api.auth,
-  });
+  };
   return api.client.getSite(form);
 }
 
 export async function listPrivateMessages(
   api: API
 ): Promise<PrivateMessagesResponse> {
-  let form = new GetPrivateMessages({
-    auth: api.auth.unwrap(),
-    unread_only: Some(false),
-    page: None,
-    limit: None,
-  });
+  let form: GetPrivateMessages = {
+    auth: api.auth,
+    unread_only: false,
+  };
   return api.client.getPrivateMessages(form);
 }
 
 export async function unfollowRemotes(api: API): Promise<GetSiteResponse> {
   // Unfollow all remote communities
   let site = await getSite(api);
-  let remoteFollowed = site.my_user
-    .unwrap()
-    .follows.filter(c => c.community.local == false);
+  let remoteFollowed =
+    site.my_user?.follows.filter(c => c.community.local == false) ?? [];
   for (let cu of remoteFollowed) {
     await followCommunity(api, false, cu.community.id);
   }
@@ -800,12 +694,8 @@ export async function unfollowRemotes(api: API): Promise<GetSiteResponse> {
 
 export async function followBeta(api: API): Promise<CommunityResponse> {
   let betaCommunity = (await resolveBetaCommunity(api)).community;
-  if (betaCommunity.isSome()) {
-    let follow = await followCommunity(
-      api,
-      true,
-      betaCommunity.unwrap().community.id
-    );
+  if (betaCommunity) {
+    let follow = await followCommunity(api, true, betaCommunity.community.id);
     return follow;
   } else {
     return Promise.reject("no community worked");
@@ -817,24 +707,20 @@ export async function reportPost(
   post_id: number,
   reason: string
 ): Promise<PostReportResponse> {
-  let form = new CreatePostReport({
+  let form: CreatePostReport = {
     post_id,
     reason,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.createPostReport(form);
 }
 
 export async function listPostReports(
   api: API
 ): Promise<ListPostReportsResponse> {
-  let form = new ListPostReports({
-    auth: api.auth.unwrap(),
-    page: None,
-    limit: None,
-    community_id: None,
-    unresolved_only: None,
-  });
+  let form: ListPostReports = {
+    auth: api.auth,
+  };
   return api.client.listPostReports(form);
 }
 
@@ -843,24 +729,20 @@ export async function reportComment(
   comment_id: number,
   reason: string
 ): Promise<CommentReportResponse> {
-  let form = new CreateCommentReport({
+  let form: CreateCommentReport = {
     comment_id,
     reason,
-    auth: api.auth.unwrap(),
-  });
+    auth: api.auth,
+  };
   return api.client.createCommentReport(form);
 }
 
 export async function listCommentReports(
   api: API
 ): Promise<ListCommentReportsResponse> {
-  let form = new ListCommentReports({
-    page: None,
-    limit: None,
-    community_id: None,
-    unresolved_only: None,
-    auth: api.auth.unwrap(),
-  });
+  let form: ListCommentReports = {
+    auth: api.auth,
+  };
   return api.client.listCommentReports(form);
 }
 
@@ -894,14 +776,14 @@ export async function unfollows() {
   await unfollowRemotes(epsilon);
 }
 
-export function getCommentParentId(comment: Comment): Option<number> {
+export function getCommentParentId(comment: Comment): number | undefined {
   let split = comment.path.split(".");
   // remove the 0
   split.shift();
 
   if (split.length > 1) {
-    return Some(Number(split[split.length - 2]));
+    return Number(split[split.length - 2]);
   } else {
-    return None;
+    return undefined;
   }
 }