### Libraries
+- [lemmy-js-client](https://github.com/LemmyNet/lemmy-js-client)
- [Kotlin API ( under development )](https://github.com/eiknat/lemmy-client)
## Support / Donate
web::post().to(route_post::<MarkCommentAsRead>),
)
.route("/like", web::post().to(route_post::<CreateCommentLike>))
- .route("/save", web::put().to(route_post::<SaveComment>)),
+ .route("/save", web::put().to(route_post::<SaveComment>))
+ .route("/list", web::get().to(route_get::<GetComments>)),
)
// Private Message
.service(
"/followed_communities",
web::get().to(route_get::<GetFollowedCommunities>),
)
+ .route("/join", web::post().to(route_post::<UserJoin>))
// Admin action. I don't like that it's in /user
.route("/ban", web::post().to(route_post::<BanUser>))
// Account actions. I don't like that they're in /user maybe /accounts
"inferno-router": "^7.4.2",
"js-cookie": "^2.2.0",
"jwt-decode": "^2.2.0",
+ "lemmy-js-client": "^1.0.8",
"markdown-it": "^11.0.0",
"markdown-it-container": "^3.0.0",
"markdown-it-emoji": "^1.4.0",
API,
} from './shared';
-import { PostResponse } from '../interfaces';
+import { PostResponse } from 'lemmy-js-client';
let postRes: PostResponse;
test('Remove a comment from admin and community on different instance', async () => {
let alphaUser = await registerUser(alpha);
let newAlphaApi: API = {
- url: alpha.url,
+ client: alpha.client,
auth: alphaUser.jwt,
};
-import fetch from 'node-fetch';
-
import {
LoginForm,
LoginResponse,
CommentForm,
DeleteCommentForm,
RemoveCommentForm,
+ SearchForm,
CommentResponse,
CommunityForm,
DeleteCommunityForm,
RemoveCommunityForm,
+ GetUserMentionsForm,
CommentLikeForm,
CreatePostLikeForm,
PrivateMessageForm,
EditPrivateMessageForm,
DeletePrivateMessageForm,
+ GetFollowedCommunitiesForm,
+ GetPrivateMessagesForm,
+ GetSiteForm,
+ GetPostForm,
PrivateMessageResponse,
PrivateMessagesResponse,
GetUserMentionsResponse,
SortType,
ListingType,
GetSiteResponse,
-} from '../interfaces';
+ SearchType,
+ LemmyHttp,
+} from 'lemmy-js-client';
export interface API {
- url: string;
+ client: LemmyHttp;
auth?: string;
}
-function apiUrl(api: API) {
- return `${api.url}/api/v1`;
-}
-
export let alpha: API = {
- url: 'http://localhost:8540',
+ client: new LemmyHttp('http://localhost:8540/api/v1'),
};
export let beta: API = {
- url: 'http://localhost:8550',
+ client: new LemmyHttp('http://localhost:8550/api/v1'),
};
export let gamma: API = {
- url: 'http://localhost:8560',
+ client: new LemmyHttp('http://localhost:8560/api/v1'),
};
export let delta: API = {
- url: 'http://localhost:8570',
+ client: new LemmyHttp('http://localhost:8570/api/v1'),
};
export let epsilon: API = {
- url: 'http://localhost:8580',
+ client: new LemmyHttp('http://localhost:8580/api/v1'),
};
export async function setupLogins() {
username_or_email: 'lemmy_alpha',
password: 'lemmy',
};
-
- let resAlpha: Promise<LoginResponse> = fetch(`${apiUrl(alpha)}/user/login`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(formAlpha),
- }).then(d => d.json());
+ let resAlpha = alpha.client.login(formAlpha);
let formBeta = {
username_or_email: 'lemmy_beta',
password: 'lemmy',
};
-
- let resBeta: Promise<LoginResponse> = fetch(`${apiUrl(beta)}/user/login`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(formBeta),
- }).then(d => d.json());
+ let resBeta = beta.client.login(formBeta);
let formGamma = {
username_or_email: 'lemmy_gamma',
password: 'lemmy',
};
-
- let resGamma: Promise<LoginResponse> = fetch(`${apiUrl(gamma)}/user/login`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(formGamma),
- }).then(d => d.json());
+ let resGamma = gamma.client.login(formGamma);
let formDelta = {
username_or_email: 'lemmy_delta',
password: 'lemmy',
};
-
- let resDelta: Promise<LoginResponse> = fetch(`${apiUrl(delta)}/user/login`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(formDelta),
- }).then(d => d.json());
+ let resDelta = delta.client.login(formDelta);
let formEpsilon = {
username_or_email: 'lemmy_epsilon',
password: 'lemmy',
};
-
- let resEpsilon: Promise<LoginResponse> = fetch(
- `${apiUrl(epsilon)}/user/login`,
- {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(formEpsilon),
- }
- ).then(d => d.json());
+ let resEpsilon = epsilon.client.login(formEpsilon);
let res = await Promise.all([
resAlpha,
community_id: number
): Promise<PostResponse> {
let name = 'A jest test post';
- let postForm: PostForm = {
+ let form: PostForm = {
name,
auth: api.auth,
community_id,
nsfw: false,
};
-
- let createPostRes: PostResponse = await fetch(`${apiUrl(api)}/post`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(postForm),
- }).then(d => d.json());
- return createPostRes;
+ return api.client.createPost(form);
}
export async function updatePost(api: API, post: Post): Promise<PostResponse> {
let name = 'A jest test federated post, updated';
- let postForm: PostForm = {
+ let form: PostForm = {
name,
edit_id: post.id,
auth: api.auth,
nsfw: false,
};
-
- let updateResponse: PostResponse = await fetch(`${apiUrl(api)}/post`, {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(postForm),
- }).then(d => d.json());
- return updateResponse;
+ return api.client.editPost(form);
}
export async function deletePost(
deleted: boolean,
post: Post
): Promise<PostResponse> {
- let deletePostForm: DeletePostForm = {
+ let form: DeletePostForm = {
edit_id: post.id,
deleted: deleted,
auth: api.auth,
};
-
- let deletePostRes: PostResponse = await fetch(`${apiUrl(api)}/post/delete`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(deletePostForm),
- }).then(d => d.json());
- return deletePostRes;
+ return api.client.deletePost(form);
}
export async function removePost(
removed: boolean,
post: Post
): Promise<PostResponse> {
- let removePostForm: RemovePostForm = {
+ let form: RemovePostForm = {
edit_id: post.id,
removed,
auth: api.auth,
};
-
- let removePostRes: PostResponse = await fetch(`${apiUrl(api)}/post/remove`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(removePostForm),
- }).then(d => d.json());
- return removePostRes;
+ return api.client.removePost(form);
}
export async function stickyPost(
stickied: boolean,
post: Post
): Promise<PostResponse> {
- let stickyPostForm: StickyPostForm = {
+ let form: StickyPostForm = {
edit_id: post.id,
stickied,
auth: api.auth,
};
-
- let stickyRes: PostResponse = await fetch(`${apiUrl(api)}/post/sticky`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(stickyPostForm),
- }).then(d => d.json());
-
- return stickyRes;
+ return api.client.stickyPost(form);
}
export async function lockPost(
locked: boolean,
post: Post
): Promise<PostResponse> {
- let lockPostForm: LockPostForm = {
+ let form: LockPostForm = {
edit_id: post.id,
locked,
auth: api.auth,
};
-
- let lockRes: PostResponse = await fetch(`${apiUrl(api)}/post/lock`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(lockPostForm),
- }).then(d => d.json());
-
- return lockRes;
+ return api.client.lockPost(form);
}
export async function searchPost(
api: API,
post: Post
): Promise<SearchResponse> {
- let searchUrl = `${apiUrl(api)}/search?q=${post.ap_id}&type_=All&sort=TopAll`;
- let searchResponse: SearchResponse = await fetch(searchUrl, {
- method: 'GET',
- }).then(d => d.json());
- return searchResponse;
+ let form: SearchForm = {
+ q: post.ap_id,
+ type_: SearchType.All,
+ sort: SortType.TopAll,
+ };
+ return api.client.search(form);
}
export async function getPost(
api: API,
post_id: number
): Promise<GetPostResponse> {
- let getPostUrl = `${apiUrl(api)}/post?id=${post_id}`;
- let getPostRes: GetPostResponse = await fetch(getPostUrl, {
- method: 'GET',
- }).then(d => d.json());
-
- return getPostRes;
+ let form: GetPostForm = {
+ id: post_id,
+ };
+ return api.client.getPost(form);
}
export async function searchComment(
api: API,
comment: Comment
): Promise<SearchResponse> {
- let searchUrl = `${apiUrl(api)}/search?q=${
- comment.ap_id
- }&type_=All&sort=TopAll`;
- let searchResponse: SearchResponse = await fetch(searchUrl, {
- method: 'GET',
- }).then(d => d.json());
- return searchResponse;
+ let form: SearchForm = {
+ q: comment.ap_id,
+ type_: SearchType.All,
+ sort: SortType.TopAll,
+ };
+ return api.client.search(form);
}
export async function searchForBetaCommunity(
): Promise<SearchResponse> {
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
// Use short-hand search url
- let searchUrl = `${apiUrl(
- api
- )}/search?q=!main@lemmy-beta:8550&type_=All&sort=TopAll`;
-
- let searchResponse: SearchResponse = await fetch(searchUrl, {
- method: 'GET',
- }).then(d => d.json());
- return searchResponse;
+ let form: SearchForm = {
+ q: '!main@lemmy-beta:8550',
+ type_: SearchType.All,
+ sort: SortType.TopAll,
+ };
+ return api.client.search(form);
}
export async function searchForUser(
): Promise<SearchResponse> {
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
// Use short-hand search url
- let searchUrl = `${apiUrl(
- api
- )}/search?q=${apShortname}&type_=All&sort=TopAll`;
-
- let searchResponse: SearchResponse = await fetch(searchUrl, {
- method: 'GET',
- }).then(d => d.json());
- return searchResponse;
+ let form: SearchForm = {
+ q: apShortname,
+ type_: SearchType.All,
+ sort: SortType.TopAll,
+ };
+ return api.client.search(form);
}
export async function followCommunity(
follow: boolean,
community_id: number
): Promise<CommunityResponse> {
- let followForm: FollowCommunityForm = {
+ let form: FollowCommunityForm = {
community_id,
follow,
auth: api.auth,
};
-
- let followRes: CommunityResponse = await fetch(
- `${apiUrl(api)}/community/follow`,
- {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(followForm),
- }
- )
- .then(d => d.json())
- .catch(_e => {});
-
- return followRes;
+ return api.client.followCommunity(form);
}
export async function checkFollowedCommunities(
api: API
): Promise<GetFollowedCommunitiesResponse> {
- let followedCommunitiesUrl = `${apiUrl(
- api
- )}/user/followed_communities?&auth=${api.auth}`;
- let followedCommunitiesRes: GetFollowedCommunitiesResponse = await fetch(
- followedCommunitiesUrl,
- {
- method: 'GET',
- }
- ).then(d => d.json());
- return followedCommunitiesRes;
+ let form: GetFollowedCommunitiesForm = {
+ auth: api.auth,
+ };
+ return api.client.getFollowedCommunities(form);
}
export async function likePost(
score: number,
post: Post
): Promise<PostResponse> {
- let likePostForm: CreatePostLikeForm = {
+ let form: CreatePostLikeForm = {
post_id: post.id,
score: score,
auth: api.auth,
};
- let likePostRes: PostResponse = await fetch(`${apiUrl(api)}/post/like`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(likePostForm),
- }).then(d => d.json());
-
- return likePostRes;
+ return api.client.likePost(form);
}
export async function createComment(
parent_id?: number,
content = 'a jest test comment'
): Promise<CommentResponse> {
- let commentForm: CommentForm = {
+ let form: CommentForm = {
content,
post_id,
parent_id,
auth: api.auth,
};
-
- let createResponse: CommentResponse = await fetch(`${apiUrl(api)}/comment`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(commentForm),
- }).then(d => d.json());
- return createResponse;
+ return api.client.createComment(form);
}
export async function updateComment(
edit_id: number,
content = 'A jest test federated comment update'
): Promise<CommentResponse> {
- let commentForm: CommentForm = {
+ let form: CommentForm = {
content,
edit_id,
auth: api.auth,
};
-
- let updateResponse: CommentResponse = await fetch(`${apiUrl(api)}/comment`, {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(commentForm),
- }).then(d => d.json());
- return updateResponse;
+ return api.client.editComment(form);
}
export async function deleteComment(
deleted: boolean,
edit_id: number
): Promise<CommentResponse> {
- let deleteCommentForm: DeleteCommentForm = {
+ let form: DeleteCommentForm = {
edit_id,
deleted,
auth: api.auth,
};
-
- let deleteCommentRes: CommentResponse = await fetch(
- `${apiUrl(api)}/comment/delete`,
- {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(deleteCommentForm),
- }
- ).then(d => d.json());
- return deleteCommentRes;
+ return api.client.deleteComment(form);
}
export async function removeComment(
removed: boolean,
edit_id: number
): Promise<CommentResponse> {
- let removeCommentForm: RemoveCommentForm = {
+ let form: RemoveCommentForm = {
edit_id,
removed,
auth: api.auth,
};
-
- let removeCommentRes: CommentResponse = await fetch(
- `${apiUrl(api)}/comment/remove`,
- {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(removeCommentForm),
- }
- ).then(d => d.json());
- return removeCommentRes;
+ return api.client.removeComment(form);
}
export async function getMentions(api: API): Promise<GetUserMentionsResponse> {
- let getMentionUrl = `${apiUrl(
- api
- )}/user/mention?sort=New&unread_only=false&auth=${api.auth}`;
- let getMentionsRes: GetUserMentionsResponse = await fetch(getMentionUrl, {
- method: 'GET',
- }).then(d => d.json());
- return getMentionsRes;
+ let form: GetUserMentionsForm = {
+ sort: SortType.New,
+ unread_only: false,
+ auth: api.auth,
+ };
+ return api.client.getUserMentions(form);
}
export async function likeComment(
score: number,
comment: Comment
): Promise<CommentResponse> {
- let likeCommentForm: CommentLikeForm = {
+ let form: CommentLikeForm = {
comment_id: comment.id,
score,
auth: api.auth,
};
-
- let likeCommentRes: CommentResponse = await fetch(
- `${apiUrl(api)}/comment/like`,
- {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(likeCommentForm),
- }
- ).then(d => d.json());
- return likeCommentRes;
+ return api.client.likeComment(form);
}
export async function createCommunity(
api: API,
name_: string = randomString(5)
): Promise<CommunityResponse> {
- let communityForm: CommunityForm = {
+ let form: CommunityForm = {
name: name_,
title: name_,
category_id: 1,
nsfw: false,
auth: api.auth,
};
-
- let createCommunityRes: CommunityResponse = await fetch(
- `${apiUrl(api)}/community`,
- {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(communityForm),
- }
- ).then(d => d.json());
- return createCommunityRes;
+ return api.client.createCommunity(form);
}
export async function deleteCommunity(
deleted: boolean,
edit_id: number
): Promise<CommunityResponse> {
- let deleteCommunityForm: DeleteCommunityForm = {
+ let form: DeleteCommunityForm = {
edit_id,
deleted,
auth: api.auth,
};
-
- let deleteResponse: CommunityResponse = await fetch(
- `${apiUrl(api)}/community/delete`,
- {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(deleteCommunityForm),
- }
- ).then(d => d.json());
- return deleteResponse;
+ return api.client.deleteCommunity(form);
}
export async function removeCommunity(
removed: boolean,
edit_id: number
): Promise<CommunityResponse> {
- let removeCommunityForm: RemoveCommunityForm = {
+ let form: RemoveCommunityForm = {
edit_id,
removed,
auth: api.auth,
};
-
- let removeResponse: CommunityResponse = await fetch(
- `${apiUrl(api)}/community/remove`,
- {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(removeCommunityForm),
- }
- ).then(d => d.json());
- return removeResponse;
+ return api.client.removeCommunity(form);
}
export async function createPrivateMessage(
recipient_id: number
): Promise<PrivateMessageResponse> {
let content = 'A jest test federated private message';
- let privateMessageForm: PrivateMessageForm = {
+ let form: PrivateMessageForm = {
content,
recipient_id,
auth: api.auth,
};
-
- let createRes: PrivateMessageResponse = await fetch(
- `${apiUrl(api)}/private_message`,
- {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(privateMessageForm),
- }
- ).then(d => d.json());
- return createRes;
+ return api.client.createPrivateMessage(form);
}
export async function updatePrivateMessage(
edit_id: number
): Promise<PrivateMessageResponse> {
let updatedContent = 'A jest test federated private message edited';
- let updatePrivateMessageForm: EditPrivateMessageForm = {
+ let form: EditPrivateMessageForm = {
content: updatedContent,
edit_id,
auth: api.auth,
};
-
- let updateRes: PrivateMessageResponse = await fetch(
- `${apiUrl(api)}/private_message`,
- {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(updatePrivateMessageForm),
- }
- ).then(d => d.json());
- return updateRes;
+ return api.client.editPrivateMessage(form);
}
export async function deletePrivateMessage(
deleted: boolean,
edit_id: number
): Promise<PrivateMessageResponse> {
- let deletePrivateMessageForm: DeletePrivateMessageForm = {
+ let form: DeletePrivateMessageForm = {
deleted,
edit_id,
auth: api.auth,
};
-
- let deleteRes: PrivateMessageResponse = await fetch(
- `${apiUrl(api)}/private_message/delete`,
- {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(deletePrivateMessageForm),
- }
- ).then(d => d.json());
-
- return deleteRes;
+ return api.client.deletePrivateMessage(form);
}
export async function registerUser(
api: API,
username: string = randomString(5)
): Promise<LoginResponse> {
- let registerForm: RegisterForm = {
+ let form: RegisterForm = {
username,
password: 'test',
password_verify: 'test',
admin: false,
show_nsfw: true,
};
-
- let registerRes: Promise<LoginResponse> = fetch(
- `${apiUrl(api)}/user/register`,
- {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(registerForm),
- }
- ).then(d => d.json());
-
- return registerRes;
+ return api.client.register(form);
}
export async function saveUserSettingsBio(
let form: UserSettingsForm = {
show_nsfw: true,
theme: 'darkly',
- default_sort_type: SortType.Active,
- default_listing_type: ListingType.All,
+ default_sort_type: Object.keys(SortType).indexOf(SortType.Active),
+ default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
lang: 'en',
show_avatars: true,
send_notifications_to_email: false,
bio: 'a changed bio',
auth,
};
-
- let res: Promise<LoginResponse> = fetch(
- `${apiUrl(api)}/user/save_user_settings`,
- {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: wrapper(form),
- }
- ).then(d => d.json());
- return res;
+ return api.client.saveUserSettings(form);
}
export async function getSite(
api: API,
auth: string
): Promise<GetSiteResponse> {
- let siteUrl = `${apiUrl(api)}/site?auth=${auth}`;
-
- let res: GetSiteResponse = await fetch(siteUrl, {
- method: 'GET',
- }).then(d => d.json());
- return res;
+ let form: GetSiteForm = {
+ auth,
+ };
+ return api.client.getSite(form);
}
export async function listPrivateMessages(
api: API
): Promise<PrivateMessagesResponse> {
- let getPrivateMessagesUrl = `${apiUrl(api)}/private_message/list?auth=${
- api.auth
- }&unread_only=false&limit=999`;
-
- let getPrivateMessagesRes: PrivateMessagesResponse = await fetch(
- getPrivateMessagesUrl,
- {
- method: 'GET',
- }
- ).then(d => d.json());
- return getPrivateMessagesRes;
+ let form: GetPrivateMessagesForm = {
+ auth: api.auth,
+ unread_only: false,
+ limit: 999,
+ };
+ return api.client.getPrivateMessages(form);
}
export async function unfollowRemotes(
SiteConfigForm,
GetSiteConfigResponse,
WebSocketJsonResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService } from '../services';
import { wsJsonToRes, capitalizeFirstLetter, toast, randomStr } from '../utils';
import autosize from 'autosize';
WebSocketJsonResponse,
UserOperation,
CommentResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { capitalizeFirstLetter, wsJsonToRes } from '../utils';
import { WebSocketService, UserService } from '../services';
import { i18n } from '../i18next';
AddAdminForm,
TransferCommunityForm,
TransferSiteForm,
- BanType,
- CommentSortType,
SortType,
-} from '../interfaces';
+} from 'lemmy-js-client';
+import { CommentSortType, BanType } from '../interfaces';
import { WebSocketService, UserService } from '../services';
import {
mdToHtml,
import { Component } from 'inferno';
+import { CommentSortType } from '../interfaces';
import {
CommentNode as CommentNodeI,
CommunityUser,
UserView,
- CommentSortType,
SortType,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { commentSort, commentSortSortType } from '../utils';
import { CommentNode } from './comment-node';
WebSocketJsonResponse,
GetSiteResponse,
Site,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService } from '../services';
import { wsJsonToRes, toast, getPageFromProps } from '../utils';
import { CommunityLink } from './community-link';
refetch() {
let listCommunitiesForm: ListCommunitiesForm = {
- sort: SortType[SortType.TopAll],
+ sort: SortType.TopAll,
limit: communityLimit,
page: this.state.page,
};
ListCategoriesResponse,
CommunityResponse,
WebSocketJsonResponse,
-} from '../interfaces';
+ Community,
+} from 'lemmy-js-client';
import { WebSocketService } from '../services';
import { wsJsonToRes, capitalizeFirstLetter, toast, randomStr } from '../utils';
import { i18n } from '../i18next';
-import { Community } from '../interfaces';
import { MarkdownTextArea } from './markdown-textarea';
import { ImageUploadForm } from './image-upload-form';
import { Component } from 'inferno';
import { Link } from 'inferno-router';
-import { Community } from '../interfaces';
+import { Community } from 'lemmy-js-client';
import { hostname, pictrsAvatarThumbnail, showAvatars } from '../utils';
interface CommunityOther {
import { Helmet } from 'inferno-helmet';
import { Subscription } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators';
+import { DataType } from '../interfaces';
import {
UserOperation,
Community as CommunityI,
GetPostsForm,
GetCommunityForm,
ListingType,
- DataType,
GetPostsResponse,
PostResponse,
AddModToCommunityResponse,
WebSocketJsonResponse,
GetSiteResponse,
Site,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService } from '../services';
import { PostListings } from './post-listings';
import { CommentNodes } from './comment-nodes';
interface UrlParams {
dataType?: string;
- sort?: string;
+ sort?: SortType;
page?: number;
}
<SortSelect sort={this.state.sort} onChange={this.handleSortChange} />
</span>
<a
- href={`/feeds/c/${this.state.communityName}.xml?sort=${
- SortType[this.state.sort]
- }`}
+ href={`/feeds/c/${this.state.communityName}.xml?sort=${this.state.sort}`}
target="_blank"
title="RSS"
rel="noopener"
}
handleSortChange(val: SortType) {
- this.updateUrl({ sort: SortType[val].toLowerCase(), page: 1 });
+ this.updateUrl({ sort: val, page: 1 });
window.scrollTo(0, 0);
}
handleDataTypeChange(val: DataType) {
- this.updateUrl({ dataType: DataType[val].toLowerCase(), page: 1 });
+ this.updateUrl({ dataType: DataType[val], page: 1 });
window.scrollTo(0, 0);
}
updateUrl(paramUpdates: UrlParams) {
- const dataTypeStr =
- paramUpdates.dataType || DataType[this.state.dataType].toLowerCase();
- const sortStr =
- paramUpdates.sort || SortType[this.state.sort].toLowerCase();
+ const dataTypeStr = paramUpdates.dataType || DataType[this.state.dataType];
+ const sortStr = paramUpdates.sort || this.state.sort;
const page = paramUpdates.page || this.state.page;
this.props.history.push(
`/c/${this.state.community.name}/data_type/${dataTypeStr}/sort/${sortStr}/page/${page}`
let getPostsForm: GetPostsForm = {
page: this.state.page,
limit: fetchLimit,
- sort: SortType[this.state.sort],
- type_: ListingType[ListingType.Community],
+ sort: this.state.sort,
+ type_: ListingType.Community,
community_id: this.state.community.id,
};
WebSocketService.Instance.getPosts(getPostsForm);
let getCommentsForm: GetCommentsForm = {
page: this.state.page,
limit: fetchLimit,
- sort: SortType[this.state.sort],
- type_: ListingType[ListingType.Community],
+ sort: this.state.sort,
+ type_: ListingType.Community,
community_id: this.state.community.id,
};
WebSocketService.Instance.getComments(getCommentsForm);
WebSocketJsonResponse,
GetSiteResponse,
Site,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { toast, wsJsonToRes } from '../utils';
import { WebSocketService, UserService } from '../services';
import { i18n } from '../i18next';
WebSocketJsonResponse,
GetSiteResponse,
Site,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { i18n } from '../i18next';
interface CreatePostState {
GetSiteResponse,
Site,
PrivateMessageFormParams,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { toast, wsJsonToRes } from '../utils';
import { i18n } from '../i18next';
UserOperation,
WebSocketJsonResponse,
GetSiteResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
interface FooterState {
version: string;
import { Component, linkEvent } from 'inferno';
-import { Post } from '../interfaces';
+import { Post } from 'lemmy-js-client';
import { mdToHtml } from '../utils';
import { i18n } from '../i18next';
PrivateMessageResponse,
GetSiteResponse,
Site,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService, UserService } from '../services';
import {
wsJsonToRes,
refetch() {
let repliesForm: GetRepliesForm = {
- sort: SortType[this.state.sort],
+ sort: this.state.sort,
unread_only: this.state.unreadOrAll == UnreadOrAll.Unread,
page: this.state.page,
limit: fetchLimit,
WebSocketService.Instance.getReplies(repliesForm);
let userMentionsForm: GetUserMentionsForm = {
- sort: SortType[this.state.sort],
+ sort: this.state.sort,
unread_only: this.state.unreadOrAll == UnreadOrAll.Unread,
page: this.state.page,
limit: fetchLimit,
UserOperation,
WebSocketJsonResponse,
GetSiteResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService } from '../services';
import { wsJsonToRes, toast } from '../utils';
import { i18n } from '../i18next';
import { Component, linkEvent } from 'inferno';
-import { ListingType } from '../interfaces';
+import { ListingType } from 'lemmy-js-client';
import { UserService } from '../services';
-
+import { randomStr } from '../utils';
import { i18n } from '../i18next';
interface ListingTypeSelectProps {
ListingTypeSelectProps,
ListingTypeSelectState
> {
+ private id = `listing-type-input-${randomStr()}`;
+
private emptyState: ListingTypeSelectState = {
type_: this.props.type_,
};
`}
>
<input
+ id={`${this.id}-subscribed`}
type="radio"
value={ListingType.Subscribed}
checked={this.state.type_ == ListingType.Subscribed}
}`}
>
<input
+ id={`${this.id}-all`}
type="radio"
value={ListingType.All}
checked={this.state.type_ == ListingType.All}
}
handleTypeChange(i: ListingTypeSelect, event: any) {
- i.props.onChange(Number(event.target.value));
+ i.props.onChange(event.target.value);
}
}
GetCaptchaResponse,
WebSocketJsonResponse,
Site,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService, UserService } from '../services';
import { wsJsonToRes, validEmail, toast } from '../utils';
import { i18n } from '../i18next';
SortType,
GetSiteResponse,
ListingType,
- DataType,
SiteResponse,
GetPostsResponse,
PostResponse,
AddAdminResponse,
BanUserResponse,
WebSocketJsonResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
+import { DataType } from '../interfaces';
import { WebSocketService, UserService } from '../services';
import { PostListings } from './post-listings';
import { CommentNodes } from './comment-nodes';
}
interface UrlParams {
- listingType?: string;
+ listingType?: ListingType;
dataType?: string;
- sort?: string;
+ sort?: SortType;
page?: number;
}
}
let listCommunitiesForm: ListCommunitiesForm = {
- sort: SortType[SortType.Hot],
+ sort: SortType.Hot,
limit: 6,
};
}
updateUrl(paramUpdates: UrlParams) {
- const listingTypeStr =
- paramUpdates.listingType ||
- ListingType[this.state.listingType].toLowerCase();
- const dataTypeStr =
- paramUpdates.dataType || DataType[this.state.dataType].toLowerCase();
- const sortStr =
- paramUpdates.sort || SortType[this.state.sort].toLowerCase();
+ const listingTypeStr = paramUpdates.listingType || this.state.listingType;
+ const dataTypeStr = paramUpdates.dataType || DataType[this.state.dataType];
+ const sortStr = paramUpdates.sort || this.state.sort;
const page = paramUpdates.page || this.state.page;
this.props.history.push(
`/home/data_type/${dataTypeStr}/listing_type/${listingTypeStr}/sort/${sortStr}/page/${page}`
</span>
{this.state.listingType == ListingType.All && (
<a
- href={`/feeds/all.xml?sort=${SortType[this.state.sort]}`}
+ href={`/feeds/all.xml?sort=${this.state.sort}`}
target="_blank"
rel="noopener"
title="RSS"
{UserService.Instance.user &&
this.state.listingType == ListingType.Subscribed && (
<a
- href={`/feeds/front/${UserService.Instance.auth}.xml?sort=${
- SortType[this.state.sort]
- }`}
+ href={`/feeds/front/${UserService.Instance.auth}.xml?sort=${this.state.sort}`}
target="_blank"
title="RSS"
rel="noopener"
}
handleSortChange(val: SortType) {
- this.updateUrl({ sort: SortType[val].toLowerCase(), page: 1 });
+ this.updateUrl({ sort: val, page: 1 });
window.scrollTo(0, 0);
}
handleListingTypeChange(val: ListingType) {
- this.updateUrl({ listingType: ListingType[val].toLowerCase(), page: 1 });
+ this.updateUrl({ listingType: val, page: 1 });
window.scrollTo(0, 0);
}
handleDataTypeChange(val: DataType) {
- this.updateUrl({ dataType: DataType[val].toLowerCase(), page: 1 });
+ this.updateUrl({ dataType: DataType[val], page: 1 });
window.scrollTo(0, 0);
}
let getPostsForm: GetPostsForm = {
page: this.state.page,
limit: fetchLimit,
- sort: SortType[this.state.sort],
- type_: ListingType[this.state.listingType],
+ sort: this.state.sort,
+ type_: this.state.listingType,
};
WebSocketService.Instance.getPosts(getPostsForm);
} else {
let getCommentsForm: GetCommentsForm = {
page: this.state.page,
limit: fetchLimit,
- sort: SortType[this.state.sort],
- type_: ListingType[this.state.listingType],
+ sort: this.state.sort,
+ type_: this.state.listingType,
};
WebSocketService.Instance.getComments(getCommentsForm);
}
WebSocketJsonResponse,
GetSiteResponse,
Site,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService } from '../services';
import { wsJsonToRes, addTypeInfo, fetchLimit, toast } from '../utils';
import { MomentTime } from './moment-time';
PrivateMessage,
PrivateMessageResponse,
WebSocketJsonResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
import {
wsJsonToRes,
pictrsAvatarThumbnail,
this.context.router.history.push(`/search/`);
} else {
this.context.router.history.push(
- `/search/q/${searchParam}/type/all/sort/topall/page/1`
+ `/search/q/${searchParam}/type/All/sort/TopAll/page/1`
);
}
}
fetchUnreads() {
console.log('Fetching unreads...');
let repliesForm: GetRepliesForm = {
- sort: SortType[SortType.New],
+ sort: SortType.New,
unread_only: true,
page: 1,
limit: fetchLimit,
};
let userMentionsForm: GetUserMentionsForm = {
- sort: SortType[SortType.New],
+ sort: SortType.New,
unread_only: true,
page: 1,
limit: fetchLimit,
WebSocketJsonResponse,
GetSiteResponse,
Site,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService, UserService } from '../services';
import { wsJsonToRes, capitalizeFirstLetter, toast } from '../utils';
import { i18n } from '../i18next';
SearchType,
SearchResponse,
WebSocketJsonResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService, UserService } from '../services';
import {
wsJsonToRes,
);
let listCommunitiesForm: ListCommunitiesForm = {
- sort: SortType[SortType.TopAll],
+ sort: SortType.TopAll,
limit: 9999,
};
if (validURL(this.state.postForm.url)) {
let form: SearchForm = {
q: this.state.postForm.url,
- type_: SearchType[SearchType.Url],
- sort: SortType[SortType.TopAll],
+ type_: SearchType.Url,
+ sort: SortType.TopAll,
page: 1,
limit: 6,
};
fetchSimilarPosts() {
let form: SearchForm = {
q: this.state.postForm.name,
- type_: SearchType[SearchType.Posts],
- sort: SortType[SortType.TopAll],
+ type_: SearchType.Posts,
+ sort: SortType.TopAll,
community_id: this.state.postForm.community_id,
page: 1,
limit: 6,
SavePostForm,
CommunityUser,
UserView,
- BanType,
BanFromCommunityForm,
BanUserForm,
AddModToCommunityForm,
AddAdminForm,
TransferSiteForm,
TransferCommunityForm,
-} from '../interfaces';
+} from 'lemmy-js-client';
+import { BanType } from '../interfaces';
import { MomentTime } from './moment-time';
import { PostForm } from './post-form';
import { IFramelyCard } from './iframely-card';
import { Component } from 'inferno';
import { Link } from 'inferno-router';
-import { Post, SortType } from '../interfaces';
+import { Post, SortType } from 'lemmy-js-client';
import { postSort } from '../utils';
import { PostListing } from './post-listing';
import { i18n } from '../i18next';
Comment,
MarkCommentAsReadForm,
CommentResponse,
- CommentSortType,
- CommentViewType,
CommunityUser,
CommunityResponse,
CommentNode as CommentNodeI,
GetSiteResponse,
GetCommunityResponse,
WebSocketJsonResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
+import { CommentSortType, CommentViewType } from '../interfaces';
import { WebSocketService, UserService } from '../services';
import {
wsJsonToRes,
if (this.state.post.url) {
let form: SearchForm = {
q: this.state.post.url,
- type_: SearchType[SearchType.Url],
- sort: SortType[SortType.TopAll],
+ type_: SearchType.Url,
+ sort: SortType.TopAll,
page: 1,
limit: 6,
};
GetUserDetailsForm,
SortType,
WebSocketJsonResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService } from '../services';
import {
capitalizeFirstLetter,
this.state.privateMessageForm.recipient_id = this.props.params.recipient_id;
let form: GetUserDetailsForm = {
user_id: this.state.privateMessageForm.recipient_id,
- sort: SortType[SortType.New],
+ sort: SortType.New,
saved_only: false,
};
WebSocketService.Instance.getUserDetails(form);
PrivateMessage as PrivateMessageI,
DeletePrivateMessageForm,
MarkPrivateMessageAsReadForm,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService, UserService } from '../services';
import { mdToHtml, pictrsAvatarThumbnail, showAvatars, toast } from '../utils';
import { MomentTime } from './moment-time';
WebSocketJsonResponse,
GetSiteResponse,
Site,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService } from '../services';
import {
wsJsonToRes,
interface UrlParams {
q?: string;
- type_?: string;
- sort?: string;
+ type_?: SearchType;
+ sort?: SortType;
page?: number;
}
search() {
let form: SearchForm = {
q: this.state.q,
- type_: SearchType[this.state.type_],
- sort: SortType[this.state.sort],
+ type_: this.state.type_,
+ sort: this.state.sort,
page: this.state.page,
limit: fetchLimit,
};
}
handleSortChange(val: SortType) {
- this.updateUrl({ sort: SortType[val].toLowerCase(), page: 1 });
+ this.updateUrl({ sort: val, page: 1 });
}
handleTypeChange(i: Search, event: any) {
i.updateUrl({
- type_: SearchType[Number(event.target.value)].toLowerCase(),
+ type_: SearchType[event.target.value],
page: 1,
});
}
event.preventDefault();
i.updateUrl({
q: i.state.searchText,
- type_: SearchType[i.state.type_].toLowerCase(),
- sort: SortType[i.state.sort].toLowerCase(),
+ type_: i.state.type_,
+ sort: i.state.sort,
page: i.state.page,
});
}
updateUrl(paramUpdates: UrlParams) {
const qStr = paramUpdates.q || this.state.q;
- const typeStr =
- paramUpdates.type_ || SearchType[this.state.type_].toLowerCase();
- const sortStr =
- paramUpdates.sort || SortType[this.state.sort].toLowerCase();
+ const typeStr = paramUpdates.type_ || this.state.type_;
+ const sortStr = paramUpdates.sort || this.state.sort;
const page = paramUpdates.page || this.state.page;
this.props.history.push(
`/search/q/${qStr}/type/${typeStr}/sort/${sortStr}/page/${page}`
LoginResponse,
UserOperation,
WebSocketJsonResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService, UserService } from '../services';
import { wsJsonToRes, toast } from '../utils';
import { SiteForm } from './site-form';
RemoveCommunityForm,
UserView,
AddModToCommunityForm,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { WebSocketService, UserService } from '../services';
import { mdToHtml, getUnixTime } from '../utils';
import { CommunityForm } from './community-form';
import { Prompt } from 'inferno-router';
import { MarkdownTextArea } from './markdown-textarea';
import { ImageUploadForm } from './image-upload-form';
-import { Site, SiteForm as SiteFormI } from '../interfaces';
+import { Site, SiteForm as SiteFormI } from 'lemmy-js-client';
import { WebSocketService } from '../services';
import { capitalizeFirstLetter, randomStr } from '../utils';
import { i18n } from '../i18next';
import { Component, linkEvent } from 'inferno';
-import { SortType } from '../interfaces';
-import { sortingHelpUrl } from '../utils';
+import { SortType } from 'lemmy-js-client';
+import { sortingHelpUrl, randomStr } from '../utils';
import { i18n } from '../i18next';
interface SortSelectProps {
}
export class SortSelect extends Component<SortSelectProps, SortSelectState> {
+ private id = `sort-select-${randomStr()}`;
private emptyState: SortSelectState = {
sort: this.props.sort,
};
return (
<>
<select
+ id={this.id}
+ name={this.id}
value={this.state.sort}
onChange={linkEvent(this, this.handleSortChange)}
class="custom-select w-auto mr-2 mb-2"
}
handleSortChange(i: SortSelect, event: any) {
- i.props.onChange(Number(event.target.value));
+ i.props.onChange(event.target.value);
}
}
Site,
WebSocketJsonResponse,
UserOperation,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { i18n } from '../i18next';
import { T } from 'inferno-i18next';
import { repoUrl, wsJsonToRes, toast } from '../utils';
UserDetailsResponse,
UserView,
WebSocketJsonResponse,
- UserDetailsView,
CommentResponse,
BanUserResponse,
PostResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
+import { UserDetailsView } from '../interfaces';
import {
wsJsonToRes,
toast,
user_id?: number;
page: number;
limit: number;
- sort: string;
+ sort: SortType;
enableDownvotes: boolean;
enableNsfw: boolean;
view: UserDetailsView;
];
// Sort it
- if (SortType[this.props.sort] === SortType.New) {
+ if (this.props.sort === SortType.New) {
combined.sort((a, b) => b.data.published.localeCompare(a.data.published));
} else {
combined.sort((a, b) => b.data.score - a.data.score);
import { Component } from 'inferno';
import { Link } from 'inferno-router';
-import { UserView } from '../interfaces';
+import { UserView } from 'lemmy-js-client';
import {
pictrsAvatarThumbnail,
showAvatars,
DeleteAccountForm,
WebSocketJsonResponse,
GetSiteResponse,
- UserDetailsView,
UserDetailsResponse,
AddAdminResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
+import { UserDetailsView } from '../interfaces';
import { WebSocketService, UserService } from '../services';
import {
wsJsonToRes,
interface UrlParams {
view?: string;
- sort?: string;
+ sort?: SortType;
page?: number;
}
);
}
- static getViewFromProps(view: any): UserDetailsView {
- return view
- ? UserDetailsView[capitalizeFirstLetter(view)]
- : UserDetailsView.Overview;
+ static getViewFromProps(view: string): UserDetailsView {
+ return view ? UserDetailsView[view] : UserDetailsView.Overview;
}
- static getSortTypeFromProps(sort: any): SortType {
+ static getSortTypeFromProps(sort: string): SortType {
return sort ? routeSortTypeToEnum(sort) : SortType.New;
}
- static getPageFromProps(page: any): number {
+ static getPageFromProps(page: number): number {
return page ? Number(page) : 1;
}
<UserDetails
user_id={this.state.user_id}
username={this.state.username}
- sort={SortType[this.state.sort]}
+ sort={this.state.sort}
page={this.state.page}
limit={fetchLimit}
enableDownvotes={this.state.siteRes.site.enable_downvotes}
hideHot
/>
<a
- href={`/feeds/u/${this.state.username}.xml?sort=${
- SortType[this.state.sort]
- }`}
+ href={`/feeds/u/${this.state.username}.xml?sort=${this.state.sort}`}
target="_blank"
rel="noopener"
title="RSS"
<div class="mr-2">{i18n.t('sort_type')}</div>
</label>
<ListingTypeSelect
- type_={this.state.userSettingsForm.default_listing_type}
+ type_={
+ Object.values(ListingType)[
+ this.state.userSettingsForm.default_listing_type
+ ]
+ }
onChange={this.handleUserSettingsListingTypeChange}
/>
</form>
<div class="mr-2">{i18n.t('type')}</div>
</label>
<SortSelect
- sort={this.state.userSettingsForm.default_sort_type}
+ sort={
+ Object.values(SortType)[
+ this.state.userSettingsForm.default_sort_type
+ ]
+ }
onChange={this.handleUserSettingsSortTypeChange}
/>
</form>
updateUrl(paramUpdates: UrlParams) {
const page = paramUpdates.page || this.state.page;
- const viewStr =
- paramUpdates.view || UserDetailsView[this.state.view].toLowerCase();
- const sortStr =
- paramUpdates.sort || SortType[this.state.sort].toLowerCase();
+ const viewStr = paramUpdates.view || UserDetailsView[this.state.view];
+ const sortStr = paramUpdates.sort || this.state.sort;
this.props.history.push(
`/u/${this.state.username}/view/${viewStr}/sort/${sortStr}/page/${page}`
);
}
handleSortChange(val: SortType) {
- this.updateUrl({ sort: SortType[val].toLowerCase(), page: 1 });
+ this.updateUrl({ sort: val, page: 1 });
}
handleViewChange(i: User, event: any) {
i.updateUrl({
- view: UserDetailsView[Number(event.target.value)].toLowerCase(),
+ view: UserDetailsView[Number(event.target.value)],
page: 1,
});
}
}
handleUserSettingsSortTypeChange(val: SortType) {
- this.state.userSettingsForm.default_sort_type = val;
+ this.state.userSettingsForm.default_sort_type = Object.keys(
+ SortType
+ ).indexOf(val);
this.setState(this.state);
}
handleUserSettingsListingTypeChange(val: ListingType) {
- this.state.userSettingsForm.default_listing_type = val;
+ this.state.userSettingsForm.default_listing_type = Object.keys(
+ ListingType
+ ).indexOf(val);
this.setState(this.state);
}
-export enum UserOperation {
- Login,
- Register,
- GetCaptcha,
- CreateCommunity,
- CreatePost,
- ListCommunities,
- ListCategories,
- GetPost,
- GetCommunity,
- CreateComment,
- EditComment,
- DeleteComment,
- RemoveComment,
- MarkCommentAsRead,
- SaveComment,
- CreateCommentLike,
- GetPosts,
- CreatePostLike,
- EditPost,
- DeletePost,
- RemovePost,
- LockPost,
- StickyPost,
- SavePost,
- EditCommunity,
- DeleteCommunity,
- RemoveCommunity,
- FollowCommunity,
- GetFollowedCommunities,
- GetUserDetails,
- GetReplies,
- GetUserMentions,
- MarkUserMentionAsRead,
- GetModlog,
- BanFromCommunity,
- AddModToCommunity,
- CreateSite,
- EditSite,
- GetSite,
- AddAdmin,
- BanUser,
- Search,
- MarkAllAsRead,
- SaveUserSettings,
- TransferCommunity,
- TransferSite,
- DeleteAccount,
- PasswordReset,
- PasswordChange,
- CreatePrivateMessage,
- EditPrivateMessage,
- DeletePrivateMessage,
- MarkPrivateMessageAsRead,
- GetPrivateMessages,
- UserJoin,
- GetComments,
- GetSiteConfig,
- SaveSiteConfig,
-}
-
export enum CommentSortType {
Hot,
Top,
Chat,
}
-export enum ListingType {
- All,
- Subscribed,
- Community,
-}
-
export enum DataType {
Post,
Comment,
}
-export enum SortType {
- Active,
- Hot,
- New,
- TopDay,
- TopWeek,
- TopMonth,
- TopYear,
- TopAll,
-}
-
-export enum SearchType {
- All,
- Comments,
- Posts,
- Communities,
- Users,
- Url,
-}
-
-export interface Claims {
- id: number;
- iss: string;
-}
-
-export interface User {
- id: number;
- name: string;
- preferred_username?: string;
- email?: string;
- avatar?: string;
- banner?: string;
- admin: boolean;
- banned: boolean;
- published: string;
- updated?: string;
- show_nsfw: boolean;
- theme: string;
- default_sort_type: SortType;
- default_listing_type: ListingType;
- lang: string;
- show_avatars: boolean;
- send_notifications_to_email: boolean;
- matrix_user_id?: string;
- actor_id: string;
- bio?: string;
- local: boolean;
- last_refreshed_at: string;
-}
-
-export interface UserView {
- id: number;
- actor_id: string;
- name: string;
- preferred_username?: string;
- avatar?: string;
- banner?: string;
- matrix_user_id?: string;
- bio?: string;
- local: boolean;
- published: string;
- number_of_posts: number;
- post_score: number;
- number_of_comments: number;
- comment_score: number;
- banned: boolean;
-}
-
-export interface CommunityUser {
- id: number;
- user_id: number;
- user_actor_id: string;
- user_local: boolean;
- user_name: string;
- user_preferred_username?: string;
- avatar?: string;
- community_id: number;
- community_actor_id: string;
- community_local: boolean;
- community_name: string;
- community_icon?: string;
- published: string;
-}
-
-export interface Community {
- id: number;
- actor_id: string;
- local: boolean;
- name: string;
- title: string;
- icon?: string;
- banner?: string;
- description?: string;
- category_id: number;
- creator_id: number;
- removed: boolean;
- deleted: boolean;
- nsfw: boolean;
- published: string;
- updated?: string;
- creator_actor_id: string;
- creator_local: boolean;
- last_refreshed_at: string;
- creator_name: string;
- creator_preferred_username?: string;
- creator_avatar?: string;
- category_name: string;
- number_of_subscribers: number;
- number_of_posts: number;
- number_of_comments: number;
- user_id?: number;
- subscribed?: boolean;
-}
-
-export interface Post {
- id: number;
- name: string;
- url?: string;
- body?: string;
- creator_id: number;
- community_id: number;
- removed: boolean;
- deleted: boolean;
- locked: boolean;
- stickied: boolean;
- embed_title?: string;
- embed_description?: string;
- embed_html?: string;
- thumbnail_url?: string;
- ap_id: string;
- local: boolean;
- nsfw: boolean;
- banned: boolean;
- banned_from_community: boolean;
- published: string;
- updated?: string;
- creator_actor_id: string;
- creator_local: boolean;
- creator_name: string;
- creator_preferred_username?: string;
- creator_published: string;
- creator_avatar?: string;
- community_actor_id: string;
- community_local: boolean;
- community_name: string;
- community_icon?: string;
- community_removed: boolean;
- community_deleted: boolean;
- community_nsfw: boolean;
- number_of_comments: number;
- score: number;
- upvotes: number;
- downvotes: number;
- hot_rank: number;
- hot_rank_active: number;
- newest_activity_time: string;
- user_id?: number;
- my_vote?: number;
- subscribed?: boolean;
- read?: boolean;
- saved?: boolean;
- duplicates?: Array<Post>;
-}
-
-export interface Comment {
- id: number;
- ap_id: string;
- local: boolean;
- creator_id: number;
- post_id: number;
- post_name: string;
- parent_id?: number;
- content: string;
- removed: boolean;
- deleted: boolean;
- read: boolean;
- published: string;
- updated?: string;
- community_id: number;
- community_actor_id: string;
- community_local: boolean;
- community_name: string;
- community_icon?: string;
- banned: boolean;
- banned_from_community: boolean;
- creator_actor_id: string;
- creator_local: boolean;
- creator_name: string;
- creator_preferred_username?: string;
- creator_avatar?: string;
- creator_published: string;
- score: number;
- upvotes: number;
- downvotes: number;
- hot_rank: number;
- hot_rank_active: number;
- user_id?: number;
- my_vote?: number;
- subscribed?: number;
- saved?: boolean;
- user_mention_id?: number; // For mention type
- recipient_id?: number;
- recipient_actor_id?: string;
- recipient_local?: boolean;
- depth?: number;
-}
-
-export interface Category {
- id: number;
- name: string;
-}
-
-export interface Site {
- id: number;
- name: string;
- description?: string;
- creator_id: number;
- published: string;
- updated?: string;
- creator_name: string;
- creator_preferred_username?: string;
- number_of_users: number;
- number_of_posts: number;
- number_of_comments: number;
- number_of_communities: number;
- enable_downvotes: boolean;
- open_registration: boolean;
- enable_nsfw: boolean;
- icon?: string;
- banner?: string;
-}
-
-export interface PrivateMessage {
- id: number;
- creator_id: number;
- recipient_id: number;
- content: string;
- deleted: boolean;
- read: boolean;
- published: string;
- updated?: string;
- ap_id: string;
- local: boolean;
- creator_name: string;
- creator_preferred_username?: string;
- creator_avatar?: string;
- creator_actor_id: string;
- creator_local: boolean;
- recipient_name: string;
- recipient_preferred_username?: string;
- recipient_avatar?: string;
- recipient_actor_id: string;
- recipient_local: boolean;
-}
-
export enum BanType {
Community,
Site,
}
-export interface FollowCommunityForm {
- community_id: number;
- follow: boolean;
- auth?: string;
-}
-
-export interface GetFollowedCommunitiesForm {
- auth: string;
-}
-
-export interface GetFollowedCommunitiesResponse {
- communities: Array<CommunityUser>;
-}
-
-export interface GetUserDetailsForm {
- user_id?: number;
- username?: string;
- sort: string;
- page?: number;
- limit?: number;
- community_id?: number;
- saved_only: boolean;
-}
-
-export interface UserDetailsResponse {
- user: UserView;
- follows: Array<CommunityUser>;
- moderates: Array<CommunityUser>;
- comments: Array<Comment>;
- posts: Array<Post>;
- admins: Array<UserView>;
-}
-
-export interface GetRepliesForm {
- sort: string;
- page?: number;
- limit?: number;
- unread_only: boolean;
- auth?: string;
-}
-
-export interface GetRepliesResponse {
- replies: Array<Comment>;
-}
-
-export interface GetUserMentionsForm {
- sort: string;
- page?: number;
- limit?: number;
- unread_only: boolean;
- auth?: string;
-}
-
-export interface GetUserMentionsResponse {
- mentions: Array<Comment>;
-}
-
-export interface MarkUserMentionAsReadForm {
- user_mention_id: number;
- read: boolean;
- auth?: string;
-}
-
-export interface UserMentionResponse {
- mention: Comment;
-}
-
-export interface BanFromCommunityForm {
- community_id: number;
- user_id: number;
- ban: boolean;
- remove_data?: boolean;
- reason?: string;
- expires?: number;
- auth?: string;
-}
-
-export interface BanFromCommunityResponse {
- user: UserView;
- banned: boolean;
-}
-
-export interface AddModToCommunityForm {
- community_id: number;
- user_id: number;
- added: boolean;
- auth?: string;
-}
-
-export interface TransferCommunityForm {
- community_id: number;
- user_id: number;
- auth?: string;
-}
-
-export interface TransferSiteForm {
- user_id: number;
- auth?: string;
-}
-
-export interface AddModToCommunityResponse {
- moderators: Array<CommunityUser>;
-}
-
-export interface GetModlogForm {
- mod_user_id?: number;
- community_id?: number;
- page?: number;
- limit?: number;
-}
-
-export interface GetModlogResponse {
- removed_posts: Array<ModRemovePost>;
- locked_posts: Array<ModLockPost>;
- stickied_posts: Array<ModStickyPost>;
- removed_comments: Array<ModRemoveComment>;
- removed_communities: Array<ModRemoveCommunity>;
- banned_from_community: Array<ModBanFromCommunity>;
- banned: Array<ModBan>;
- added_to_community: Array<ModAddCommunity>;
- added: Array<ModAdd>;
-}
-
-export interface ModRemovePost {
- id: number;
- mod_user_id: number;
- post_id: number;
- reason?: string;
- removed?: boolean;
- when_: string;
- mod_user_name: string;
- post_name: string;
- community_id: number;
- community_name: string;
-}
-
-export interface ModLockPost {
- id: number;
- mod_user_id: number;
- post_id: number;
- locked?: boolean;
- when_: string;
- mod_user_name: string;
- post_name: string;
- community_id: number;
- community_name: string;
-}
-
-export interface ModStickyPost {
- id: number;
- mod_user_id: number;
- post_id: number;
- stickied?: boolean;
- when_: string;
- mod_user_name: string;
- post_name: string;
- community_id: number;
- community_name: string;
-}
-
-export interface ModRemoveComment {
- id: number;
- mod_user_id: number;
- comment_id: number;
- reason?: string;
- removed?: boolean;
- when_: string;
- mod_user_name: string;
- comment_user_id: number;
- comment_user_name: string;
- comment_content: string;
- post_id: number;
- post_name: string;
- community_id: number;
- community_name: string;
-}
-
-export interface ModRemoveCommunity {
- id: number;
- mod_user_id: number;
- community_id: number;
- reason?: string;
- removed?: boolean;
- expires?: number;
- when_: string;
- mod_user_name: string;
- community_name: string;
-}
-
-export interface ModBanFromCommunity {
- id: number;
- mod_user_id: number;
- other_user_id: number;
- community_id: number;
- reason?: string;
- banned?: boolean;
- expires?: number;
- when_: string;
- mod_user_name: string;
- other_user_name: string;
- community_name: string;
-}
-
-export interface ModBan {
- id: number;
- mod_user_id: number;
- other_user_id: number;
- reason?: string;
- banned?: boolean;
- expires?: number;
- when_: string;
- mod_user_name: string;
- other_user_name: string;
-}
-
-export interface ModAddCommunity {
- id: number;
- mod_user_id: number;
- other_user_id: number;
- community_id: number;
- removed?: boolean;
- when_: string;
- mod_user_name: string;
- other_user_name: string;
- community_name: string;
-}
-
-export interface ModAdd {
- id: number;
- mod_user_id: number;
- other_user_id: number;
- removed?: boolean;
- when_: string;
- mod_user_name: string;
- other_user_name: string;
-}
-
-export interface LoginForm {
- username_or_email: string;
- password: string;
-}
-
-export interface RegisterForm {
- username: string;
- email?: string;
- password: string;
- password_verify: string;
- admin: boolean;
- show_nsfw: boolean;
- captcha_uuid?: string;
- captcha_answer?: string;
-}
-
-export interface GetCaptchaResponse {
- ok?: {
- png: string;
- wav?: string;
- uuid: string;
- };
-}
-
-export interface LoginResponse {
- jwt: string;
-}
-
-export interface UserSettingsForm {
- show_nsfw: boolean;
- theme: string;
- default_sort_type: SortType;
- default_listing_type: ListingType;
- lang: string;
- avatar?: string;
- banner?: string;
- preferred_username?: string;
- email?: string;
- bio?: string;
- matrix_user_id?: string;
- new_password?: string;
- new_password_verify?: string;
- old_password?: string;
- show_avatars: boolean;
- send_notifications_to_email: boolean;
- auth: string;
-}
-
-export interface CommunityForm {
- name: string;
- edit_id?: number;
- title: string;
- description?: string;
- icon?: string;
- banner?: string;
- category_id: number;
- nsfw: boolean;
- auth?: string;
-}
-
-export interface DeleteCommunityForm {
- edit_id: number;
- deleted: boolean;
- auth?: string;
-}
-
-export interface RemoveCommunityForm {
- edit_id: number;
- removed: boolean;
- reason?: string;
- expires?: number;
- auth?: string;
-}
-
-export interface GetCommunityForm {
- id?: number;
- name?: string;
- auth?: string;
-}
-
-export interface GetCommunityResponse {
- community: Community;
- moderators: Array<CommunityUser>;
- online: number;
-}
-
-export interface CommunityResponse {
- community: Community;
-}
-
-export interface ListCommunitiesForm {
- sort: string;
- page?: number;
- limit?: number;
- auth?: string;
-}
-
-export interface ListCommunitiesResponse {
- communities: Array<Community>;
-}
-
-export interface ListCategoriesResponse {
- categories: Array<Category>;
-}
-
-export interface PostForm {
- name: string;
- url?: string;
- body?: string;
- community_id?: number;
- edit_id?: number;
- nsfw: boolean;
- auth: string;
-}
-
-export interface DeletePostForm {
- edit_id: number;
- deleted: boolean;
- auth: string;
-}
-
-export interface RemovePostForm {
- edit_id: number;
- removed: boolean;
- reason?: string;
- auth: string;
-}
-
-export interface LockPostForm {
- edit_id: number;
- locked: boolean;
- auth: string;
-}
-
-export interface StickyPostForm {
- edit_id: number;
- stickied: boolean;
- auth: string;
-}
-
-export interface PostFormParams {
- name: string;
- url?: string;
- body?: string;
- community?: string;
-}
-
-export interface GetPostForm {
- id: number;
- auth?: string;
-}
-
-export interface GetPostResponse {
- post: Post;
- comments: Array<Comment>;
- community: Community;
- moderators: Array<CommunityUser>;
- online: number;
-}
-
-export interface SavePostForm {
- post_id: number;
- save: boolean;
- auth?: string;
-}
-
-export interface PostResponse {
- post: Post;
-}
-
-export interface CommentForm {
- content: string;
- post_id?: number;
- parent_id?: number;
- edit_id?: number;
- creator_id?: number;
- form_id?: string;
- auth: string;
-}
-
-export interface DeleteCommentForm {
- edit_id: number;
- deleted: boolean;
- auth: string;
-}
-
-export interface RemoveCommentForm {
- edit_id: number;
- removed: boolean;
- reason?: string;
- auth: string;
-}
-
-export interface MarkCommentAsReadForm {
- edit_id: number;
- read: boolean;
- auth: string;
-}
-
-export interface SaveCommentForm {
- comment_id: number;
- save: boolean;
- auth?: string;
-}
-
-export interface CommentResponse {
- comment: Comment;
- recipient_ids: Array<number>;
- form_id?: string;
-}
-
-export interface CommentLikeForm {
- comment_id: number;
- score: number;
- auth?: string;
-}
-
-export interface CommentNode {
- comment: Comment;
- children?: Array<CommentNode>;
-}
-
-export interface GetPostsForm {
- type_: string;
- sort: string;
- page?: number;
- limit?: number;
- community_id?: number;
- auth?: string;
-}
-
-export interface GetPostsResponse {
- posts: Array<Post>;
-}
-
-export interface GetCommentsForm {
- type_: string;
- sort: string;
- page?: number;
- limit: number;
- community_id?: number;
- auth?: string;
-}
-
-export interface GetCommentsResponse {
- comments: Array<Comment>;
-}
-
-export interface CreatePostLikeForm {
- post_id: number;
- score: number;
- auth?: string;
-}
-
-export interface SiteForm {
- name: string;
- description?: string;
- icon?: string;
- banner?: string;
- enable_downvotes: boolean;
- open_registration: boolean;
- enable_nsfw: boolean;
- auth?: string;
-}
-
-export interface GetSiteConfig {
- auth?: string;
-}
-
-export interface GetSiteForm {
- auth?: string;
-}
-
-export interface GetSiteConfigResponse {
- config_hjson: string;
-}
-
-export interface SiteConfigForm {
- config_hjson: string;
- auth?: string;
-}
-
-export interface GetSiteResponse {
- site: Site;
- admins: Array<UserView>;
- banned: Array<UserView>;
- online: number;
- version: string;
- my_user?: User;
- federated_instances: Array<string>;
-}
-
-export interface SiteResponse {
- site: Site;
-}
-
-export interface BanUserForm {
- user_id: number;
- ban: boolean;
- remove_data?: boolean;
- reason?: string;
- expires?: number;
- auth?: string;
-}
-
-export interface BanUserResponse {
- user: UserView;
- banned: boolean;
-}
-
-export interface AddAdminForm {
- user_id: number;
- added: boolean;
- auth?: string;
-}
-
-export interface AddAdminResponse {
- admins: Array<UserView>;
-}
-
-export interface SearchForm {
- q: string;
- type_: string;
- community_id?: number;
- sort: string;
- page?: number;
- limit?: number;
- auth?: string;
-}
-
-export interface SearchResponse {
- type_: string;
- posts?: Array<Post>;
- comments?: Array<Comment>;
- communities: Array<Community>;
- users: Array<UserView>;
-}
-
-export interface DeleteAccountForm {
- password: string;
-}
-
-export interface PasswordResetForm {
- email: string;
-}
-
-// export interface PasswordResetResponse {
-// }
-
-export interface PasswordChangeForm {
- token: string;
- password: string;
- password_verify: string;
-}
-
-export interface PrivateMessageForm {
- content: string;
- recipient_id: number;
- auth?: string;
-}
-
-export interface PrivateMessageFormParams {
- recipient_id: number;
-}
-
-export interface EditPrivateMessageForm {
- edit_id: number;
- content: string;
- auth?: string;
-}
-
-export interface DeletePrivateMessageForm {
- edit_id: number;
- deleted: boolean;
- auth?: string;
-}
-
-export interface MarkPrivateMessageAsReadForm {
- edit_id: number;
- read: boolean;
- auth?: string;
-}
-
-export interface GetPrivateMessagesForm {
- unread_only: boolean;
- page?: number;
- limit?: number;
- auth?: string;
-}
-
-export interface PrivateMessagesResponse {
- messages: Array<PrivateMessage>;
-}
-
-export interface PrivateMessageResponse {
- message: PrivateMessage;
-}
-
-export interface UserJoinForm {
- auth: string;
-}
-
-export interface UserJoinResponse {
- user_id: number;
-}
-
-export type MessageType =
- | LoginForm
- | RegisterForm
- | CommunityForm
- | DeleteCommunityForm
- | RemoveCommunityForm
- | FollowCommunityForm
- | ListCommunitiesForm
- | GetFollowedCommunitiesForm
- | PostForm
- | DeletePostForm
- | RemovePostForm
- | LockPostForm
- | StickyPostForm
- | GetPostForm
- | GetPostsForm
- | GetCommunityForm
- | CommentForm
- | DeleteCommentForm
- | RemoveCommentForm
- | MarkCommentAsReadForm
- | CommentLikeForm
- | SaveCommentForm
- | CreatePostLikeForm
- | BanFromCommunityForm
- | AddAdminForm
- | AddModToCommunityForm
- | TransferCommunityForm
- | TransferSiteForm
- | SaveCommentForm
- | BanUserForm
- | AddAdminForm
- | GetUserDetailsForm
- | GetRepliesForm
- | GetUserMentionsForm
- | MarkUserMentionAsReadForm
- | GetModlogForm
- | SiteForm
- | SearchForm
- | UserSettingsForm
- | DeleteAccountForm
- | PasswordResetForm
- | PasswordChangeForm
- | PrivateMessageForm
- | EditPrivateMessageForm
- | DeletePrivateMessageForm
- | MarkPrivateMessageAsReadForm
- | GetPrivateMessagesForm
- | SiteConfigForm;
-
-type ResponseType =
- | SiteResponse
- | GetFollowedCommunitiesResponse
- | ListCommunitiesResponse
- | GetPostsResponse
- | PostResponse
- | GetRepliesResponse
- | GetUserMentionsResponse
- | ListCategoriesResponse
- | CommunityResponse
- | CommentResponse
- | UserMentionResponse
- | LoginResponse
- | GetCaptchaResponse
- | GetModlogResponse
- | SearchResponse
- | BanFromCommunityResponse
- | AddModToCommunityResponse
- | BanUserResponse
- | AddAdminResponse
- | PrivateMessageResponse
- | PrivateMessagesResponse
- | GetSiteConfigResponse
- | GetSiteResponse;
-
-export interface WebSocketResponse {
- op: UserOperation;
- data: ResponseType;
-}
-
-export interface WebSocketJsonResponse {
- op?: string;
- data?: ResponseType;
- error?: string;
- reconnect?: boolean;
-}
-
export enum UserDetailsView {
Overview,
Comments,
import Cookies from 'js-cookie';
-import { User, Claims, LoginResponse } from '../interfaces';
+import { User, LoginResponse } from 'lemmy-js-client';
import { setTheme } from '../utils';
import jwt_decode from 'jwt-decode';
import { Subject, BehaviorSubject } from 'rxjs';
+interface Claims {
+ id: number;
+ iss: string;
+}
+
export class UserService {
private static _instance: UserService;
public user: User;
import { wsUri } from '../env';
import {
+ LemmyWebsocket,
LoginForm,
RegisterForm,
- UserOperation,
CommunityForm,
DeleteCommunityForm,
RemoveCommunityForm,
GetSiteConfig,
GetSiteForm,
SiteConfigForm,
- MessageType,
+ MarkAllAsReadForm,
WebSocketJsonResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
import { UserService } from './';
import { i18n } from '../i18next';
import { toast } from '../utils';
public admins: Array<UserView>;
public banned: Array<UserView>;
+ private client = new LemmyWebsocket();
private constructor() {
this.ws = new ReconnectingWebSocket(wsUri);
public userJoin() {
let form: UserJoinForm = { auth: UserService.Instance.auth };
- this.ws.send(this.wsSendWrapper(UserOperation.UserJoin, form));
+ this.ws.send(this.client.userJoin(form));
}
- public login(loginForm: LoginForm) {
- this.ws.send(this.wsSendWrapper(UserOperation.Login, loginForm));
+ public login(form: LoginForm) {
+ this.ws.send(this.client.login(form));
}
- public register(registerForm: RegisterForm) {
- this.ws.send(this.wsSendWrapper(UserOperation.Register, registerForm));
+ public register(form: RegisterForm) {
+ this.ws.send(this.client.register(form));
}
public getCaptcha() {
- this.ws.send(this.wsSendWrapper(UserOperation.GetCaptcha, {}));
+ this.ws.send(this.client.getCaptcha());
}
public createCommunity(form: CommunityForm) {
- this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.CreateCommunity, form));
+ this.setAuth(form); // TODO all these setauths at some point would be good to make required
+ this.ws.send(this.client.createCommunity(form));
}
public editCommunity(form: CommunityForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.EditCommunity, form));
+ this.ws.send(this.client.editCommunity(form));
}
public deleteCommunity(form: DeleteCommunityForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.DeleteCommunity, form));
+ this.ws.send(this.client.deleteCommunity(form));
}
public removeCommunity(form: RemoveCommunityForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.RemoveCommunity, form));
+ this.ws.send(this.client.removeCommunity(form));
}
- public followCommunity(followCommunityForm: FollowCommunityForm) {
- this.setAuth(followCommunityForm);
- this.ws.send(
- this.wsSendWrapper(UserOperation.FollowCommunity, followCommunityForm)
- );
+ public followCommunity(form: FollowCommunityForm) {
+ this.setAuth(form);
+ this.ws.send(this.client.followCommunity(form));
}
public listCommunities(form: ListCommunitiesForm) {
this.setAuth(form, false);
- this.ws.send(this.wsSendWrapper(UserOperation.ListCommunities, form));
+ this.ws.send(this.client.listCommunities(form));
}
public getFollowedCommunities() {
let form: GetFollowedCommunitiesForm = { auth: UserService.Instance.auth };
- this.ws.send(
- this.wsSendWrapper(UserOperation.GetFollowedCommunities, form)
- );
+ this.ws.send(this.client.getFollowedCommunities(form));
}
public listCategories() {
- this.ws.send(this.wsSendWrapper(UserOperation.ListCategories, {}));
+ this.ws.send(this.client.listCategories());
}
public createPost(form: PostForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.CreatePost, form));
+ this.ws.send(this.client.createPost(form));
}
public getPost(form: GetPostForm) {
this.setAuth(form, false);
- this.ws.send(this.wsSendWrapper(UserOperation.GetPost, form));
+ this.ws.send(this.client.getPost(form));
}
public getCommunity(form: GetCommunityForm) {
this.setAuth(form, false);
- this.ws.send(this.wsSendWrapper(UserOperation.GetCommunity, form));
+ this.ws.send(this.client.getCommunity(form));
}
public createComment(form: CommentForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.CreateComment, form));
+ this.ws.send(this.client.createComment(form));
}
public editComment(form: CommentForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.EditComment, form));
+ this.ws.send(this.client.editComment(form));
}
public deleteComment(form: DeleteCommentForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.DeleteComment, form));
+ this.ws.send(this.client.deleteComment(form));
}
public removeComment(form: RemoveCommentForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.RemoveComment, form));
+ this.ws.send(this.client.removeComment(form));
}
public markCommentAsRead(form: MarkCommentAsReadForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.MarkCommentAsRead, form));
+ this.ws.send(this.client.markCommentAsRead(form));
}
public likeComment(form: CommentLikeForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.CreateCommentLike, form));
+ this.ws.send(this.client.likeComment(form));
}
public saveComment(form: SaveCommentForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.SaveComment, form));
+ this.ws.send(this.client.saveComment(form));
}
public getPosts(form: GetPostsForm) {
this.setAuth(form, false);
- this.ws.send(this.wsSendWrapper(UserOperation.GetPosts, form));
+ this.ws.send(this.client.getPosts(form));
}
public getComments(form: GetCommentsForm) {
this.setAuth(form, false);
- this.ws.send(this.wsSendWrapper(UserOperation.GetComments, form));
+ this.ws.send(this.client.getComments(form));
}
public likePost(form: CreatePostLikeForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.CreatePostLike, form));
+ this.ws.send(this.client.likePost(form));
}
public editPost(form: PostForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.EditPost, form));
+ this.ws.send(this.client.editPost(form));
}
public deletePost(form: DeletePostForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.DeletePost, form));
+ this.ws.send(this.client.deletePost(form));
}
public removePost(form: RemovePostForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.RemovePost, form));
+ this.ws.send(this.client.removePost(form));
}
public lockPost(form: LockPostForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.LockPost, form));
+ this.ws.send(this.client.lockPost(form));
}
public stickyPost(form: StickyPostForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.StickyPost, form));
+ this.ws.send(this.client.stickyPost(form));
}
public savePost(form: SavePostForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.SavePost, form));
+ this.ws.send(this.client.savePost(form));
}
public banFromCommunity(form: BanFromCommunityForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.BanFromCommunity, form));
+ this.ws.send(this.client.banFromCommunity(form));
}
public addModToCommunity(form: AddModToCommunityForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.AddModToCommunity, form));
+ this.ws.send(this.client.addModToCommunity(form));
}
public transferCommunity(form: TransferCommunityForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.TransferCommunity, form));
+ this.ws.send(this.client.transferCommunity(form));
}
public transferSite(form: TransferSiteForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.TransferSite, form));
+ this.ws.send(this.client.transferSite(form));
}
public banUser(form: BanUserForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.BanUser, form));
+ this.ws.send(this.client.banUser(form));
}
public addAdmin(form: AddAdminForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.AddAdmin, form));
+ this.ws.send(this.client.addAdmin(form));
}
public getUserDetails(form: GetUserDetailsForm) {
this.setAuth(form, false);
- this.ws.send(this.wsSendWrapper(UserOperation.GetUserDetails, form));
+ this.ws.send(this.client.getUserDetails(form));
}
public getReplies(form: GetRepliesForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.GetReplies, form));
+ this.ws.send(this.client.getReplies(form));
}
public getUserMentions(form: GetUserMentionsForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.GetUserMentions, form));
+ this.ws.send(this.client.getUserMentions(form));
}
public markUserMentionAsRead(form: MarkUserMentionAsReadForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.MarkUserMentionAsRead, form));
+ this.ws.send(this.client.markUserMentionAsRead(form));
}
public getModlog(form: GetModlogForm) {
- this.ws.send(this.wsSendWrapper(UserOperation.GetModlog, form));
+ this.ws.send(this.client.getModlog(form));
}
- public createSite(siteForm: SiteForm) {
- this.setAuth(siteForm);
- this.ws.send(this.wsSendWrapper(UserOperation.CreateSite, siteForm));
+ public createSite(form: SiteForm) {
+ this.setAuth(form);
+ this.ws.send(this.client.createSite(form));
}
- public editSite(siteForm: SiteForm) {
- this.setAuth(siteForm);
- this.ws.send(this.wsSendWrapper(UserOperation.EditSite, siteForm));
+ public editSite(form: SiteForm) {
+ this.setAuth(form);
+ this.ws.send(this.client.editSite(form));
}
public getSite(form: GetSiteForm = {}) {
this.setAuth(form, false);
- this.ws.send(this.wsSendWrapper(UserOperation.GetSite, form));
+ this.ws.send(this.client.getSite(form));
}
public getSiteConfig() {
- let siteConfig: GetSiteConfig = {};
- this.setAuth(siteConfig);
- this.ws.send(this.wsSendWrapper(UserOperation.GetSiteConfig, siteConfig));
+ let form: GetSiteConfig = {};
+ this.setAuth(form);
+ this.ws.send(this.client.getSiteConfig(form));
}
public search(form: SearchForm) {
this.setAuth(form, false);
- this.ws.send(this.wsSendWrapper(UserOperation.Search, form));
+ this.ws.send(this.client.search(form));
}
public markAllAsRead() {
- let form = {};
+ let form: MarkAllAsReadForm;
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.MarkAllAsRead, form));
+ this.ws.send(this.client.markAllAsRead(form));
}
- public saveUserSettings(userSettingsForm: UserSettingsForm) {
- this.setAuth(userSettingsForm);
- this.ws.send(
- this.wsSendWrapper(UserOperation.SaveUserSettings, userSettingsForm)
- );
+ public saveUserSettings(form: UserSettingsForm) {
+ this.setAuth(form);
+ this.ws.send(this.client.saveUserSettings(form));
}
public deleteAccount(form: DeleteAccountForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.DeleteAccount, form));
+ this.ws.send(this.client.deleteAccount(form));
}
public passwordReset(form: PasswordResetForm) {
- this.ws.send(this.wsSendWrapper(UserOperation.PasswordReset, form));
+ this.ws.send(this.client.passwordReset(form));
}
public passwordChange(form: PasswordChangeForm) {
- this.ws.send(this.wsSendWrapper(UserOperation.PasswordChange, form));
+ this.ws.send(this.client.passwordChange(form));
}
public createPrivateMessage(form: PrivateMessageForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.CreatePrivateMessage, form));
+ this.ws.send(this.client.createPrivateMessage(form));
}
public editPrivateMessage(form: EditPrivateMessageForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.EditPrivateMessage, form));
+ this.ws.send(this.client.editPrivateMessage(form));
}
public deletePrivateMessage(form: DeletePrivateMessageForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.DeletePrivateMessage, form));
+ this.ws.send(this.client.deletePrivateMessage(form));
}
public markPrivateMessageAsRead(form: MarkPrivateMessageAsReadForm) {
this.setAuth(form);
- this.ws.send(
- this.wsSendWrapper(UserOperation.MarkPrivateMessageAsRead, form)
- );
+ this.ws.send(this.client.markPrivateMessageAsRead(form));
}
public getPrivateMessages(form: GetPrivateMessagesForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.GetPrivateMessages, form));
+ this.ws.send(this.client.getPrivateMessages(form));
}
public saveSiteConfig(form: SiteConfigForm) {
this.setAuth(form);
- this.ws.send(this.wsSendWrapper(UserOperation.SaveSiteConfig, form));
- }
-
- private wsSendWrapper(op: UserOperation, data: MessageType) {
- let send = { op: UserOperation[op], data: data };
- console.log(send);
- return JSON.stringify(send);
+ this.ws.send(this.client.saveSiteConfig(form));
}
private setAuth(obj: any, throwErr: boolean = true) {
PrivateMessage,
User,
SortType,
- CommentSortType,
ListingType,
- DataType,
SearchType,
WebSocketResponse,
WebSocketJsonResponse,
SearchResponse,
CommentResponse,
PostResponse,
-} from './interfaces';
+} from 'lemmy-js-client';
+
+import { CommentSortType, DataType } from './interfaces';
import { UserService, WebSocketService } from './services';
import Tribute from 'tributejs/src/Tribute.js';
}
export function routeSortTypeToEnum(sort: string): SortType {
- if (sort == 'new') {
- return SortType.New;
- } else if (sort == 'hot') {
- return SortType.Hot;
- } else if (sort == 'active') {
- return SortType.Active;
- } else if (sort == 'topday') {
- return SortType.TopDay;
- } else if (sort == 'topweek') {
- return SortType.TopWeek;
- } else if (sort == 'topmonth') {
- return SortType.TopMonth;
- } else if (sort == 'topyear') {
- return SortType.TopYear;
- } else if (sort == 'topall') {
- return SortType.TopAll;
- }
+ return SortType[sort];
}
export function routeListingTypeToEnum(type: string): ListingType {
- return ListingType[capitalizeFirstLetter(type)];
+ return ListingType[type];
}
export function routeDataTypeToEnum(type: string): DataType {
if (text) {
let form: SearchForm = {
q: text,
- type_: SearchType[SearchType.Users],
- sort: SortType[SortType.TopAll],
+ type_: SearchType.Users,
+ sort: SortType.TopAll,
page: 1,
limit: mentionDropdownFetchLimit,
};
if (text) {
let form: SearchForm = {
q: text,
- type_: SearchType[SearchType.Communities],
- sort: SortType[SortType.TopAll],
+ type_: SearchType.Communities,
+ sort: SortType.TopAll,
page: 1,
limit: mentionDropdownFetchLimit,
};
return props.match.params.listing_type
? routeListingTypeToEnum(props.match.params.listing_type)
: UserService.Instance.user
- ? UserService.Instance.user.default_listing_type
+ ? Object.values(ListingType)[UserService.Instance.user.default_listing_type]
: ListingType.All;
}
return props.match.params.sort
? routeSortTypeToEnum(props.match.params.sort)
: UserService.Instance.user
- ? UserService.Instance.user.default_sort_type
+ ? Object.values(SortType)[UserService.Instance.user.default_sort_type]
: SortType.Active;
}
dependencies:
chain-able "^3.0.0"
+lemmy-js-client@^1.0.8:
+ version "1.0.8"
+ resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.8.tgz#98e34c8e3cd07427f883f60fad376dc4d6f46e7f"
+ integrity sha512-YZxD3+8RGz7cRKdI8EIe5iQqQIMm5WzdNz6zZ7/CdkMtXUv6YuMOEv8HLTvBoGuaWIJwlMJ+23NIarxlT26IEw==
+
leven@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2"