2022-06-21 21:42:29 +00:00
|
|
|
import { None, Option, Some } from "@sniptt/monads";
|
2022-01-12 00:53:23 +00:00
|
|
|
import classNames from "classnames";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
|
|
|
import { Link } from "inferno-router";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2021-07-17 20:42:55 +00:00
|
|
|
AddAdmin,
|
|
|
|
AddModToCommunity,
|
|
|
|
BanFromCommunity,
|
|
|
|
BanPerson,
|
2021-08-20 02:56:18 +00:00
|
|
|
BlockPerson,
|
2021-07-17 20:42:55 +00:00
|
|
|
CommunityModeratorView,
|
2020-12-24 01:58:27 +00:00
|
|
|
CreatePostLike,
|
2021-09-28 10:38:59 +00:00
|
|
|
CreatePostReport,
|
2020-12-24 01:58:27 +00:00
|
|
|
DeletePost,
|
2022-09-22 15:14:58 +00:00
|
|
|
Language,
|
2020-12-24 01:58:27 +00:00
|
|
|
LockPost,
|
2021-03-15 18:09:31 +00:00
|
|
|
PersonViewSafe,
|
2021-07-17 20:42:55 +00:00
|
|
|
PostView,
|
2022-06-23 19:44:05 +00:00
|
|
|
PurgePerson,
|
|
|
|
PurgePost,
|
2021-07-17 20:42:55 +00:00
|
|
|
RemovePost,
|
|
|
|
SavePost,
|
|
|
|
StickyPost,
|
2022-06-21 21:42:29 +00:00
|
|
|
toUndefined,
|
2020-12-24 01:58:27 +00:00
|
|
|
TransferCommunity,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { externalHost } from "../../env";
|
|
|
|
import { i18n } from "../../i18next";
|
2022-06-23 19:44:05 +00:00
|
|
|
import { BanType, PurgeType } from "../../interfaces";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { UserService, WebSocketService } from "../../services";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2022-06-21 21:42:29 +00:00
|
|
|
amCommunityCreator,
|
|
|
|
auth,
|
|
|
|
canAdmin,
|
2020-09-06 16:15:25 +00:00
|
|
|
canMod,
|
2022-01-09 17:53:11 +00:00
|
|
|
futureDaysToUnixTime,
|
2020-09-06 16:15:25 +00:00
|
|
|
hostname,
|
2022-06-21 21:42:29 +00:00
|
|
|
isAdmin,
|
2022-01-09 17:53:11 +00:00
|
|
|
isBanned,
|
2021-07-17 20:42:55 +00:00
|
|
|
isImage,
|
|
|
|
isMod,
|
|
|
|
isVideo,
|
2022-11-19 02:02:38 +00:00
|
|
|
mdNoImages,
|
2021-07-17 20:42:55 +00:00
|
|
|
mdToHtml,
|
2022-11-18 02:01:52 +00:00
|
|
|
mdToHtmlInline,
|
2021-09-18 16:35:49 +00:00
|
|
|
numToSI,
|
2022-02-24 15:31:44 +00:00
|
|
|
relTags,
|
2021-07-17 20:42:55 +00:00
|
|
|
setupTippy,
|
2021-04-09 16:23:30 +00:00
|
|
|
showScores,
|
2021-07-17 20:42:55 +00:00
|
|
|
wsClient,
|
|
|
|
} from "../../utils";
|
2022-06-23 19:44:05 +00:00
|
|
|
import { Icon, PurgeWarning, Spinner } from "../common/icon";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { MomentTime } from "../common/moment-time";
|
|
|
|
import { PictrsImage } from "../common/pictrs-image";
|
|
|
|
import { CommunityLink } from "../community/community-link";
|
|
|
|
import { PersonListing } from "../person/person-listing";
|
2021-08-19 15:24:13 +00:00
|
|
|
import { MetadataCard } from "./metadata-card";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { PostForm } from "./post-form";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface PostListingState {
|
|
|
|
showEdit: boolean;
|
|
|
|
showRemoveDialog: boolean;
|
2022-06-23 19:44:05 +00:00
|
|
|
showPurgeDialog: boolean;
|
|
|
|
purgeReason: Option<string>;
|
|
|
|
purgeType: PurgeType;
|
|
|
|
purgeLoading: boolean;
|
2022-06-21 21:42:29 +00:00
|
|
|
removeReason: Option<string>;
|
2020-09-06 16:15:25 +00:00
|
|
|
showBanDialog: boolean;
|
2022-06-21 21:42:29 +00:00
|
|
|
banReason: Option<string>;
|
|
|
|
banExpireDays: Option<number>;
|
2020-09-06 16:15:25 +00:00
|
|
|
banType: BanType;
|
2022-04-15 21:22:39 +00:00
|
|
|
removeData: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
showConfirmTransferSite: boolean;
|
|
|
|
showConfirmTransferCommunity: boolean;
|
|
|
|
imageExpanded: boolean;
|
|
|
|
viewSource: boolean;
|
|
|
|
showAdvanced: boolean;
|
2020-09-26 16:18:49 +00:00
|
|
|
showMoreMobile: boolean;
|
2021-03-25 16:44:16 +00:00
|
|
|
showBody: boolean;
|
2021-09-28 10:38:59 +00:00
|
|
|
showReportDialog: boolean;
|
2022-06-21 21:42:29 +00:00
|
|
|
reportReason: Option<string>;
|
|
|
|
my_vote: Option<number>;
|
2020-09-06 16:15:25 +00:00
|
|
|
score: number;
|
|
|
|
upvotes: number;
|
|
|
|
downvotes: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface PostListingProps {
|
2020-12-24 01:58:27 +00:00
|
|
|
post_view: PostView;
|
2022-06-21 21:42:29 +00:00
|
|
|
duplicates: Option<PostView[]>;
|
|
|
|
moderators: Option<CommunityModeratorView[]>;
|
|
|
|
admins: Option<PersonViewSafe[]>;
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages: Language[];
|
2020-09-06 16:15:25 +00:00
|
|
|
showCommunity?: boolean;
|
|
|
|
showBody?: boolean;
|
2022-11-18 02:11:30 +00:00
|
|
|
hideImage?: boolean;
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes?: boolean;
|
|
|
|
enableNsfw?: boolean;
|
2022-02-02 14:56:43 +00:00
|
|
|
viewOnly?: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class PostListing extends Component<PostListingProps, PostListingState> {
|
|
|
|
private emptyState: PostListingState = {
|
|
|
|
showEdit: false,
|
|
|
|
showRemoveDialog: false,
|
2022-06-23 19:44:05 +00:00
|
|
|
showPurgeDialog: false,
|
|
|
|
purgeReason: None,
|
|
|
|
purgeType: PurgeType.Person,
|
|
|
|
purgeLoading: false,
|
2022-06-21 21:42:29 +00:00
|
|
|
removeReason: None,
|
2020-09-06 16:15:25 +00:00
|
|
|
showBanDialog: false,
|
2022-06-21 21:42:29 +00:00
|
|
|
banReason: None,
|
|
|
|
banExpireDays: None,
|
2020-09-06 16:15:25 +00:00
|
|
|
banType: BanType.Community,
|
2022-04-15 21:22:39 +00:00
|
|
|
removeData: false,
|
2020-09-06 16:15:25 +00:00
|
|
|
showConfirmTransferSite: false,
|
|
|
|
showConfirmTransferCommunity: false,
|
|
|
|
imageExpanded: false,
|
|
|
|
viewSource: false,
|
|
|
|
showAdvanced: false,
|
2020-09-26 16:18:49 +00:00
|
|
|
showMoreMobile: false,
|
2021-03-25 16:44:16 +00:00
|
|
|
showBody: false,
|
2021-09-28 10:38:59 +00:00
|
|
|
showReportDialog: false,
|
2022-06-21 21:42:29 +00:00
|
|
|
reportReason: None,
|
2020-12-24 01:58:27 +00:00
|
|
|
my_vote: this.props.post_view.my_vote,
|
|
|
|
score: this.props.post_view.counts.score,
|
|
|
|
upvotes: this.props.post_view.counts.upvotes,
|
|
|
|
downvotes: this.props.post_view.counts.downvotes,
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
|
|
|
this.handlePostLike = this.handlePostLike.bind(this);
|
|
|
|
this.handlePostDisLike = this.handlePostDisLike.bind(this);
|
|
|
|
this.handleEditPost = this.handleEditPost.bind(this);
|
|
|
|
this.handleEditCancel = this.handleEditCancel.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps: PostListingProps) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
|
|
|
my_vote: nextProps.post_view.my_vote,
|
|
|
|
upvotes: nextProps.post_view.counts.upvotes,
|
|
|
|
downvotes: nextProps.post_view.counts.downvotes,
|
|
|
|
score: nextProps.post_view.counts.score,
|
|
|
|
});
|
2020-12-24 01:58:27 +00:00
|
|
|
if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ imageExpanded: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2022-01-12 00:53:23 +00:00
|
|
|
let post = this.props.post_view.post;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="post-listing">
|
2020-09-06 16:15:25 +00:00
|
|
|
{!this.state.showEdit ? (
|
|
|
|
<>
|
|
|
|
{this.listing()}
|
2022-11-18 02:11:30 +00:00
|
|
|
{this.state.imageExpanded && !this.props.hideImage && this.img}
|
2022-06-21 21:42:29 +00:00
|
|
|
{post.url.isSome() &&
|
|
|
|
this.showBody &&
|
|
|
|
post.embed_title.isSome() && <MetadataCard post={post} />}
|
|
|
|
{this.showBody && this.body()}
|
2020-09-06 16:15:25 +00:00
|
|
|
</>
|
|
|
|
) : (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="col-12">
|
2020-09-06 16:15:25 +00:00
|
|
|
<PostForm
|
2022-06-21 21:42:29 +00:00
|
|
|
post_view={Some(this.props.post_view)}
|
|
|
|
communities={None}
|
|
|
|
params={None}
|
2020-09-06 16:15:25 +00:00
|
|
|
onEdit={this.handleEditPost}
|
|
|
|
onCancel={this.handleEditCancel}
|
|
|
|
enableNsfw={this.props.enableNsfw}
|
|
|
|
enableDownvotes={this.props.enableDownvotes}
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.props.allLanguages}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
body() {
|
2022-06-21 21:42:29 +00:00
|
|
|
return this.props.post_view.post.body.match({
|
|
|
|
some: body => (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="col-12 card my-2 p-2">
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.state.viewSource ? (
|
|
|
|
<pre>{body}</pre>
|
|
|
|
) : (
|
|
|
|
<div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-01-12 00:53:23 +00:00
|
|
|
get img() {
|
2022-06-21 21:42:29 +00:00
|
|
|
return this.imageSrc.match({
|
|
|
|
some: src => (
|
|
|
|
<>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="offset-sm-3 my-2 d-none d-sm-block">
|
|
|
|
<a href={src} className="d-inline-block">
|
2022-06-21 21:42:29 +00:00
|
|
|
<PictrsImage src={src} />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div className="my-2 d-block d-sm-none">
|
|
|
|
<a
|
2022-09-22 15:03:35 +00:00
|
|
|
className="d-inline-block"
|
2022-06-21 21:42:29 +00:00
|
|
|
onClick={linkEvent(this, this.handleImageExpandClick)}
|
|
|
|
>
|
|
|
|
<PictrsImage src={src} />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
});
|
2022-01-12 00:53:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
imgThumb(src: string) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let post_view = this.props.post_view;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2020-10-14 19:36:37 +00:00
|
|
|
<PictrsImage
|
2020-09-06 16:15:25 +00:00
|
|
|
src={src}
|
2020-10-14 19:36:37 +00:00
|
|
|
thumbnail
|
2021-02-06 20:20:41 +00:00
|
|
|
alt=""
|
2020-12-24 01:58:27 +00:00
|
|
|
nsfw={post_view.post.nsfw || post_view.community.nsfw}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
get imageSrc(): Option<string> {
|
2020-12-24 01:58:27 +00:00
|
|
|
let post = this.props.post_view.post;
|
2022-06-21 21:42:29 +00:00
|
|
|
let url = post.url;
|
|
|
|
let thumbnail = post.thumbnail_url;
|
|
|
|
|
|
|
|
if (url.isSome() && isImage(url.unwrap())) {
|
|
|
|
if (url.unwrap().includes("pictrs")) {
|
|
|
|
return url;
|
|
|
|
} else if (thumbnail.isSome()) {
|
|
|
|
return thumbnail;
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2022-06-21 21:42:29 +00:00
|
|
|
return url;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2022-06-21 21:42:29 +00:00
|
|
|
} else if (thumbnail.isSome()) {
|
|
|
|
return thumbnail;
|
2020-09-09 00:48:17 +00:00
|
|
|
} else {
|
2022-06-21 21:42:29 +00:00
|
|
|
return None;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
thumbnail() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let post = this.props.post_view.post;
|
2022-06-21 21:42:29 +00:00
|
|
|
let url = post.url;
|
|
|
|
let thumbnail = post.thumbnail_url;
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-11-18 02:11:30 +00:00
|
|
|
if (!this.props.hideImage && url.isSome() && isImage(url.unwrap())) {
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2021-09-19 20:29:03 +00:00
|
|
|
<a
|
2022-06-21 21:42:29 +00:00
|
|
|
href={this.imageSrc.unwrap()}
|
2022-09-22 15:03:35 +00:00
|
|
|
className="text-body d-inline-block position-relative mb-2"
|
2021-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={i18n.t("expand_here")}
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(this, this.handleImageExpandClick)}
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("expand_here")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.imgThumb(this.imageSrc.unwrap())}
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="image" classes="mini-overlay" />
|
2021-09-19 20:29:03 +00:00
|
|
|
</a>
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
2022-11-18 02:11:30 +00:00
|
|
|
} else if (!this.props.hideImage && url.isSome() && thumbnail.isSome()) {
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<a
|
2022-09-22 15:03:35 +00:00
|
|
|
className="text-body d-inline-block position-relative mb-2"
|
2022-06-21 21:42:29 +00:00
|
|
|
href={url.unwrap()}
|
2022-02-24 15:31:44 +00:00
|
|
|
rel={relTags}
|
2022-06-21 21:42:29 +00:00
|
|
|
title={url.unwrap()}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.imgThumb(this.imageSrc.unwrap())}
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="external-link" classes="mini-overlay" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</a>
|
|
|
|
);
|
2022-06-21 21:42:29 +00:00
|
|
|
} else if (url.isSome()) {
|
2022-11-18 02:11:30 +00:00
|
|
|
if (!this.props.hideImage && isVideo(url.unwrap())) {
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="embed-responsive embed-responsive-16by9">
|
2020-09-06 16:15:25 +00:00
|
|
|
<video
|
2022-09-22 15:03:35 +00:00
|
|
|
playsInline
|
2020-09-06 16:15:25 +00:00
|
|
|
muted
|
|
|
|
loop
|
|
|
|
controls
|
2022-09-22 15:03:35 +00:00
|
|
|
className="embed-responsive-item"
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2022-06-21 21:42:29 +00:00
|
|
|
<source src={url.unwrap()} type="video/mp4" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</video>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<a
|
|
|
|
className="text-body"
|
2022-06-21 21:42:29 +00:00
|
|
|
href={url.unwrap()}
|
|
|
|
title={url.unwrap()}
|
2022-02-24 15:31:44 +00:00
|
|
|
rel={relTags}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="thumbnail rounded bg-light d-flex justify-content-center">
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="external-link" classes="d-flex align-items-center" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<Link
|
|
|
|
className="text-body"
|
|
|
|
to={`/post/${post.id}`}
|
2021-02-22 02:39:04 +00:00
|
|
|
title={i18n.t("comments")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="thumbnail rounded bg-light d-flex justify-content-center">
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="message-square" classes="d-flex align-items-center" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createdLine() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let post_view = this.props.post_view;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<ul className="list-inline mb-1 text-muted small">
|
2020-09-06 16:15:25 +00:00
|
|
|
<li className="list-inline-item">
|
2021-03-15 18:09:31 +00:00
|
|
|
<PersonListing person={post_view.creator} />
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.creatorIsMod_ && (
|
2021-02-22 02:39:04 +00:00
|
|
|
<span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.creatorIsAdmin_ && (
|
2021-02-22 02:39:04 +00:00
|
|
|
<span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2021-10-18 01:44:02 +00:00
|
|
|
{post_view.creator.bot_account && (
|
|
|
|
<span className="mx-1 badge badge-light">
|
|
|
|
{i18n.t("bot_account").toLowerCase()}
|
|
|
|
</span>
|
|
|
|
)}
|
2020-12-24 01:58:27 +00:00
|
|
|
{(post_view.creator_banned_from_community ||
|
2022-01-09 17:53:11 +00:00
|
|
|
isBanned(post_view.creator)) && (
|
2021-02-22 02:39:04 +00:00
|
|
|
<span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2021-08-20 02:56:18 +00:00
|
|
|
{post_view.creator_blocked && (
|
|
|
|
<span className="mx-1 badge badge-danger">{"blocked"}</span>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.props.showCommunity && (
|
|
|
|
<span>
|
2022-09-22 15:03:35 +00:00
|
|
|
<span className="mx-1"> {i18n.t("to")} </span>
|
2020-12-24 01:58:27 +00:00
|
|
|
<CommunityLink community={post_view.community} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</li>
|
|
|
|
<li className="list-inline-item">•</li>
|
2022-06-21 21:42:29 +00:00
|
|
|
{post_view.post.url.match({
|
|
|
|
some: url =>
|
|
|
|
!(hostname(url) == externalHost) && (
|
|
|
|
<>
|
|
|
|
<li className="list-inline-item">
|
|
|
|
<a
|
|
|
|
className="text-muted font-italic"
|
|
|
|
href={url}
|
|
|
|
title={url}
|
|
|
|
rel={relTags}
|
|
|
|
>
|
|
|
|
{hostname(url)}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li className="list-inline-item">•</li>
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
})}
|
2020-09-06 16:15:25 +00:00
|
|
|
<li className="list-inline-item">
|
|
|
|
<span>
|
2022-06-21 21:42:29 +00:00
|
|
|
<MomentTime
|
|
|
|
published={post_view.post.published}
|
|
|
|
updated={post_view.post.updated}
|
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
</span>
|
|
|
|
</li>
|
2022-06-21 21:42:29 +00:00
|
|
|
{post_view.post.body.match({
|
|
|
|
some: body => (
|
|
|
|
<>
|
|
|
|
<li className="list-inline-item">•</li>
|
|
|
|
<li className="list-inline-item">
|
|
|
|
<button
|
|
|
|
className="text-muted btn btn-sm btn-link p-0"
|
2022-11-19 02:02:38 +00:00
|
|
|
data-tippy-content={mdNoImages.render(body)}
|
2022-06-21 21:42:29 +00:00
|
|
|
data-tippy-allowHtml={true}
|
|
|
|
onClick={linkEvent(this, this.handleShowBody)}
|
|
|
|
>
|
|
|
|
<Icon icon="book-open" classes="icon-inline mr-1" />
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
})}
|
2020-09-06 16:15:25 +00:00
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
voteBar() {
|
|
|
|
return (
|
|
|
|
<div className={`vote-bar col-1 pr-0 small text-center`}>
|
|
|
|
<button
|
|
|
|
className={`btn-animate btn btn-link p-0 ${
|
2022-06-21 21:42:29 +00:00
|
|
|
this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
2022-07-30 13:28:08 +00:00
|
|
|
onClick={this.handlePostLike}
|
2021-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={i18n.t("upvote")}
|
|
|
|
aria-label={i18n.t("upvote")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="arrow-up1" classes="upvote" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
2021-04-09 16:23:30 +00:00
|
|
|
{showScores() ? (
|
|
|
|
<div
|
2022-09-22 15:03:35 +00:00
|
|
|
className={`unselectable pointer font-weight-bold text-muted px-1`}
|
2021-04-09 16:23:30 +00:00
|
|
|
data-tippy-content={this.pointsTippy}
|
|
|
|
>
|
2021-09-18 16:35:49 +00:00
|
|
|
{numToSI(this.state.score)}
|
2021-04-09 16:23:30 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="p-1"></div>
|
2021-04-09 16:23:30 +00:00
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.props.enableDownvotes && (
|
|
|
|
<button
|
|
|
|
className={`btn-animate btn btn-link p-0 ${
|
2022-06-21 21:42:29 +00:00
|
|
|
this.state.my_vote.unwrapOr(0) == -1
|
|
|
|
? "text-danger"
|
|
|
|
: "text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
2022-07-30 13:28:08 +00:00
|
|
|
onClick={this.handlePostDisLike}
|
2021-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={i18n.t("downvote")}
|
|
|
|
aria-label={i18n.t("downvote")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="arrow-down1" classes="downvote" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
postTitleLine() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let post = this.props.post_view.post;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<div className="post-title overflow-hidden">
|
|
|
|
<h5>
|
2022-06-21 21:42:29 +00:00
|
|
|
{post.url.match({
|
|
|
|
some: url => (
|
|
|
|
<a
|
|
|
|
className={!post.stickied ? "text-body" : "text-primary"}
|
|
|
|
href={url}
|
|
|
|
title={url}
|
|
|
|
rel={relTags}
|
|
|
|
>
|
2022-11-18 02:01:52 +00:00
|
|
|
<div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
|
2022-06-21 21:42:29 +00:00
|
|
|
</a>
|
|
|
|
),
|
|
|
|
none: (
|
|
|
|
<Link
|
|
|
|
className={!post.stickied ? "text-body" : "text-primary"}
|
|
|
|
to={`/post/${post.id}`}
|
|
|
|
title={i18n.t("comments")}
|
|
|
|
>
|
2022-11-18 02:01:52 +00:00
|
|
|
<div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
|
2022-06-21 21:42:29 +00:00
|
|
|
</Link>
|
|
|
|
),
|
|
|
|
})}
|
|
|
|
{post.url.map(isImage).or(post.thumbnail_url).unwrapOr(false) && (
|
2022-01-12 00:53:23 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link text-monospace text-muted small d-inline-block ml-2"
|
2022-01-12 00:53:23 +00:00
|
|
|
data-tippy-content={i18n.t("expand_here")}
|
|
|
|
onClick={linkEvent(this, this.handleImageExpandClick)}
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
icon={
|
|
|
|
!this.state.imageExpanded ? "plus-square" : "minus-square"
|
|
|
|
}
|
|
|
|
classes="icon-inline"
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
{post.removed && (
|
|
|
|
<small className="ml-2 text-muted font-italic">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("removed")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
{post.deleted && (
|
|
|
|
<small
|
|
|
|
className="unselectable pointer ml-2 text-muted font-italic"
|
2021-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={i18n.t("deleted")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="trash" classes="icon-inline text-danger" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
{post.locked && (
|
|
|
|
<small
|
|
|
|
className="unselectable pointer ml-2 text-muted font-italic"
|
2021-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={i18n.t("locked")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="lock" classes="icon-inline text-danger" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
{post.stickied && (
|
|
|
|
<small
|
|
|
|
className="unselectable pointer ml-2 text-muted font-italic"
|
2021-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={i18n.t("stickied")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="pin" classes="icon-inline text-primary" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
{post.nsfw && (
|
|
|
|
<small className="ml-2 text-muted font-italic">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("nsfw")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
</h5>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
duplicatesLine() {
|
2022-06-21 21:42:29 +00:00
|
|
|
return this.props.duplicates.match({
|
|
|
|
some: dupes =>
|
|
|
|
dupes.length > 0 && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<ul className="list-inline mb-1 small text-muted">
|
2022-06-21 21:42:29 +00:00
|
|
|
<>
|
2020-09-06 16:15:25 +00:00
|
|
|
<li className="list-inline-item mr-2">
|
2022-06-21 21:42:29 +00:00
|
|
|
{i18n.t("cross_posted_to")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
2022-06-21 21:42:29 +00:00
|
|
|
{dupes.map(pv => (
|
2022-09-22 15:03:35 +00:00
|
|
|
<li key={pv.post.id} className="list-inline-item mr-2">
|
2022-06-21 21:42:29 +00:00
|
|
|
<Link to={`/post/${pv.post.id}`}>
|
|
|
|
{pv.community.local
|
|
|
|
? pv.community.name
|
|
|
|
: `${pv.community.name}@${hostname(
|
|
|
|
pv.community.actor_id
|
|
|
|
)}`}
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
</ul>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-01-12 00:53:23 +00:00
|
|
|
commentsLine(mobile = false) {
|
2022-02-17 18:28:43 +00:00
|
|
|
let post = this.props.post_view.post;
|
2022-01-12 00:53:23 +00:00
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
|
2022-01-12 00:53:23 +00:00
|
|
|
{this.commentsButton}
|
2022-02-17 18:28:43 +00:00
|
|
|
{!post.local && (
|
|
|
|
<a
|
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
|
|
|
title={i18n.t("link")}
|
|
|
|
href={post.ap_id}
|
|
|
|
>
|
|
|
|
<Icon icon="fedilink" inline />
|
|
|
|
</a>
|
|
|
|
)}
|
2022-02-02 14:56:43 +00:00
|
|
|
{mobile && !this.props.viewOnly && this.mobileVotes}
|
2022-06-21 21:42:29 +00:00
|
|
|
{UserService.Instance.myUserInfo.isSome() &&
|
2022-02-02 14:56:43 +00:00
|
|
|
!this.props.viewOnly &&
|
|
|
|
this.postActions(mobile)}
|
2022-01-12 00:53:23 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-22 02:24:09 +00:00
|
|
|
postActions(mobile = false) {
|
2022-01-12 00:53:23 +00:00
|
|
|
// Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
|
|
|
|
// Possible enhancement: Make each button a component.
|
2020-12-24 01:58:27 +00:00
|
|
|
let post_view = this.props.post_view;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2022-01-12 00:53:23 +00:00
|
|
|
<>
|
|
|
|
{this.saveButton}
|
|
|
|
{this.crossPostButton}
|
|
|
|
{mobile && this.showMoreButton}
|
|
|
|
{(!mobile || this.state.showAdvanced) && (
|
|
|
|
<>
|
|
|
|
{!this.myPost && (
|
|
|
|
<>
|
|
|
|
{this.reportButton}
|
|
|
|
{this.blockButton}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{this.myPost && (this.showBody || this.state.showAdvanced) && (
|
|
|
|
<>
|
|
|
|
{this.editButton}
|
|
|
|
{this.deleteButton}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{this.state.showAdvanced && (
|
|
|
|
<>
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.showBody &&
|
|
|
|
post_view.post.body.isSome() &&
|
|
|
|
this.viewSourceButton}
|
|
|
|
{this.canModOnSelf_ && (
|
2022-01-12 00:53:23 +00:00
|
|
|
<>
|
|
|
|
{this.lockButton}
|
|
|
|
{this.stickyButton}
|
|
|
|
</>
|
|
|
|
)}
|
2022-06-21 21:42:29 +00:00
|
|
|
{(this.canMod_ || this.canAdmin_) && <>{this.modRemoveButton}</>}
|
2022-01-12 00:53:23 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{!mobile && this.showMoreButton}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get commentsButton() {
|
|
|
|
let post_view = this.props.post_view;
|
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<button className="btn btn-link text-muted py-0 pl-0">
|
2022-01-12 00:53:23 +00:00
|
|
|
<Link
|
|
|
|
className="text-muted"
|
|
|
|
title={i18n.t("number_of_comments", {
|
|
|
|
count: post_view.counts.comments,
|
|
|
|
formattedCount: post_view.counts.comments,
|
|
|
|
})}
|
|
|
|
to={`/post/${post_view.post.id}?scrollToComments=true`}
|
|
|
|
>
|
|
|
|
<Icon icon="message-square" classes="mr-1" inline />
|
2022-09-27 19:42:24 +00:00
|
|
|
<span className="mr-2">
|
|
|
|
{i18n.t("number_of_comments", {
|
|
|
|
count: post_view.counts.comments,
|
|
|
|
formattedCount: numToSI(post_view.counts.comments),
|
|
|
|
})}
|
|
|
|
</span>
|
|
|
|
{this.unreadCount.match({
|
|
|
|
some: unreadCount => (
|
|
|
|
<span className="small text-warning">
|
|
|
|
({unreadCount} {i18n.t("new")})
|
|
|
|
</span>
|
|
|
|
),
|
|
|
|
none: <></>,
|
2022-01-12 00:53:23 +00:00
|
|
|
})}
|
|
|
|
</Link>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-27 19:42:24 +00:00
|
|
|
get unreadCount(): Option<number> {
|
|
|
|
let pv = this.props.post_view;
|
|
|
|
if (pv.unread_comments == pv.counts.comments || pv.unread_comments == 0) {
|
|
|
|
return None;
|
|
|
|
} else {
|
|
|
|
return Some(pv.unread_comments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-12 00:53:23 +00:00
|
|
|
get mobileVotes() {
|
|
|
|
// TODO: make nicer
|
|
|
|
let tippy = showScores() ? { "data-tippy-content": this.pointsTippy } : {};
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div>
|
|
|
|
<button
|
|
|
|
className={`btn-animate btn py-0 px-1 ${
|
2022-06-21 21:42:29 +00:00
|
|
|
this.state.my_vote.unwrapOr(0) == 1 ? "text-info" : "text-muted"
|
2022-01-12 00:53:23 +00:00
|
|
|
}`}
|
|
|
|
{...tippy}
|
2022-07-30 13:28:08 +00:00
|
|
|
onClick={this.handlePostLike}
|
2022-01-12 00:53:23 +00:00
|
|
|
aria-label={i18n.t("upvote")}
|
|
|
|
>
|
|
|
|
<Icon icon="arrow-up1" classes="icon-inline small" />
|
|
|
|
{showScores() && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<span className="ml-2">{numToSI(this.state.upvotes)}</span>
|
2022-01-12 00:53:23 +00:00
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
{this.props.enableDownvotes && (
|
|
|
|
<button
|
|
|
|
className={`ml-2 btn-animate btn py-0 px-1 ${
|
2022-06-21 21:42:29 +00:00
|
|
|
this.state.my_vote.unwrapOr(0) == -1
|
|
|
|
? "text-danger"
|
|
|
|
: "text-muted"
|
2022-01-12 00:53:23 +00:00
|
|
|
}`}
|
2022-07-30 13:28:08 +00:00
|
|
|
onClick={this.handlePostDisLike}
|
2022-01-12 00:53:23 +00:00
|
|
|
{...tippy}
|
|
|
|
aria-label={i18n.t("downvote")}
|
|
|
|
>
|
|
|
|
<Icon icon="arrow-down1" classes="icon-inline small" />
|
|
|
|
{showScores() && (
|
|
|
|
<span
|
2022-09-22 15:03:35 +00:00
|
|
|
className={classNames("ml-2", {
|
2022-01-12 00:53:23 +00:00
|
|
|
invisible: this.state.downvotes === 0,
|
|
|
|
})}
|
2020-09-26 16:18:49 +00:00
|
|
|
>
|
2022-01-12 00:53:23 +00:00
|
|
|
{numToSI(this.state.downvotes)}
|
|
|
|
</span>
|
2020-09-26 16:18:49 +00:00
|
|
|
)}
|
2022-01-12 00:53:23 +00:00
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get saveButton() {
|
|
|
|
let saved = this.props.post_view.saved;
|
|
|
|
let label = saved ? i18n.t("unsave") : i18n.t("save");
|
|
|
|
return (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(this, this.handleSavePostClick)}
|
|
|
|
data-tippy-content={label}
|
|
|
|
aria-label={label}
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
icon="star"
|
|
|
|
classes={classNames({ "text-warning": saved })}
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get crossPostButton() {
|
|
|
|
return (
|
|
|
|
<Link
|
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
|
|
|
to={`/create_post${this.crossPostParams}`}
|
|
|
|
title={i18n.t("cross_post")}
|
|
|
|
>
|
|
|
|
<Icon icon="copy" inline />
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get reportButton() {
|
|
|
|
return (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(this, this.handleShowReportDialog)}
|
|
|
|
data-tippy-content={i18n.t("show_report_dialog")}
|
|
|
|
aria-label={i18n.t("show_report_dialog")}
|
|
|
|
>
|
|
|
|
<Icon icon="flag" inline />
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get blockButton() {
|
|
|
|
return (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(this, this.handleBlockUserClick)}
|
|
|
|
data-tippy-content={i18n.t("block_user")}
|
|
|
|
aria-label={i18n.t("block_user")}
|
|
|
|
>
|
|
|
|
<Icon icon="slash" inline />
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get editButton() {
|
|
|
|
return (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(this, this.handleEditClick)}
|
|
|
|
data-tippy-content={i18n.t("edit")}
|
|
|
|
aria-label={i18n.t("edit")}
|
|
|
|
>
|
|
|
|
<Icon icon="edit" inline />
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get deleteButton() {
|
|
|
|
let deleted = this.props.post_view.post.deleted;
|
|
|
|
let label = !deleted ? i18n.t("delete") : i18n.t("restore");
|
|
|
|
return (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(this, this.handleDeleteClick)}
|
|
|
|
data-tippy-content={label}
|
|
|
|
aria-label={label}
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
icon="trash"
|
|
|
|
classes={classNames({ "text-danger": deleted })}
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get showMoreButton() {
|
|
|
|
return (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(this, this.handleShowAdvanced)}
|
|
|
|
data-tippy-content={i18n.t("more")}
|
|
|
|
aria-label={i18n.t("more")}
|
|
|
|
>
|
|
|
|
<Icon icon="more-vertical" inline />
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get viewSourceButton() {
|
|
|
|
return (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(this, this.handleViewSource)}
|
|
|
|
data-tippy-content={i18n.t("view_source")}
|
|
|
|
aria-label={i18n.t("view_source")}
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
icon="file-text"
|
|
|
|
classes={classNames({ "text-success": this.state.viewSource })}
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get lockButton() {
|
|
|
|
let locked = this.props.post_view.post.locked;
|
|
|
|
let label = locked ? i18n.t("unlock") : i18n.t("lock");
|
|
|
|
return (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(this, this.handleModLock)}
|
|
|
|
data-tippy-content={label}
|
|
|
|
aria-label={label}
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
icon="lock"
|
|
|
|
classes={classNames({ "text-danger": locked })}
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get stickyButton() {
|
|
|
|
let stickied = this.props.post_view.post.stickied;
|
|
|
|
let label = stickied ? i18n.t("unsticky") : i18n.t("sticky");
|
|
|
|
return (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(this, this.handleModSticky)}
|
|
|
|
data-tippy-content={label}
|
|
|
|
aria-label={label}
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
icon="pin"
|
|
|
|
classes={classNames({ "text-success": stickied })}
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get modRemoveButton() {
|
|
|
|
let removed = this.props.post_view.post.removed;
|
|
|
|
return (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
!removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{/* TODO: Find an icon for this. */}
|
|
|
|
{!removed ? i18n.t("remove") : i18n.t("restore")}
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mod/Admin actions to be taken against the author.
|
|
|
|
*/
|
|
|
|
userActionsLine() {
|
|
|
|
// TODO: make nicer
|
|
|
|
let post_view = this.props.post_view;
|
|
|
|
return (
|
|
|
|
this.state.showAdvanced && (
|
|
|
|
<>
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.canMod_ && (
|
2022-01-12 00:53:23 +00:00
|
|
|
<>
|
2022-06-21 21:42:29 +00:00
|
|
|
{!this.creatorIsMod_ &&
|
2022-01-12 00:53:23 +00:00
|
|
|
(!post_view.creator_banned_from_community ? (
|
2021-09-28 10:38:59 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModBanFromCommunityShow
|
|
|
|
)}
|
|
|
|
aria-label={i18n.t("ban")}
|
2021-09-28 10:38:59 +00:00
|
|
|
>
|
2022-01-12 00:53:23 +00:00
|
|
|
{i18n.t("ban")}
|
2021-09-28 10:38:59 +00:00
|
|
|
</button>
|
2022-01-12 00:53:23 +00:00
|
|
|
) : (
|
2021-09-28 10:38:59 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModBanFromCommunitySubmit
|
|
|
|
)}
|
|
|
|
aria-label={i18n.t("unban")}
|
2021-09-28 10:38:59 +00:00
|
|
|
>
|
2022-01-12 00:53:23 +00:00
|
|
|
{i18n.t("unban")}
|
2021-09-28 10:38:59 +00:00
|
|
|
</button>
|
2022-01-12 00:53:23 +00:00
|
|
|
))}
|
|
|
|
{!post_view.creator_banned_from_community && (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(this, this.handleAddModToCommunity)}
|
|
|
|
aria-label={
|
2022-06-21 21:42:29 +00:00
|
|
|
this.creatorIsMod_
|
2022-01-12 00:53:23 +00:00
|
|
|
? i18n.t("remove_as_mod")
|
|
|
|
: i18n.t("appoint_as_mod")
|
|
|
|
}
|
|
|
|
>
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.creatorIsMod_
|
2022-01-12 00:53:23 +00:00
|
|
|
? i18n.t("remove_as_mod")
|
|
|
|
: i18n.t("appoint_as_mod")}
|
|
|
|
</button>
|
2021-08-20 02:56:18 +00:00
|
|
|
)}
|
2020-09-26 16:18:49 +00:00
|
|
|
</>
|
|
|
|
)}
|
2022-01-12 00:53:23 +00:00
|
|
|
{/* Community creators and admins can transfer community to another mod */}
|
2022-06-21 21:42:29 +00:00
|
|
|
{(amCommunityCreator(this.props.moderators, post_view.creator.id) ||
|
|
|
|
this.canAdmin_) &&
|
|
|
|
this.creatorIsMod_ &&
|
2022-01-12 00:53:23 +00:00
|
|
|
(!this.state.showConfirmTransferCommunity ? (
|
2020-09-26 16:18:49 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleShowConfirmTransferCommunity
|
|
|
|
)}
|
|
|
|
aria-label={i18n.t("transfer_community")}
|
2020-09-26 16:18:49 +00:00
|
|
|
>
|
2022-01-12 00:53:23 +00:00
|
|
|
{i18n.t("transfer_community")}
|
2020-09-26 16:18:49 +00:00
|
|
|
</button>
|
2022-01-12 00:53:23 +00:00
|
|
|
) : (
|
|
|
|
<>
|
2020-09-26 16:18:49 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
aria-label={i18n.t("are_you_sure")}
|
2020-09-26 16:18:49 +00:00
|
|
|
>
|
2022-01-12 00:53:23 +00:00
|
|
|
{i18n.t("are_you_sure")}
|
2020-09-26 16:18:49 +00:00
|
|
|
</button>
|
2022-01-12 00:53:23 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
|
2022-01-12 00:53:23 +00:00
|
|
|
aria-label={i18n.t("yes")}
|
|
|
|
onClick={linkEvent(this, this.handleTransferCommunity)}
|
|
|
|
>
|
|
|
|
{i18n.t("yes")}
|
|
|
|
</button>
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0 d-inline-block"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleCancelShowConfirmTransferCommunity
|
2021-03-25 16:44:16 +00:00
|
|
|
)}
|
2022-01-12 00:53:23 +00:00
|
|
|
aria-label={i18n.t("no")}
|
|
|
|
>
|
|
|
|
{i18n.t("no")}
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
{/* Admins can ban from all, and appoint other admins */}
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.canAdmin_ && (
|
2022-01-12 00:53:23 +00:00
|
|
|
<>
|
2022-06-23 19:44:05 +00:00
|
|
|
{!this.creatorIsAdmin_ && (
|
|
|
|
<>
|
|
|
|
{!isBanned(post_view.creator) ? (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-06-23 19:44:05 +00:00
|
|
|
onClick={linkEvent(this, this.handleModBanShow)}
|
|
|
|
aria-label={i18n.t("ban_from_site")}
|
|
|
|
>
|
|
|
|
{i18n.t("ban_from_site")}
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-06-23 19:44:05 +00:00
|
|
|
onClick={linkEvent(this, this.handleModBanSubmit)}
|
|
|
|
aria-label={i18n.t("unban_from_site")}
|
|
|
|
>
|
|
|
|
{i18n.t("unban_from_site")}
|
|
|
|
</button>
|
|
|
|
)}
|
2020-10-13 20:12:40 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-06-23 19:44:05 +00:00
|
|
|
onClick={linkEvent(this, this.handlePurgePersonShow)}
|
|
|
|
aria-label={i18n.t("purge_user")}
|
2020-09-26 16:18:49 +00:00
|
|
|
>
|
2022-06-23 19:44:05 +00:00
|
|
|
{i18n.t("purge_user")}
|
2020-10-13 20:12:40 +00:00
|
|
|
</button>
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-06-23 19:44:05 +00:00
|
|
|
onClick={linkEvent(this, this.handlePurgePostShow)}
|
|
|
|
aria-label={i18n.t("purge_post")}
|
2020-09-26 16:18:49 +00:00
|
|
|
>
|
2022-06-23 19:44:05 +00:00
|
|
|
{i18n.t("purge_post")}
|
2020-10-13 20:12:40 +00:00
|
|
|
</button>
|
2022-06-23 19:44:05 +00:00
|
|
|
</>
|
|
|
|
)}
|
2022-01-12 00:53:23 +00:00
|
|
|
{!isBanned(post_view.creator) && post_view.creator.local && (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link btn-animate text-muted py-0"
|
2022-01-12 00:53:23 +00:00
|
|
|
onClick={linkEvent(this, this.handleAddAdmin)}
|
|
|
|
aria-label={
|
2022-06-21 21:42:29 +00:00
|
|
|
this.creatorIsAdmin_
|
2022-01-12 00:53:23 +00:00
|
|
|
? i18n.t("remove_as_admin")
|
|
|
|
: i18n.t("appoint_as_admin")
|
|
|
|
}
|
|
|
|
>
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.creatorIsAdmin_
|
2022-01-12 00:53:23 +00:00
|
|
|
? i18n.t("remove_as_admin")
|
|
|
|
: i18n.t("appoint_as_admin")}
|
|
|
|
</button>
|
|
|
|
)}
|
2020-09-26 16:18:49 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
removeAndBanDialogs() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let post = this.props.post_view;
|
2022-06-23 19:44:05 +00:00
|
|
|
let purgeTypeText: string;
|
|
|
|
if (this.state.purgeType == PurgeType.Post) {
|
|
|
|
purgeTypeText = i18n.t("purge_post");
|
|
|
|
} else if (this.state.purgeType == PurgeType.Person) {
|
|
|
|
purgeTypeText = `${i18n.t("purge")} ${post.creator.name}`;
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{this.state.showRemoveDialog && (
|
|
|
|
<form
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-inline"
|
2020-09-06 16:15:25 +00:00
|
|
|
onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
|
|
|
|
>
|
2022-09-22 15:03:35 +00:00
|
|
|
<label className="sr-only" htmlFor="post-listing-remove-reason">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("reason")}
|
2021-02-09 16:21:24 +00:00
|
|
|
</label>
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
|
|
|
type="text"
|
2021-02-09 16:21:24 +00:00
|
|
|
id="post-listing-remove-reason"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control mr-2"
|
2021-02-22 02:39:04 +00:00
|
|
|
placeholder={i18n.t("reason")}
|
2022-06-21 21:42:29 +00:00
|
|
|
value={toUndefined(this.state.removeReason)}
|
2020-09-06 16:15:25 +00:00
|
|
|
onInput={linkEvent(this, this.handleModRemoveReasonChange)}
|
|
|
|
/>
|
2021-02-09 16:21:24 +00:00
|
|
|
<button
|
|
|
|
type="submit"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-secondary"
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("remove_post")}
|
2021-02-09 16:21:24 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("remove_post")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
)}
|
|
|
|
{this.state.showBanDialog && (
|
|
|
|
<form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row col-12">
|
|
|
|
<label
|
|
|
|
className="col-form-label"
|
|
|
|
htmlFor="post-listing-ban-reason"
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("reason")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
2021-02-09 16:21:24 +00:00
|
|
|
id="post-listing-ban-reason"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control mr-2"
|
2021-02-22 02:39:04 +00:00
|
|
|
placeholder={i18n.t("reason")}
|
2022-06-21 21:42:29 +00:00
|
|
|
value={toUndefined(this.state.banReason)}
|
2020-09-06 16:15:25 +00:00
|
|
|
onInput={linkEvent(this, this.handleModBanReasonChange)}
|
|
|
|
/>
|
2022-09-22 15:03:35 +00:00
|
|
|
<label className="col-form-label" htmlFor={`mod-ban-expires`}>
|
2022-01-09 17:53:11 +00:00
|
|
|
{i18n.t("expires")}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
id={`mod-ban-expires`}
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control mr-2"
|
2022-01-09 17:53:11 +00:00
|
|
|
placeholder={i18n.t("number_of_days")}
|
2022-06-21 21:42:29 +00:00
|
|
|
value={toUndefined(this.state.banExpireDays)}
|
2022-01-09 17:53:11 +00:00
|
|
|
onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
|
|
|
|
/>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group">
|
|
|
|
<div className="form-check">
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-input"
|
2020-09-06 16:15:25 +00:00
|
|
|
id="mod-ban-remove-data"
|
|
|
|
type="checkbox"
|
|
|
|
checked={this.state.removeData}
|
|
|
|
onChange={linkEvent(this, this.handleModRemoveDataChange)}
|
|
|
|
/>
|
2021-08-17 21:46:27 +00:00
|
|
|
<label
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-label"
|
2021-08-17 21:46:27 +00:00
|
|
|
htmlFor="mod-ban-remove-data"
|
|
|
|
title={i18n.t("remove_content_more")}
|
|
|
|
>
|
|
|
|
{i18n.t("remove_content")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/* TODO hold off on expires until later */}
|
|
|
|
{/* <div class="form-group row"> */}
|
|
|
|
{/* <label class="col-form-label">Expires</label> */}
|
|
|
|
{/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
|
|
|
|
{/* </div> */}
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
2021-02-09 16:21:24 +00:00
|
|
|
<button
|
|
|
|
type="submit"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-secondary"
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("ban")}
|
2021-02-09 16:21:24 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("ban")} {post.creator.name}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
)}
|
2021-09-28 10:38:59 +00:00
|
|
|
{this.state.showReportDialog && (
|
|
|
|
<form
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-inline"
|
2021-09-28 10:38:59 +00:00
|
|
|
onSubmit={linkEvent(this, this.handleReportSubmit)}
|
|
|
|
>
|
2022-09-22 15:03:35 +00:00
|
|
|
<label className="sr-only" htmlFor="post-report-reason">
|
2021-09-28 10:38:59 +00:00
|
|
|
{i18n.t("reason")}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="post-report-reason"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control mr-2"
|
2021-09-28 10:38:59 +00:00
|
|
|
placeholder={i18n.t("reason")}
|
|
|
|
required
|
2022-06-21 21:42:29 +00:00
|
|
|
value={toUndefined(this.state.reportReason)}
|
2021-09-28 10:38:59 +00:00
|
|
|
onInput={linkEvent(this, this.handleReportReasonChange)}
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
type="submit"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-secondary"
|
2021-09-28 10:38:59 +00:00
|
|
|
aria-label={i18n.t("create_report")}
|
|
|
|
>
|
|
|
|
{i18n.t("create_report")}
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
)}
|
2022-06-23 19:44:05 +00:00
|
|
|
{this.state.showPurgeDialog && (
|
|
|
|
<form
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-inline"
|
2022-06-23 19:44:05 +00:00
|
|
|
onSubmit={linkEvent(this, this.handlePurgeSubmit)}
|
|
|
|
>
|
|
|
|
<PurgeWarning />
|
2022-09-22 15:03:35 +00:00
|
|
|
<label className="sr-only" htmlFor="purge-reason">
|
2022-06-23 19:44:05 +00:00
|
|
|
{i18n.t("reason")}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="purge-reason"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control mr-2"
|
2022-06-23 19:44:05 +00:00
|
|
|
placeholder={i18n.t("reason")}
|
|
|
|
value={toUndefined(this.state.purgeReason)}
|
|
|
|
onInput={linkEvent(this, this.handlePurgeReasonChange)}
|
|
|
|
/>
|
|
|
|
{this.state.purgeLoading ? (
|
|
|
|
<Spinner />
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
type="submit"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-secondary"
|
2022-06-23 19:44:05 +00:00
|
|
|
aria-label={purgeTypeText}
|
|
|
|
>
|
|
|
|
{purgeTypeText}
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</form>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
mobileThumbnail() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let post = this.props.post_view.post;
|
2022-06-21 21:42:29 +00:00
|
|
|
return post.thumbnail_url.isSome() ||
|
|
|
|
post.url.map(isImage).unwrapOr(false) ? (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="row">
|
2021-02-22 02:39:04 +00:00
|
|
|
<div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.postTitleLine()}
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="col-4">
|
2020-09-06 16:15:25 +00:00
|
|
|
{/* Post body prev or thumbnail */}
|
|
|
|
{!this.state.imageExpanded && this.thumbnail()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
this.postTitleLine()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
showMobilePreview() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let post = this.props.post_view.post;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2022-06-21 21:42:29 +00:00
|
|
|
!this.showBody &&
|
|
|
|
post.body.match({
|
|
|
|
some: body => <div className="md-div mb-1 preview-lines">{body}</div>,
|
|
|
|
none: <></>,
|
|
|
|
})
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
listing() {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{/* The mobile view*/}
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="d-block d-sm-none">
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-12">
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.createdLine()}
|
|
|
|
|
|
|
|
{/* If it has a thumbnail, do a right aligned thumbnail */}
|
|
|
|
{this.mobileThumbnail()}
|
|
|
|
|
|
|
|
{/* Show a preview of the post body */}
|
|
|
|
{this.showMobilePreview()}
|
|
|
|
|
|
|
|
{this.commentsLine(true)}
|
2022-01-12 00:53:23 +00:00
|
|
|
{this.userActionsLine()}
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.duplicatesLine()}
|
|
|
|
{this.removeAndBanDialogs()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* The larger view*/}
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="d-none d-sm-block">
|
|
|
|
<div className="row">
|
2022-02-02 14:56:43 +00:00
|
|
|
{!this.props.viewOnly && this.voteBar()}
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="col-sm-2 pr-0">
|
|
|
|
<div className="">{this.thumbnail()}</div>
|
2022-01-12 00:53:23 +00:00
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="col-12 col-sm-9">
|
|
|
|
<div className="row">
|
2020-09-06 16:15:25 +00:00
|
|
|
<div className="col-12">
|
|
|
|
{this.postTitleLine()}
|
|
|
|
{this.createdLine()}
|
|
|
|
{this.commentsLine()}
|
|
|
|
{this.duplicatesLine()}
|
2022-01-12 00:53:23 +00:00
|
|
|
{this.userActionsLine()}
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.removeAndBanDialogs()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private get myPost(): boolean {
|
2022-06-21 21:42:29 +00:00
|
|
|
return UserService.Instance.myUserInfo.match({
|
|
|
|
some: mui =>
|
|
|
|
this.props.post_view.creator.id == mui.local_user_view.person.id,
|
|
|
|
none: false,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
handlePostLike(event: any) {
|
2021-02-02 16:52:44 +00:00
|
|
|
event.preventDefault();
|
2022-06-21 21:42:29 +00:00
|
|
|
if (UserService.Instance.myUserInfo.isNone()) {
|
2020-09-06 16:15:25 +00:00
|
|
|
this.context.router.history.push(`/login`);
|
|
|
|
}
|
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
let myVote = this.state.my_vote.unwrapOr(0);
|
|
|
|
let newVote = myVote == 1 ? 0 : 1;
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
if (myVote == 1) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
|
|
|
score: this.state.score - 1,
|
|
|
|
upvotes: this.state.upvotes - 1,
|
|
|
|
});
|
2022-06-21 21:42:29 +00:00
|
|
|
} else if (myVote == -1) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
|
|
|
score: this.state.score + 2,
|
|
|
|
upvotes: this.state.upvotes + 1,
|
|
|
|
downvotes: this.state.downvotes - 1,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
|
|
|
score: this.state.score + 1,
|
|
|
|
upvotes: this.state.upvotes + 1,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ my_vote: Some(newVote) });
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new CreatePostLike({
|
2022-07-30 13:28:08 +00:00
|
|
|
post_id: this.props.post_view.post.id,
|
2022-06-21 21:42:29 +00:00
|
|
|
score: newVote,
|
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.likePost(form));
|
2022-07-30 13:28:08 +00:00
|
|
|
this.setState(this.state);
|
2020-09-06 16:15:25 +00:00
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
2022-07-30 13:28:08 +00:00
|
|
|
handlePostDisLike(event: any) {
|
2021-02-02 16:52:44 +00:00
|
|
|
event.preventDefault();
|
2022-06-21 21:42:29 +00:00
|
|
|
if (UserService.Instance.myUserInfo.isNone()) {
|
2020-09-06 16:15:25 +00:00
|
|
|
this.context.router.history.push(`/login`);
|
|
|
|
}
|
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
let myVote = this.state.my_vote.unwrapOr(0);
|
|
|
|
let newVote = myVote == -1 ? 0 : -1;
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
if (myVote == 1) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
|
|
|
score: this.state.score - 2,
|
|
|
|
upvotes: this.state.upvotes - 1,
|
|
|
|
downvotes: this.state.downvotes + 1,
|
|
|
|
});
|
2022-06-21 21:42:29 +00:00
|
|
|
} else if (myVote == -1) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
|
|
|
score: this.state.score + 1,
|
|
|
|
downvotes: this.state.downvotes - 1,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({
|
|
|
|
score: this.state.score - 1,
|
|
|
|
downvotes: this.state.downvotes + 1,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ my_vote: Some(newVote) });
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new CreatePostLike({
|
2022-07-30 13:28:08 +00:00
|
|
|
post_id: this.props.post_view.post.id,
|
2022-06-21 21:42:29 +00:00
|
|
|
score: newVote,
|
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.likePost(form));
|
2022-07-30 13:28:08 +00:00
|
|
|
this.setState(this.state);
|
2020-09-06 16:15:25 +00:00
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEditClick(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showEdit: true });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleEditCancel() {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ showEdit: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The actual editing is done in the recieve for post
|
|
|
|
handleEditPost() {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ showEdit: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 10:38:59 +00:00
|
|
|
handleShowReportDialog(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showReportDialog: !i.state.showReportDialog });
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleReportReasonChange(i: PostListing, event: any) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ reportReason: Some(event.target.value) });
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleReportSubmit(i: PostListing, event: any) {
|
|
|
|
event.preventDefault();
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new CreatePostReport({
|
2021-09-28 10:38:59 +00:00
|
|
|
post_id: i.props.post_view.post.id,
|
2022-06-21 21:42:29 +00:00
|
|
|
reason: toUndefined(i.state.reportReason),
|
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2021-09-28 10:38:59 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.createPostReport(form));
|
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showReportDialog: false });
|
2021-09-28 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 02:56:18 +00:00
|
|
|
handleBlockUserClick(i: PostListing) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let blockUserForm = new BlockPerson({
|
2021-08-20 02:56:18 +00:00
|
|
|
person_id: i.props.post_view.creator.id,
|
|
|
|
block: true,
|
2022-06-21 21:42:29 +00:00
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2021-08-20 02:56:18 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleDeleteClick(i: PostListing) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let deleteForm = new DeletePost({
|
2021-01-18 22:42:41 +00:00
|
|
|
post_id: i.props.post_view.post.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
deleted: !i.props.post_view.post.deleted,
|
2022-06-21 21:42:29 +00:00
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleSavePostClick(i: PostListing) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let saved =
|
|
|
|
i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new SavePost({
|
2020-12-24 01:58:27 +00:00
|
|
|
post_id: i.props.post_view.post.id,
|
2020-09-06 16:15:25 +00:00
|
|
|
save: saved,
|
2022-06-21 21:42:29 +00:00
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.savePost(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get crossPostParams(): string {
|
2020-12-24 01:58:27 +00:00
|
|
|
let post = this.props.post_view.post;
|
2021-02-02 17:18:18 +00:00
|
|
|
let params = `?title=${encodeURIComponent(post.name)}`;
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
if (post.url.isSome()) {
|
|
|
|
params += `&url=${encodeURIComponent(post.url.unwrap())}`;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2022-06-21 21:42:29 +00:00
|
|
|
if (post.body.isSome()) {
|
2021-03-25 17:28:47 +00:00
|
|
|
params += `&body=${encodeURIComponent(this.crossPostBody())}`;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
2021-03-25 17:28:47 +00:00
|
|
|
crossPostBody(): string {
|
|
|
|
let post = this.props.post_view.post;
|
2022-06-21 21:42:29 +00:00
|
|
|
let body = `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${post.body
|
|
|
|
.unwrap()
|
|
|
|
.replace(/^/gm, "> ")}`;
|
2021-03-25 17:28:47 +00:00
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
2021-03-25 16:44:16 +00:00
|
|
|
get showBody(): boolean {
|
|
|
|
return this.props.showBody || this.state.showBody;
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleModRemoveShow(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({
|
|
|
|
showRemoveDialog: !i.state.showRemoveDialog,
|
|
|
|
showBanDialog: false,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveReasonChange(i: PostListing, event: any) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ removeReason: Some(event.target.value) });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveDataChange(i: PostListing, event: any) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ removeData: event.target.checked });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 17:21:10 +00:00
|
|
|
handleModRemoveSubmit(i: PostListing, event: any) {
|
2020-09-06 16:15:25 +00:00
|
|
|
event.preventDefault();
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new RemovePost({
|
2021-01-18 22:42:41 +00:00
|
|
|
post_id: i.props.post_view.post.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
removed: !i.props.post_view.post.removed,
|
2020-09-06 16:15:25 +00:00
|
|
|
reason: i.state.removeReason,
|
2022-06-21 21:42:29 +00:00
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.removePost(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showRemoveDialog: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModLock(i: PostListing) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new LockPost({
|
2021-01-18 22:42:41 +00:00
|
|
|
post_id: i.props.post_view.post.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
locked: !i.props.post_view.post.locked,
|
2022-06-21 21:42:29 +00:00
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.lockPost(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModSticky(i: PostListing) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new StickyPost({
|
2021-01-18 22:42:41 +00:00
|
|
|
post_id: i.props.post_view.post.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
stickied: !i.props.post_view.post.stickied,
|
2022-06-21 21:42:29 +00:00
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.stickyPost(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanFromCommunityShow(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({
|
|
|
|
showBanDialog: true,
|
|
|
|
banType: BanType.Community,
|
|
|
|
showRemoveDialog: false,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanShow(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({
|
|
|
|
showBanDialog: true,
|
|
|
|
banType: BanType.Site,
|
|
|
|
showRemoveDialog: false,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-06-23 19:44:05 +00:00
|
|
|
handlePurgePersonShow(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({
|
|
|
|
showPurgeDialog: true,
|
|
|
|
purgeType: PurgeType.Person,
|
|
|
|
showRemoveDialog: false,
|
|
|
|
});
|
2022-06-23 19:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handlePurgePostShow(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({
|
|
|
|
showPurgeDialog: true,
|
|
|
|
purgeType: PurgeType.Post,
|
|
|
|
showRemoveDialog: false,
|
|
|
|
});
|
2022-06-23 19:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handlePurgeReasonChange(i: PostListing, event: any) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ purgeReason: Some(event.target.value) });
|
2022-06-23 19:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handlePurgeSubmit(i: PostListing, event: any) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if (i.state.purgeType == PurgeType.Person) {
|
|
|
|
let form = new PurgePerson({
|
|
|
|
person_id: i.props.post_view.creator.id,
|
|
|
|
reason: i.state.purgeReason,
|
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
|
|
|
WebSocketService.Instance.send(wsClient.purgePerson(form));
|
|
|
|
} else if (i.state.purgeType == PurgeType.Post) {
|
|
|
|
let form = new PurgePost({
|
|
|
|
post_id: i.props.post_view.post.id,
|
|
|
|
reason: i.state.purgeReason,
|
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
|
|
|
WebSocketService.Instance.send(wsClient.purgePost(form));
|
|
|
|
}
|
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ purgeLoading: true });
|
2022-06-23 19:44:05 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleModBanReasonChange(i: PostListing, event: any) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ banReason: Some(event.target.value) });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-01-09 17:53:11 +00:00
|
|
|
handleModBanExpireDaysChange(i: PostListing, event: any) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ banExpireDays: Some(event.target.value) });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanFromCommunitySubmit(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ banType: BanType.Community });
|
2020-09-06 16:15:25 +00:00
|
|
|
i.handleModBanBothSubmit(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanSubmit(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ banType: BanType.Site });
|
2020-09-06 16:15:25 +00:00
|
|
|
i.handleModBanBothSubmit(i);
|
|
|
|
}
|
|
|
|
|
2021-01-26 17:21:10 +00:00
|
|
|
handleModBanBothSubmit(i: PostListing, event?: any) {
|
2021-04-07 17:01:58 +00:00
|
|
|
if (event) event.preventDefault();
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
if (i.state.banType == BanType.Community) {
|
|
|
|
// If its an unban, restore all their data
|
2020-12-24 01:58:27 +00:00
|
|
|
let ban = !i.props.post_view.creator_banned_from_community;
|
2020-09-06 16:15:25 +00:00
|
|
|
if (ban == false) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ removeData: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new BanFromCommunity({
|
2021-03-15 18:09:31 +00:00
|
|
|
person_id: i.props.post_view.creator.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
community_id: i.props.post_view.community.id,
|
2020-09-06 16:15:25 +00:00
|
|
|
ban,
|
2022-06-21 21:42:29 +00:00
|
|
|
remove_data: Some(i.state.removeData),
|
2020-09-06 16:15:25 +00:00
|
|
|
reason: i.state.banReason,
|
2022-06-21 21:42:29 +00:00
|
|
|
expires: i.state.banExpireDays.map(futureDaysToUnixTime),
|
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.banFromCommunity(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
|
|
|
// If its an unban, restore all their data
|
2020-12-24 01:58:27 +00:00
|
|
|
let ban = !i.props.post_view.creator.banned;
|
2020-09-06 16:15:25 +00:00
|
|
|
if (ban == false) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ removeData: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new BanPerson({
|
2021-03-15 18:09:31 +00:00
|
|
|
person_id: i.props.post_view.creator.id,
|
2020-09-06 16:15:25 +00:00
|
|
|
ban,
|
2022-06-21 21:42:29 +00:00
|
|
|
remove_data: Some(i.state.removeData),
|
2020-09-06 16:15:25 +00:00
|
|
|
reason: i.state.banReason,
|
2022-06-21 21:42:29 +00:00
|
|
|
expires: i.state.banExpireDays.map(futureDaysToUnixTime),
|
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2021-03-15 18:09:31 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.banPerson(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showBanDialog: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleAddModToCommunity(i: PostListing) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new AddModToCommunity({
|
2021-03-15 18:09:31 +00:00
|
|
|
person_id: i.props.post_view.creator.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
community_id: i.props.post_view.community.id,
|
2022-06-21 21:42:29 +00:00
|
|
|
added: !i.creatorIsMod_,
|
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.addModToCommunity(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleAddAdmin(i: PostListing) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new AddAdmin({
|
2021-03-15 18:09:31 +00:00
|
|
|
person_id: i.props.post_view.creator.id,
|
2022-06-21 21:42:29 +00:00
|
|
|
added: !i.creatorIsAdmin_,
|
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.addAdmin(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleShowConfirmTransferCommunity(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmTransferCommunity: true });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleCancelShowConfirmTransferCommunity(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmTransferCommunity: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleTransferCommunity(i: PostListing) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new TransferCommunity({
|
2020-12-24 01:58:27 +00:00
|
|
|
community_id: i.props.post_view.community.id,
|
2021-03-15 18:09:31 +00:00
|
|
|
person_id: i.props.post_view.creator.id,
|
2022-06-21 21:42:29 +00:00
|
|
|
auth: auth().unwrap(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.transferCommunity(form));
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmTransferCommunity: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleShowConfirmTransferSite(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmTransferSite: true });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleCancelShowConfirmTransferSite(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmTransferSite: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-09-19 20:29:03 +00:00
|
|
|
handleImageExpandClick(i: PostListing, event: any) {
|
|
|
|
event.preventDefault();
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ imageExpanded: !i.state.imageExpanded });
|
2022-01-12 00:53:23 +00:00
|
|
|
setupTippy();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleViewSource(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ viewSource: !i.state.viewSource });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleShowAdvanced(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showAdvanced: !i.state.showAdvanced });
|
2020-09-06 16:15:25 +00:00
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
2020-09-26 16:18:49 +00:00
|
|
|
handleShowMoreMobile(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({
|
|
|
|
showMoreMobile: !i.state.showMoreMobile,
|
|
|
|
showAdvanced: !i.state.showAdvanced,
|
|
|
|
});
|
2020-09-26 16:18:49 +00:00
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
2021-03-25 16:44:16 +00:00
|
|
|
handleShowBody(i: PostListing) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showBody: !i.state.showBody });
|
2021-03-25 16:44:16 +00:00
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
get pointsTippy(): string {
|
2021-02-22 02:39:04 +00:00
|
|
|
let points = i18n.t("number_of_points", {
|
2020-09-06 16:15:25 +00:00
|
|
|
count: this.state.score,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: this.state.score,
|
2020-09-06 16:15:25 +00:00
|
|
|
});
|
|
|
|
|
2021-02-22 02:39:04 +00:00
|
|
|
let upvotes = i18n.t("number_of_upvotes", {
|
2020-09-06 16:15:25 +00:00
|
|
|
count: this.state.upvotes,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: this.state.upvotes,
|
2020-09-06 16:15:25 +00:00
|
|
|
});
|
|
|
|
|
2021-02-22 02:39:04 +00:00
|
|
|
let downvotes = i18n.t("number_of_downvotes", {
|
2020-09-06 16:15:25 +00:00
|
|
|
count: this.state.downvotes,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: this.state.downvotes,
|
2020-09-06 16:15:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return `${points} • ${upvotes} • ${downvotes}`;
|
|
|
|
}
|
2022-06-21 21:42:29 +00:00
|
|
|
|
|
|
|
get canModOnSelf_(): boolean {
|
|
|
|
return canMod(
|
|
|
|
this.props.moderators,
|
|
|
|
this.props.admins,
|
|
|
|
this.props.post_view.creator.id,
|
|
|
|
undefined,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get canMod_(): boolean {
|
|
|
|
return canMod(
|
|
|
|
this.props.moderators,
|
|
|
|
this.props.admins,
|
|
|
|
this.props.post_view.creator.id
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get canAdmin_(): boolean {
|
|
|
|
return canAdmin(this.props.admins, this.props.post_view.creator.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
get creatorIsMod_(): boolean {
|
|
|
|
return isMod(this.props.moderators, this.props.post_view.creator.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
get creatorIsAdmin_(): boolean {
|
|
|
|
return isAdmin(this.props.admins, this.props.post_view.creator.id);
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|