2022-06-21 21:42:29 +00:00
|
|
|
import { None, Option, Some } from "@sniptt/monads";
|
2021-02-23 14:58:31 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
2021-09-18 14:27:49 +00:00
|
|
|
import { T } from "inferno-i18next-dess";
|
2021-02-23 14:58:31 +00:00
|
|
|
import { Link } from "inferno-router";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2021-07-17 20:42:55 +00:00
|
|
|
AddAdminResponse,
|
|
|
|
BanPersonResponse,
|
2021-08-20 02:56:18 +00:00
|
|
|
BlockPersonResponse,
|
2021-09-28 10:38:59 +00:00
|
|
|
CommentReportResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
CommentResponse,
|
|
|
|
CommentView,
|
|
|
|
CommunityView,
|
|
|
|
GetComments,
|
|
|
|
GetCommentsResponse,
|
|
|
|
GetPosts,
|
|
|
|
GetPostsResponse,
|
|
|
|
GetSiteResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
ListCommunities,
|
2020-09-06 16:15:25 +00:00
|
|
|
ListCommunitiesResponse,
|
|
|
|
ListingType,
|
2021-09-28 10:38:59 +00:00
|
|
|
PostReportResponse,
|
2020-09-06 16:15:25 +00:00
|
|
|
PostResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
PostView,
|
2021-07-17 20:42:55 +00:00
|
|
|
SiteResponse,
|
|
|
|
SortType,
|
|
|
|
UserOperation,
|
2022-06-21 21:42:29 +00:00
|
|
|
wsJsonToRes,
|
|
|
|
wsUserOp,
|
2021-02-23 14:58:31 +00:00
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { Subscription } from "rxjs";
|
|
|
|
import { i18n } from "../../i18next";
|
|
|
|
import { DataType, InitialFetchRequest } from "../../interfaces";
|
|
|
|
import { UserService, WebSocketService } from "../../services";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2022-06-21 21:42:29 +00:00
|
|
|
auth,
|
2021-07-17 20:42:55 +00:00
|
|
|
commentsToFlatNodes,
|
|
|
|
createCommentLikeRes,
|
|
|
|
createPostLikeFindRes,
|
|
|
|
editCommentRes,
|
|
|
|
editPostFindRes,
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes,
|
|
|
|
enableNsfw,
|
2020-09-06 16:15:25 +00:00
|
|
|
fetchLimit,
|
2021-07-17 20:42:55 +00:00
|
|
|
getDataTypeFromProps,
|
2020-09-06 16:15:25 +00:00
|
|
|
getListingTypeFromProps,
|
|
|
|
getPageFromProps,
|
|
|
|
getSortTypeFromProps,
|
2022-06-21 21:42:29 +00:00
|
|
|
isBrowser,
|
2020-09-06 16:15:25 +00:00
|
|
|
notifyPost,
|
2022-02-24 15:31:44 +00:00
|
|
|
relTags,
|
2021-07-17 20:42:55 +00:00
|
|
|
restoreScrollPosition,
|
|
|
|
saveCommentRes,
|
|
|
|
saveScrollPosition,
|
2020-09-08 04:09:11 +00:00
|
|
|
setIsoData,
|
2021-07-17 20:42:55 +00:00
|
|
|
setupTippy,
|
2021-04-23 21:48:31 +00:00
|
|
|
showLocal,
|
2021-07-17 20:42:55 +00:00
|
|
|
toast,
|
2022-06-21 21:42:29 +00:00
|
|
|
trendingFetchLimit,
|
2021-08-20 02:56:18 +00:00
|
|
|
updatePersonBlock,
|
2021-07-17 20:42:55 +00:00
|
|
|
wsClient,
|
|
|
|
wsSubscribe,
|
|
|
|
} from "../../utils";
|
|
|
|
import { CommentNodes } from "../comment/comment-nodes";
|
|
|
|
import { DataTypeSelect } from "../common/data-type-select";
|
|
|
|
import { HtmlTags } from "../common/html-tags";
|
|
|
|
import { Icon, Spinner } from "../common/icon";
|
|
|
|
import { ListingTypeSelect } from "../common/listing-type-select";
|
|
|
|
import { Paginator } from "../common/paginator";
|
|
|
|
import { SortSelect } from "../common/sort-select";
|
|
|
|
import { CommunityLink } from "../community/community-link";
|
|
|
|
import { PostListings } from "../post/post-listings";
|
2022-04-28 20:42:15 +00:00
|
|
|
import { SiteSidebar } from "./site-sidebar";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2021-07-17 20:42:55 +00:00
|
|
|
interface HomeState {
|
2020-12-24 01:58:27 +00:00
|
|
|
trendingCommunities: CommunityView[];
|
2020-09-06 16:15:25 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2020-12-24 01:58:27 +00:00
|
|
|
posts: PostView[];
|
|
|
|
comments: CommentView[];
|
2020-09-06 16:15:25 +00:00
|
|
|
listingType: ListingType;
|
|
|
|
dataType: DataType;
|
|
|
|
sort: SortType;
|
|
|
|
page: number;
|
2022-06-21 21:42:29 +00:00
|
|
|
showSubscribedMobile: boolean;
|
|
|
|
showTrendingMobile: boolean;
|
|
|
|
showSidebarMobile: boolean;
|
|
|
|
subscribedCollapsed: boolean;
|
|
|
|
loading: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-17 20:42:55 +00:00
|
|
|
interface HomeProps {
|
2020-09-06 16:15:25 +00:00
|
|
|
listingType: ListingType;
|
|
|
|
dataType: DataType;
|
|
|
|
sort: SortType;
|
|
|
|
page: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface UrlParams {
|
|
|
|
listingType?: ListingType;
|
|
|
|
dataType?: string;
|
|
|
|
sort?: SortType;
|
|
|
|
page?: number;
|
|
|
|
}
|
|
|
|
|
2021-07-17 20:42:55 +00:00
|
|
|
export class Home extends Component<any, HomeState> {
|
2022-06-21 21:42:29 +00:00
|
|
|
private isoData = setIsoData(
|
|
|
|
this.context,
|
|
|
|
GetPostsResponse,
|
|
|
|
GetCommentsResponse,
|
|
|
|
ListCommunitiesResponse
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
private subscription: Subscription;
|
2021-07-17 20:42:55 +00:00
|
|
|
private emptyState: HomeState = {
|
2020-09-06 16:15:25 +00:00
|
|
|
trendingCommunities: [],
|
2020-12-24 01:58:27 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2021-07-18 03:56:33 +00:00
|
|
|
showSubscribedMobile: false,
|
|
|
|
showTrendingMobile: false,
|
|
|
|
showSidebarMobile: false,
|
2022-04-15 16:21:57 +00:00
|
|
|
subscribedCollapsed: false,
|
2020-09-06 16:15:25 +00:00
|
|
|
loading: true,
|
|
|
|
posts: [],
|
|
|
|
comments: [],
|
2022-05-23 19:19:14 +00:00
|
|
|
listingType: getListingTypeFromProps(
|
|
|
|
this.props,
|
|
|
|
ListingType[
|
2022-06-21 21:42:29 +00:00
|
|
|
this.isoData.site_res.site_view.unwrap().site.default_post_listing_type
|
2022-05-23 19:19:14 +00:00
|
|
|
]
|
|
|
|
),
|
2020-09-06 16:15:25 +00:00
|
|
|
dataType: getDataTypeFromProps(this.props),
|
|
|
|
sort: getSortTypeFromProps(this.props),
|
|
|
|
page: getPageFromProps(this.props),
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
|
|
|
this.handleSortChange = this.handleSortChange.bind(this);
|
|
|
|
this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
|
|
|
|
this.handleDataTypeChange = this.handleDataTypeChange.bind(this);
|
2021-07-16 19:40:56 +00:00
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-09-08 04:09:11 +00:00
|
|
|
this.parseMessage = this.parseMessage.bind(this);
|
|
|
|
this.subscription = wsSubscribe(this.parseMessage);
|
|
|
|
|
|
|
|
// Only fetch the data if coming from another route
|
|
|
|
if (this.isoData.path == this.context.router.route.match.url) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let postsRes = Some(this.isoData.routeData[0] as GetPostsResponse);
|
|
|
|
let commentsRes = Some(this.isoData.routeData[1] as GetCommentsResponse);
|
|
|
|
let trendingRes = this.isoData.routeData[2] as ListCommunitiesResponse;
|
|
|
|
|
|
|
|
postsRes.match({
|
|
|
|
some: pvs => (this.state.posts = pvs.posts),
|
|
|
|
none: void 0,
|
|
|
|
});
|
|
|
|
commentsRes.match({
|
|
|
|
some: cvs => (this.state.comments = cvs.comments),
|
|
|
|
none: void 0,
|
|
|
|
});
|
|
|
|
this.state.trendingCommunities = trendingRes.communities;
|
|
|
|
|
|
|
|
if (isBrowser()) {
|
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.communityJoin({ community_id: 0 })
|
|
|
|
);
|
2020-09-08 04:09:11 +00:00
|
|
|
}
|
|
|
|
this.state.loading = false;
|
|
|
|
} else {
|
|
|
|
this.fetchTrendingCommunities();
|
|
|
|
this.fetchData();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2020-09-08 04:09:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fetchTrendingCommunities() {
|
2022-06-21 21:42:29 +00:00
|
|
|
let listCommunitiesForm = new ListCommunities({
|
|
|
|
type_: Some(ListingType.Local),
|
|
|
|
sort: Some(SortType.Hot),
|
|
|
|
limit: Some(trendingFetchLimit),
|
|
|
|
page: None,
|
|
|
|
auth: auth(false).ok(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.listCommunities(listCommunitiesForm)
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-13 15:37:23 +00:00
|
|
|
componentDidMount() {
|
2020-09-15 16:44:46 +00:00
|
|
|
// This means it hasn't been set up yet
|
2020-12-24 01:58:27 +00:00
|
|
|
if (!this.state.siteRes.site_view) {
|
2021-02-23 14:58:31 +00:00
|
|
|
this.context.router.history.push("/setup");
|
2020-09-15 16:44:46 +00:00
|
|
|
}
|
2021-11-25 17:40:48 +00:00
|
|
|
setupTippy();
|
2020-09-13 15:37:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
componentWillUnmount() {
|
2021-02-02 18:36:59 +00:00
|
|
|
saveScrollPosition(this.context);
|
|
|
|
this.subscription.unsubscribe();
|
2020-09-08 04:09:11 +00:00
|
|
|
}
|
|
|
|
|
2021-07-17 20:42:55 +00:00
|
|
|
static getDerivedStateFromProps(props: any): HomeProps {
|
2020-09-08 04:09:11 +00:00
|
|
|
return {
|
2022-05-23 19:19:14 +00:00
|
|
|
listingType: getListingTypeFromProps(props, ListingType.Local),
|
2020-09-08 04:09:11 +00:00
|
|
|
dataType: getDataTypeFromProps(props),
|
|
|
|
sort: getSortTypeFromProps(props),
|
|
|
|
page: getPageFromProps(props),
|
|
|
|
};
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 21:56:46 +00:00
|
|
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
2021-02-23 14:58:31 +00:00
|
|
|
let pathSplit = req.path.split("/");
|
2020-09-08 04:09:11 +00:00
|
|
|
let dataType: DataType = pathSplit[3]
|
|
|
|
? DataType[pathSplit[3]]
|
|
|
|
: DataType.Post;
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-09-08 04:09:11 +00:00
|
|
|
// TODO figure out auth default_listingType, default_sort_type
|
2022-06-21 21:42:29 +00:00
|
|
|
let type_: Option<ListingType> = Some(
|
|
|
|
pathSplit[5]
|
|
|
|
? ListingType[pathSplit[5]]
|
|
|
|
: UserService.Instance.myUserInfo.match({
|
|
|
|
some: mui =>
|
|
|
|
Object.values(ListingType)[
|
|
|
|
mui.local_user_view.local_user.default_listing_type
|
|
|
|
],
|
|
|
|
none: ListingType.Local,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
let sort: Option<SortType> = Some(
|
|
|
|
pathSplit[7]
|
|
|
|
? SortType[pathSplit[7]]
|
|
|
|
: UserService.Instance.myUserInfo.match({
|
|
|
|
some: mui =>
|
|
|
|
Object.values(SortType)[
|
|
|
|
mui.local_user_view.local_user.default_sort_type
|
|
|
|
],
|
|
|
|
none: SortType.Active,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
let page = Some(pathSplit[9] ? Number(pathSplit[9]) : 1);
|
2020-09-08 04:09:11 +00:00
|
|
|
|
|
|
|
let promises: Promise<any>[] = [];
|
|
|
|
|
|
|
|
if (dataType == DataType.Post) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let getPostsForm = new GetPosts({
|
|
|
|
community_id: None,
|
|
|
|
community_name: None,
|
|
|
|
type_,
|
2020-09-08 04:09:11 +00:00
|
|
|
page,
|
2022-06-21 21:42:29 +00:00
|
|
|
limit: Some(fetchLimit),
|
2020-09-08 04:09:11 +00:00
|
|
|
sort,
|
2022-06-21 21:42:29 +00:00
|
|
|
saved_only: Some(false),
|
|
|
|
auth: req.auth,
|
|
|
|
});
|
2022-05-23 19:19:14 +00:00
|
|
|
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.getPosts(getPostsForm));
|
2022-06-21 21:42:29 +00:00
|
|
|
promises.push(Promise.resolve());
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2022-06-21 21:42:29 +00:00
|
|
|
let getCommentsForm = new GetComments({
|
|
|
|
community_id: None,
|
|
|
|
community_name: None,
|
2020-09-08 04:09:11 +00:00
|
|
|
page,
|
2022-06-21 21:42:29 +00:00
|
|
|
limit: Some(fetchLimit),
|
2020-09-08 04:09:11 +00:00
|
|
|
sort,
|
2022-06-21 21:42:29 +00:00
|
|
|
type_,
|
|
|
|
saved_only: Some(false),
|
|
|
|
auth: req.auth,
|
|
|
|
});
|
|
|
|
promises.push(Promise.resolve());
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.getComments(getCommentsForm));
|
2020-09-08 04:09:11 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
let trendingCommunitiesForm = new ListCommunities({
|
|
|
|
type_: Some(ListingType.Local),
|
|
|
|
sort: Some(SortType.Hot),
|
|
|
|
limit: Some(trendingFetchLimit),
|
|
|
|
page: None,
|
|
|
|
auth: req.auth,
|
|
|
|
});
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.listCommunities(trendingCommunitiesForm));
|
2020-09-08 04:09:11 +00:00
|
|
|
|
|
|
|
return promises;
|
|
|
|
}
|
|
|
|
|
2021-07-17 20:42:55 +00:00
|
|
|
componentDidUpdate(_: any, lastState: HomeState) {
|
2020-09-08 04:09:11 +00:00
|
|
|
if (
|
|
|
|
lastState.listingType !== this.state.listingType ||
|
|
|
|
lastState.dataType !== this.state.dataType ||
|
|
|
|
lastState.sort !== this.state.sort ||
|
|
|
|
lastState.page !== this.state.page
|
|
|
|
) {
|
|
|
|
this.setState({ loading: true });
|
|
|
|
this.fetchData();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-08 04:09:11 +00:00
|
|
|
get documentTitle(): string {
|
2022-06-21 21:42:29 +00:00
|
|
|
return this.state.siteRes.site_view.match({
|
|
|
|
some: siteView =>
|
|
|
|
siteView.site.description.match({
|
|
|
|
some: desc => `${siteView.site.name} - ${desc}`,
|
|
|
|
none: siteView.site.name,
|
|
|
|
}),
|
|
|
|
none: "Lemmy",
|
|
|
|
});
|
2020-09-08 04:09:11 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div class="container">
|
2020-09-11 18:09:21 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
2022-06-21 21:42:29 +00:00
|
|
|
description={None}
|
|
|
|
image={None}
|
2020-09-11 18:09:21 +00:00
|
|
|
/>
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.state.siteRes.site_view.isSome() && (
|
2020-09-15 16:44:46 +00:00
|
|
|
<div class="row">
|
|
|
|
<main role="main" class="col-12 col-md-8">
|
2021-07-18 03:56:33 +00:00
|
|
|
<div class="d-block d-md-none">{this.mobileView()}</div>
|
2020-09-15 16:44:46 +00:00
|
|
|
{this.posts()}
|
|
|
|
</main>
|
2021-07-18 03:56:33 +00:00
|
|
|
<aside class="d-none d-md-block col-md-4">{this.mySidebar()}</aside>
|
2020-09-15 16:44:46 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
get hasFollows(): boolean {
|
|
|
|
return UserService.Instance.myUserInfo.match({
|
|
|
|
some: mui => mui.follows.length > 0,
|
|
|
|
none: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-18 03:56:33 +00:00
|
|
|
mobileView() {
|
2022-04-28 20:42:15 +00:00
|
|
|
let siteRes = this.state.siteRes;
|
2021-07-18 03:56:33 +00:00
|
|
|
return (
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-12">
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.hasFollows && (
|
|
|
|
<button
|
|
|
|
class="btn btn-secondary d-inline-block mb-2 mr-3"
|
|
|
|
onClick={linkEvent(this, this.handleShowSubscribedMobile)}
|
|
|
|
>
|
|
|
|
{i18n.t("subscribed")}{" "}
|
|
|
|
<Icon
|
|
|
|
icon={
|
|
|
|
this.state.showSubscribedMobile
|
|
|
|
? `minus-square`
|
|
|
|
: `plus-square`
|
|
|
|
}
|
|
|
|
classes="icon-inline"
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
)}
|
2021-07-18 03:56:33 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-secondary d-inline-block mb-2 mr-3"
|
|
|
|
onClick={linkEvent(this, this.handleShowTrendingMobile)}
|
|
|
|
>
|
|
|
|
{i18n.t("trending")}{" "}
|
|
|
|
<Icon
|
|
|
|
icon={
|
|
|
|
this.state.showTrendingMobile ? `minus-square` : `plus-square`
|
|
|
|
}
|
|
|
|
classes="icon-inline"
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-secondary d-inline-block mb-2 mr-3"
|
|
|
|
onClick={linkEvent(this, this.handleShowSidebarMobile)}
|
|
|
|
>
|
|
|
|
{i18n.t("sidebar")}{" "}
|
|
|
|
<Icon
|
|
|
|
icon={
|
|
|
|
this.state.showSidebarMobile ? `minus-square` : `plus-square`
|
|
|
|
}
|
|
|
|
classes="icon-inline"
|
|
|
|
/>
|
|
|
|
</button>
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.state.showSidebarMobile &&
|
|
|
|
siteRes.site_view.match({
|
|
|
|
some: siteView => (
|
|
|
|
<SiteSidebar
|
|
|
|
site={siteView.site}
|
|
|
|
admins={Some(siteRes.admins)}
|
|
|
|
counts={Some(siteView.counts)}
|
|
|
|
online={Some(siteRes.online)}
|
|
|
|
showLocal={showLocal(this.isoData)}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
})}
|
2021-07-18 03:56:33 +00:00
|
|
|
{this.state.showTrendingMobile && (
|
|
|
|
<div class="col-12 card border-secondary mb-3">
|
|
|
|
<div class="card-body">{this.trendingCommunities()}</div>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-04-28 20:42:15 +00:00
|
|
|
{this.state.showSubscribedMobile && (
|
2021-07-18 03:56:33 +00:00
|
|
|
<div class="col-12 card border-secondary mb-3">
|
2022-04-28 20:42:15 +00:00
|
|
|
<div class="card-body">{this.subscribedCommunities()}</div>
|
2021-07-18 03:56:33 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
mySidebar() {
|
2022-04-28 20:42:15 +00:00
|
|
|
let siteRes = this.state.siteRes;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{!this.state.loading && (
|
|
|
|
<div>
|
2020-09-23 23:01:45 +00:00
|
|
|
<div class="card border-secondary mb-3">
|
2020-09-06 16:15:25 +00:00
|
|
|
<div class="card-body">
|
|
|
|
{this.trendingCommunities()}
|
|
|
|
{this.createCommunityButton()}
|
2021-07-19 23:12:08 +00:00
|
|
|
{this.exploreCommunitiesButton()}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-21 21:42:29 +00:00
|
|
|
{siteRes.site_view.match({
|
|
|
|
some: siteView => (
|
|
|
|
<SiteSidebar
|
|
|
|
site={siteView.site}
|
|
|
|
admins={Some(siteRes.admins)}
|
|
|
|
counts={Some(siteView.counts)}
|
|
|
|
online={Some(siteRes.online)}
|
|
|
|
showLocal={showLocal(this.isoData)}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
})}
|
|
|
|
{this.hasFollows && (
|
|
|
|
<div class="card border-secondary mb-3">
|
|
|
|
<div class="card-body">{this.subscribedCommunities()}</div>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
createCommunityButton() {
|
|
|
|
return (
|
2021-07-19 23:12:08 +00:00
|
|
|
<Link className="mt-2 btn btn-secondary btn-block" to="/create_community">
|
2021-02-23 14:58:31 +00:00
|
|
|
{i18n.t("create_a_community")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:12:08 +00:00
|
|
|
exploreCommunitiesButton() {
|
|
|
|
return (
|
|
|
|
<Link className="btn btn-secondary btn-block" to="/communities">
|
|
|
|
{i18n.t("explore_communities")}
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
trendingCommunities() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h5>
|
|
|
|
<T i18nKey="trending_communities">
|
|
|
|
#
|
2020-09-08 04:09:11 +00:00
|
|
|
<Link className="text-body" to="/communities">
|
2020-09-06 16:15:25 +00:00
|
|
|
#
|
|
|
|
</Link>
|
|
|
|
</T>
|
|
|
|
</h5>
|
2021-07-19 23:12:08 +00:00
|
|
|
<ul class="list-inline mb-0">
|
2020-12-24 01:58:27 +00:00
|
|
|
{this.state.trendingCommunities.map(cv => (
|
2021-01-08 05:03:02 +00:00
|
|
|
<li class="list-inline-item d-inline-block">
|
2020-12-24 01:58:27 +00:00
|
|
|
<CommunityLink community={cv.community} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
subscribedCommunities() {
|
|
|
|
return (
|
2020-09-23 23:01:45 +00:00
|
|
|
<div>
|
|
|
|
<h5>
|
2022-04-15 16:21:57 +00:00
|
|
|
<T class="d-inline" i18nKey="subscribed_to_communities">
|
2020-09-23 23:01:45 +00:00
|
|
|
#
|
|
|
|
<Link className="text-body" to="/communities">
|
2020-09-06 16:15:25 +00:00
|
|
|
#
|
2020-09-23 23:01:45 +00:00
|
|
|
</Link>
|
|
|
|
</T>
|
2022-04-15 16:21:57 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-sm text-muted"
|
|
|
|
onClick={linkEvent(this, this.handleCollapseSubscribe)}
|
|
|
|
aria-label={i18n.t("collapse")}
|
|
|
|
data-tippy-content={i18n.t("collapse")}
|
|
|
|
>
|
|
|
|
{this.state.subscribedCollapsed ? (
|
|
|
|
<Icon icon="plus-square" classes="icon-inline" />
|
|
|
|
) : (
|
|
|
|
<Icon icon="minus-square" classes="icon-inline" />
|
|
|
|
)}
|
|
|
|
</button>
|
2020-09-23 23:01:45 +00:00
|
|
|
</h5>
|
2022-04-15 16:21:57 +00:00
|
|
|
{!this.state.subscribedCollapsed && (
|
|
|
|
<ul class="list-inline mb-0">
|
2022-06-21 21:42:29 +00:00
|
|
|
{UserService.Instance.myUserInfo
|
|
|
|
.map(m => m.follows)
|
|
|
|
.unwrapOr([])
|
|
|
|
.map(cfv => (
|
|
|
|
<li class="list-inline-item d-inline-block">
|
|
|
|
<CommunityLink community={cfv.community} />
|
|
|
|
</li>
|
|
|
|
))}
|
2022-04-15 16:21:57 +00:00
|
|
|
</ul>
|
|
|
|
)}
|
2020-09-23 23:01:45 +00:00
|
|
|
</div>
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateUrl(paramUpdates: UrlParams) {
|
|
|
|
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}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
posts() {
|
|
|
|
return (
|
|
|
|
<div class="main-content-wrapper">
|
|
|
|
{this.state.loading ? (
|
|
|
|
<h5>
|
2021-07-17 20:21:31 +00:00
|
|
|
<Spinner large />
|
2020-09-06 16:15:25 +00:00
|
|
|
</h5>
|
|
|
|
) : (
|
|
|
|
<div>
|
|
|
|
{this.selects()}
|
|
|
|
{this.listings()}
|
2021-07-16 19:40:56 +00:00
|
|
|
<Paginator
|
|
|
|
page={this.state.page}
|
|
|
|
onChange={this.handlePageChange}
|
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
listings() {
|
|
|
|
return this.state.dataType == DataType.Post ? (
|
|
|
|
<PostListings
|
|
|
|
posts={this.state.posts}
|
|
|
|
showCommunity
|
|
|
|
removeDuplicates
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes={enableDownvotes(this.state.siteRes)}
|
|
|
|
enableNsfw={enableNsfw(this.state.siteRes)}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<CommentNodes
|
|
|
|
nodes={commentsToFlatNodes(this.state.comments)}
|
2022-06-21 21:42:29 +00:00
|
|
|
moderators={None}
|
|
|
|
admins={None}
|
|
|
|
maxCommentsShown={None}
|
2020-09-06 16:15:25 +00:00
|
|
|
noIndent
|
|
|
|
showCommunity
|
|
|
|
showContext
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes={enableDownvotes(this.state.siteRes)}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
selects() {
|
2022-01-25 03:24:32 +00:00
|
|
|
let allRss = `/feeds/all.xml?sort=${this.state.sort}`;
|
|
|
|
let localRss = `/feeds/local.xml?sort=${this.state.sort}`;
|
2022-06-21 21:42:29 +00:00
|
|
|
let frontRss = auth(false)
|
|
|
|
.ok()
|
|
|
|
.map(auth => `/feeds/front/${auth}.xml?sort=${this.state.sort}`);
|
2022-01-25 03:24:32 +00:00
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<div className="mb-3">
|
|
|
|
<span class="mr-3">
|
|
|
|
<DataTypeSelect
|
|
|
|
type_={this.state.dataType}
|
|
|
|
onChange={this.handleDataTypeChange}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
<span class="mr-3">
|
|
|
|
<ListingTypeSelect
|
|
|
|
type_={this.state.listingType}
|
2021-04-23 21:48:31 +00:00
|
|
|
showLocal={showLocal(this.isoData)}
|
2022-05-23 19:19:14 +00:00
|
|
|
showSubscribed
|
2020-09-06 16:15:25 +00:00
|
|
|
onChange={this.handleListingTypeChange}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
<span class="mr-2">
|
|
|
|
<SortSelect sort={this.state.sort} onChange={this.handleSortChange} />
|
|
|
|
</span>
|
|
|
|
{this.state.listingType == ListingType.All && (
|
2022-01-25 03:24:32 +00:00
|
|
|
<>
|
2022-02-24 15:31:44 +00:00
|
|
|
<a href={allRss} rel={relTags} title="RSS">
|
2022-01-25 03:24:32 +00:00
|
|
|
<Icon icon="rss" classes="text-muted small" />
|
|
|
|
</a>
|
|
|
|
<link rel="alternate" type="application/atom+xml" href={allRss} />
|
|
|
|
</>
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2020-11-25 20:19:42 +00:00
|
|
|
{this.state.listingType == ListingType.Local && (
|
2022-01-25 03:24:32 +00:00
|
|
|
<>
|
2022-02-24 15:31:44 +00:00
|
|
|
<a href={localRss} rel={relTags} title="RSS">
|
2022-01-25 03:24:32 +00:00
|
|
|
<Icon icon="rss" classes="text-muted small" />
|
|
|
|
</a>
|
|
|
|
<link rel="alternate" type="application/atom+xml" href={localRss} />
|
|
|
|
</>
|
2020-11-25 20:19:42 +00:00
|
|
|
)}
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.state.listingType == ListingType.Subscribed &&
|
|
|
|
frontRss.match({
|
|
|
|
some: rss => (
|
|
|
|
<>
|
|
|
|
<a href={rss} title="RSS" rel={relTags}>
|
|
|
|
<Icon icon="rss" classes="text-muted small" />
|
|
|
|
</a>
|
|
|
|
<link rel="alternate" type="application/atom+xml" href={rss} />
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
})}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-18 03:56:33 +00:00
|
|
|
handleShowSubscribedMobile(i: Home) {
|
|
|
|
i.state.showSubscribedMobile = !i.state.showSubscribedMobile;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleShowTrendingMobile(i: Home) {
|
|
|
|
i.state.showTrendingMobile = !i.state.showTrendingMobile;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleShowSidebarMobile(i: Home) {
|
|
|
|
i.state.showSidebarMobile = !i.state.showSidebarMobile;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2022-04-15 16:21:57 +00:00
|
|
|
handleCollapseSubscribe(i: Home) {
|
|
|
|
i.state.subscribedCollapsed = !i.state.subscribedCollapsed;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2021-07-16 19:40:56 +00:00
|
|
|
handlePageChange(page: number) {
|
|
|
|
this.updateUrl({ page });
|
2020-09-06 16:15:25 +00:00
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSortChange(val: SortType) {
|
|
|
|
this.updateUrl({ sort: val, page: 1 });
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleListingTypeChange(val: ListingType) {
|
|
|
|
this.updateUrl({ listingType: val, page: 1 });
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDataTypeChange(val: DataType) {
|
|
|
|
this.updateUrl({ dataType: DataType[val], page: 1 });
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchData() {
|
|
|
|
if (this.state.dataType == DataType.Post) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let getPostsForm = new GetPosts({
|
|
|
|
community_id: None,
|
|
|
|
community_name: None,
|
|
|
|
page: Some(this.state.page),
|
|
|
|
limit: Some(fetchLimit),
|
|
|
|
sort: Some(this.state.sort),
|
|
|
|
saved_only: Some(false),
|
|
|
|
auth: auth(false).ok(),
|
|
|
|
type_: Some(this.state.listingType),
|
|
|
|
});
|
2022-05-23 19:19:14 +00:00
|
|
|
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.getPosts(getPostsForm));
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2022-06-21 21:42:29 +00:00
|
|
|
let getCommentsForm = new GetComments({
|
|
|
|
community_id: None,
|
|
|
|
community_name: None,
|
|
|
|
page: Some(this.state.page),
|
|
|
|
limit: Some(fetchLimit),
|
|
|
|
sort: Some(this.state.sort),
|
|
|
|
saved_only: Some(false),
|
|
|
|
auth: auth(false).ok(),
|
|
|
|
type_: Some(this.state.listingType),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.getComments(getCommentsForm));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
parseMessage(msg: any) {
|
|
|
|
let op = wsUserOp(msg);
|
2021-04-07 15:54:38 +00:00
|
|
|
console.log(msg);
|
2020-09-06 16:15:25 +00:00
|
|
|
if (msg.error) {
|
2021-02-23 14:58:31 +00:00
|
|
|
toast(i18n.t(msg.error), "danger");
|
2020-09-06 16:15:25 +00:00
|
|
|
return;
|
|
|
|
} else if (msg.reconnect) {
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.communityJoin({ community_id: 0 })
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.fetchData();
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.ListCommunities) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<ListCommunitiesResponse>(
|
|
|
|
msg,
|
|
|
|
ListCommunitiesResponse
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.trendingCommunities = data.communities;
|
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.EditSite) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<SiteResponse>(msg, SiteResponse);
|
|
|
|
this.state.siteRes.site_view = Some(data.site_view);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2021-02-23 14:58:31 +00:00
|
|
|
toast(i18n.t("site_saved"));
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.GetPosts) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<GetPostsResponse>(msg, GetPostsResponse);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.posts = data.posts;
|
|
|
|
this.state.loading = false;
|
|
|
|
this.setState(this.state);
|
2022-06-21 21:42:29 +00:00
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.communityJoin({ community_id: 0 })
|
|
|
|
);
|
2021-02-02 18:36:59 +00:00
|
|
|
restoreScrollPosition(this.context);
|
2020-09-06 16:15:25 +00:00
|
|
|
setupTippy();
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreatePost) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
|
2021-01-24 05:56:00 +00:00
|
|
|
// NSFW check
|
|
|
|
let nsfw = data.post_view.post.nsfw || data.post_view.community.nsfw;
|
|
|
|
let nsfwCheck =
|
|
|
|
!nsfw ||
|
|
|
|
(nsfw &&
|
2022-06-21 21:42:29 +00:00
|
|
|
UserService.Instance.myUserInfo
|
|
|
|
.map(m => m.local_user_view.local_user.show_nsfw)
|
|
|
|
.unwrapOr(false));
|
|
|
|
|
|
|
|
let showPostNotifs = UserService.Instance.myUserInfo
|
|
|
|
.map(m => m.local_user_view.local_user.show_new_post_notifs)
|
|
|
|
.unwrapOr(false);
|
2021-01-24 05:56:00 +00:00
|
|
|
|
|
|
|
// Only push these if you're on the first page, and you pass the nsfw check
|
|
|
|
if (this.state.page == 1 && nsfwCheck) {
|
|
|
|
// If you're on subscribed, only push it if you're subscribed.
|
|
|
|
if (this.state.listingType == ListingType.Subscribed) {
|
|
|
|
if (
|
2022-06-21 21:42:29 +00:00
|
|
|
UserService.Instance.myUserInfo
|
|
|
|
.map(m => m.follows)
|
|
|
|
.unwrapOr([])
|
2021-01-24 05:56:00 +00:00
|
|
|
.map(c => c.community.id)
|
|
|
|
.includes(data.post_view.community.id)
|
|
|
|
) {
|
|
|
|
this.state.posts.unshift(data.post_view);
|
2022-06-21 21:42:29 +00:00
|
|
|
if (showPostNotifs) {
|
2021-07-22 20:18:13 +00:00
|
|
|
notifyPost(data.post_view, this.context.router);
|
|
|
|
}
|
2021-01-24 05:56:00 +00:00
|
|
|
}
|
|
|
|
} else if (this.state.listingType == ListingType.Local) {
|
|
|
|
// If you're on the local view, only push it if its local
|
|
|
|
if (data.post_view.post.local) {
|
|
|
|
this.state.posts.unshift(data.post_view);
|
2022-06-21 21:42:29 +00:00
|
|
|
if (showPostNotifs) {
|
2021-07-22 20:18:13 +00:00
|
|
|
notifyPost(data.post_view, this.context.router);
|
|
|
|
}
|
2021-01-24 05:56:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-12-24 01:58:27 +00:00
|
|
|
this.state.posts.unshift(data.post_view);
|
2022-06-21 21:42:29 +00:00
|
|
|
if (showPostNotifs) {
|
2021-07-22 20:18:13 +00:00
|
|
|
notifyPost(data.post_view, this.context.router);
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2021-01-24 05:56:00 +00:00
|
|
|
this.setState(this.state);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2020-09-25 21:16:41 +00:00
|
|
|
} else if (
|
2020-12-24 01:58:27 +00:00
|
|
|
op == UserOperation.EditPost ||
|
|
|
|
op == UserOperation.DeletePost ||
|
|
|
|
op == UserOperation.RemovePost ||
|
|
|
|
op == UserOperation.LockPost ||
|
|
|
|
op == UserOperation.StickyPost ||
|
|
|
|
op == UserOperation.SavePost
|
2020-09-25 21:16:41 +00:00
|
|
|
) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
editPostFindRes(data.post_view, this.state.posts);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreatePostLike) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
createPostLikeFindRes(data.post_view, this.state.posts);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.AddAdmin) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<AddAdminResponse>(msg, AddAdminResponse);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.siteRes.admins = data.admins;
|
|
|
|
this.setState(this.state);
|
2021-03-15 18:09:31 +00:00
|
|
|
} else if (op == UserOperation.BanPerson) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<BanPersonResponse>(msg, BanPersonResponse);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.posts
|
2021-03-15 18:09:31 +00:00
|
|
|
.filter(p => p.creator.id == data.person_view.person.id)
|
2020-12-24 01:58:27 +00:00
|
|
|
.forEach(p => (p.creator.banned = data.banned));
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.GetComments) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<GetCommentsResponse>(msg, GetCommentsResponse);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.comments = data.comments;
|
|
|
|
this.state.loading = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
} else if (
|
2020-12-24 01:58:27 +00:00
|
|
|
op == UserOperation.EditComment ||
|
|
|
|
op == UserOperation.DeleteComment ||
|
|
|
|
op == UserOperation.RemoveComment
|
2020-09-06 16:15:25 +00:00
|
|
|
) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
editCommentRes(data.comment_view, this.state.comments);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreateComment) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
// Necessary since it might be a user reply
|
2021-01-07 18:55:09 +00:00
|
|
|
if (data.form_id) {
|
2020-09-06 16:15:25 +00:00
|
|
|
// If you're on subscribed, only push it if you're subscribed.
|
|
|
|
if (this.state.listingType == ListingType.Subscribed) {
|
|
|
|
if (
|
2022-06-21 21:42:29 +00:00
|
|
|
UserService.Instance.myUserInfo
|
|
|
|
.map(m => m.follows)
|
|
|
|
.unwrapOr([])
|
2020-12-24 01:58:27 +00:00
|
|
|
.map(c => c.community.id)
|
|
|
|
.includes(data.comment_view.community.id)
|
2020-09-06 16:15:25 +00:00
|
|
|
) {
|
2020-12-24 01:58:27 +00:00
|
|
|
this.state.comments.unshift(data.comment_view);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-12-24 01:58:27 +00:00
|
|
|
this.state.comments.unshift(data.comment_view);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.SaveComment) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
saveCommentRes(data.comment_view, this.state.comments);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreateCommentLike) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
createCommentLikeRes(data.comment_view, this.state.comments);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2021-08-20 02:56:18 +00:00
|
|
|
} else if (op == UserOperation.BlockPerson) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<BlockPersonResponse>(msg, BlockPersonResponse);
|
2021-08-20 02:56:18 +00:00
|
|
|
updatePersonBlock(data);
|
2021-09-28 10:38:59 +00:00
|
|
|
} else if (op == UserOperation.CreatePostReport) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PostReportResponse>(msg, PostReportResponse);
|
2021-09-28 10:38:59 +00:00
|
|
|
if (data) {
|
|
|
|
toast(i18n.t("report_created"));
|
|
|
|
}
|
|
|
|
} else if (op == UserOperation.CreateCommentReport) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentReportResponse>(msg, CommentReportResponse);
|
2021-09-28 10:38:59 +00:00
|
|
|
if (data) {
|
|
|
|
toast(i18n.t("report_created"));
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|