2019-04-03 06:49:32 +00:00
|
|
|
import { Component, linkEvent } from 'inferno';
|
|
|
|
import { Link } from 'inferno-router';
|
|
|
|
import { WebSocketService, UserService } from '../services';
|
2019-10-19 00:20:27 +00:00
|
|
|
import {
|
|
|
|
Post,
|
|
|
|
CreatePostLikeForm,
|
|
|
|
PostForm as PostFormI,
|
|
|
|
SavePostForm,
|
|
|
|
CommunityUser,
|
|
|
|
UserView,
|
|
|
|
BanType,
|
|
|
|
BanFromCommunityForm,
|
|
|
|
BanUserForm,
|
|
|
|
AddModToCommunityForm,
|
|
|
|
AddAdminForm,
|
|
|
|
TransferSiteForm,
|
|
|
|
TransferCommunityForm,
|
2020-02-17 16:18:01 +00:00
|
|
|
FramelyData,
|
2019-10-19 00:20:27 +00:00
|
|
|
} from '../interfaces';
|
2019-04-03 06:49:32 +00:00
|
|
|
import { MomentTime } from './moment-time';
|
2019-04-03 20:59:37 +00:00
|
|
|
import { PostForm } from './post-form';
|
2020-02-17 16:18:01 +00:00
|
|
|
import { IFramelyCard } from './iframely-card';
|
2019-10-19 00:20:27 +00:00
|
|
|
import {
|
|
|
|
mdToHtml,
|
|
|
|
canMod,
|
|
|
|
isMod,
|
|
|
|
isImage,
|
|
|
|
isVideo,
|
|
|
|
getUnixTime,
|
2019-12-29 20:39:48 +00:00
|
|
|
pictshareAvatarThumbnail,
|
2020-01-02 21:55:54 +00:00
|
|
|
showAvatars,
|
2020-01-03 19:13:22 +00:00
|
|
|
imageThumbnailer,
|
2020-03-03 07:29:45 +00:00
|
|
|
setupTippy,
|
2019-10-19 00:20:27 +00:00
|
|
|
} from '../utils';
|
2019-08-10 00:14:43 +00:00
|
|
|
import { i18n } from '../i18next';
|
2019-04-03 06:49:32 +00:00
|
|
|
|
|
|
|
interface PostListingState {
|
2019-04-03 20:59:37 +00:00
|
|
|
showEdit: boolean;
|
2019-04-15 23:12:06 +00:00
|
|
|
showRemoveDialog: boolean;
|
|
|
|
removeReason: string;
|
2019-09-06 00:18:48 +00:00
|
|
|
showBanDialog: boolean;
|
|
|
|
banReason: string;
|
|
|
|
banExpires: string;
|
|
|
|
banType: BanType;
|
|
|
|
showConfirmTransferSite: boolean;
|
|
|
|
showConfirmTransferCommunity: boolean;
|
2019-04-24 16:28:20 +00:00
|
|
|
imageExpanded: boolean;
|
2019-09-08 18:00:08 +00:00
|
|
|
viewSource: boolean;
|
2020-03-01 03:06:42 +00:00
|
|
|
showAdvanced: boolean;
|
2020-02-09 20:04:41 +00:00
|
|
|
my_vote: number;
|
|
|
|
score: number;
|
|
|
|
upvotes: number;
|
|
|
|
downvotes: number;
|
2020-02-17 21:00:18 +00:00
|
|
|
url: string;
|
2020-02-17 16:18:01 +00:00
|
|
|
iframely: FramelyData;
|
2020-02-27 17:55:23 +00:00
|
|
|
thumbnail: string;
|
2019-04-03 06:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface PostListingProps {
|
|
|
|
post: Post;
|
|
|
|
showCommunity?: boolean;
|
|
|
|
showBody?: boolean;
|
2019-04-20 07:24:59 +00:00
|
|
|
moderators?: Array<CommunityUser>;
|
|
|
|
admins?: Array<UserView>;
|
2019-04-03 06:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class PostListing extends Component<PostListingProps, PostListingState> {
|
|
|
|
private emptyState: PostListingState = {
|
2019-04-05 00:01:10 +00:00
|
|
|
showEdit: false,
|
2019-04-15 23:12:06 +00:00
|
|
|
showRemoveDialog: false,
|
|
|
|
removeReason: null,
|
2019-09-06 00:18:48 +00:00
|
|
|
showBanDialog: false,
|
|
|
|
banReason: null,
|
|
|
|
banExpires: null,
|
|
|
|
banType: BanType.Community,
|
|
|
|
showConfirmTransferSite: false,
|
|
|
|
showConfirmTransferCommunity: false,
|
|
|
|
imageExpanded: false,
|
2019-09-08 18:00:08 +00:00
|
|
|
viewSource: false,
|
2020-03-01 03:06:42 +00:00
|
|
|
showAdvanced: false,
|
2020-02-09 20:04:41 +00:00
|
|
|
my_vote: this.props.post.my_vote,
|
|
|
|
score: this.props.post.score,
|
|
|
|
upvotes: this.props.post.upvotes,
|
|
|
|
downvotes: this.props.post.downvotes,
|
2020-02-17 21:00:18 +00:00
|
|
|
url: this.props.post.url,
|
2020-02-17 16:18:01 +00:00
|
|
|
iframely: null,
|
2020-02-27 17:55:23 +00:00
|
|
|
thumbnail: null,
|
2019-10-19 00:20:27 +00:00
|
|
|
};
|
2019-04-03 06:49:32 +00:00
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
constructor(props: any, context: any) {
|
2019-04-03 06:49:32 +00:00
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
|
|
|
this.handlePostLike = this.handlePostLike.bind(this);
|
|
|
|
this.handlePostDisLike = this.handlePostDisLike.bind(this);
|
2019-04-03 20:59:37 +00:00
|
|
|
this.handleEditPost = this.handleEditPost.bind(this);
|
2019-04-05 02:08:21 +00:00
|
|
|
this.handleEditCancel = this.handleEditCancel.bind(this);
|
2020-02-17 16:18:01 +00:00
|
|
|
|
2020-02-17 21:00:18 +00:00
|
|
|
if (this.state.url) {
|
2020-02-27 17:55:23 +00:00
|
|
|
this.setThumbnail();
|
2020-02-17 16:18:01 +00:00
|
|
|
this.fetchIframely();
|
|
|
|
}
|
2019-04-03 06:49:32 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 07:29:45 +00:00
|
|
|
componentDidUpdate() {
|
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
2020-01-20 15:11:50 +00:00
|
|
|
componentWillReceiveProps(nextProps: PostListingProps) {
|
2020-02-09 20:04:41 +00:00
|
|
|
this.state.my_vote = nextProps.post.my_vote;
|
|
|
|
this.state.upvotes = nextProps.post.upvotes;
|
|
|
|
this.state.downvotes = nextProps.post.downvotes;
|
|
|
|
this.state.score = nextProps.post.score;
|
2020-02-17 21:00:18 +00:00
|
|
|
|
2020-02-18 14:00:17 +00:00
|
|
|
if (nextProps.post.url !== this.state.url) {
|
|
|
|
this.state.url = nextProps.post.url;
|
|
|
|
if (this.state.url) {
|
2020-02-27 17:55:23 +00:00
|
|
|
this.setThumbnail();
|
2020-02-18 14:00:17 +00:00
|
|
|
this.fetchIframely();
|
|
|
|
} else {
|
|
|
|
this.state.iframely = null;
|
2020-02-27 17:55:23 +00:00
|
|
|
this.state.thumbnail = null;
|
2020-02-18 14:00:17 +00:00
|
|
|
}
|
2020-02-17 21:00:18 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 20:04:41 +00:00
|
|
|
this.setState(this.state);
|
2020-01-20 00:48:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 22:29:14 +00:00
|
|
|
render() {
|
|
|
|
return (
|
2020-02-29 18:03:41 +00:00
|
|
|
<div class="">
|
2019-10-19 00:20:27 +00:00
|
|
|
{!this.state.showEdit ? (
|
2020-02-29 18:03:41 +00:00
|
|
|
<>
|
|
|
|
{this.listing()}
|
|
|
|
{this.body()}
|
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
) : (
|
2019-09-01 04:10:48 +00:00
|
|
|
<div class="col-12">
|
2019-10-19 00:20:27 +00:00
|
|
|
<PostForm
|
|
|
|
post={this.props.post}
|
|
|
|
onEdit={this.handleEditPost}
|
|
|
|
onCancel={this.handleEditCancel}
|
|
|
|
/>
|
2019-09-01 04:10:48 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2019-04-04 22:29:14 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-03 20:59:37 +00:00
|
|
|
}
|
|
|
|
|
2020-02-29 18:03:41 +00:00
|
|
|
body() {
|
|
|
|
return (
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-12">
|
|
|
|
{this.state.url && this.props.showBody && this.state.iframely && (
|
|
|
|
<IFramelyCard iframely={this.state.iframely} />
|
|
|
|
)}
|
|
|
|
{this.props.showBody && this.props.post.body && (
|
|
|
|
<>
|
|
|
|
{this.state.viewSource ? (
|
|
|
|
<pre>{this.props.post.body}</pre>
|
|
|
|
) : (
|
|
|
|
<div
|
|
|
|
className="md-div"
|
|
|
|
dangerouslySetInnerHTML={mdToHtml(this.props.post.body)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
imgThumb() {
|
2020-02-27 17:55:23 +00:00
|
|
|
let post = this.props.post;
|
|
|
|
return (
|
2020-02-29 18:03:41 +00:00
|
|
|
<img
|
2020-02-27 17:55:23 +00:00
|
|
|
className={`img-fluid thumbnail rounded ${(post.nsfw ||
|
|
|
|
post.community_nsfw) &&
|
|
|
|
'img-blur'}`}
|
2020-02-29 18:03:41 +00:00
|
|
|
src={imageThumbnailer(this.state.thumbnail)}
|
|
|
|
/>
|
2020-02-27 17:55:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-29 18:03:41 +00:00
|
|
|
thumbnail() {
|
|
|
|
let post = this.props.post;
|
|
|
|
|
|
|
|
if (isImage(this.state.url)) {
|
|
|
|
return (
|
|
|
|
<span
|
|
|
|
class="text-body pointer"
|
2020-03-03 07:29:45 +00:00
|
|
|
data-tippy-content={i18n.t('expand_here')}
|
2020-02-29 18:03:41 +00:00
|
|
|
onClick={linkEvent(this, this.handleImageExpandClick)}
|
|
|
|
>
|
|
|
|
{this.imgThumb()}
|
|
|
|
<svg class="icon mini-overlay">
|
|
|
|
<use xlinkHref="#icon-image"></use>
|
|
|
|
</svg>
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
} else if (this.state.thumbnail) {
|
|
|
|
return (
|
|
|
|
<a
|
|
|
|
className="text-body"
|
|
|
|
href={this.state.url}
|
|
|
|
target="_blank"
|
|
|
|
title={this.state.url}
|
|
|
|
>
|
|
|
|
{this.imgThumb()}
|
|
|
|
<svg class="icon mini-overlay">
|
|
|
|
<use xlinkHref="#icon-external-link"></use>
|
|
|
|
</svg>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
} else if (this.state.url && !this.state.thumbnail) {
|
|
|
|
return (
|
|
|
|
<a
|
|
|
|
className="text-body"
|
|
|
|
href={this.state.url}
|
|
|
|
target="_blank"
|
|
|
|
title={this.state.url}
|
|
|
|
>
|
|
|
|
<svg class="icon thumbnail">
|
|
|
|
<use xlinkHref="#icon-external-link"></use>
|
|
|
|
</svg>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<Link
|
|
|
|
className="text-body"
|
|
|
|
to={`/post/${post.id}`}
|
|
|
|
title={i18n.t('comments')}
|
|
|
|
>
|
|
|
|
<svg class="icon thumbnail">
|
2020-02-29 18:21:11 +00:00
|
|
|
<use xlinkHref="#icon-message-square"></use>
|
2020-02-29 18:03:41 +00:00
|
|
|
</svg>
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 20:59:37 +00:00
|
|
|
listing() {
|
2019-04-03 06:49:32 +00:00
|
|
|
let post = this.props.post;
|
|
|
|
return (
|
2020-02-29 18:03:41 +00:00
|
|
|
<div class="row">
|
|
|
|
<div className={`vote-bar col-1 pr-0 small text-center`}>
|
2019-10-19 00:20:27 +00:00
|
|
|
<button
|
2020-02-09 20:04:41 +00:00
|
|
|
className={`vote-animate btn btn-link p-0 ${
|
|
|
|
this.state.my_vote == 1 ? 'text-info' : 'text-muted'
|
2019-10-19 00:20:27 +00:00
|
|
|
}`}
|
|
|
|
onClick={linkEvent(this, this.handlePostLike)}
|
2020-03-03 07:29:45 +00:00
|
|
|
data-tippy-content={i18n.t('upvote')}
|
2019-10-19 00:20:27 +00:00
|
|
|
>
|
2020-02-09 20:04:41 +00:00
|
|
|
<svg class="icon upvote">
|
|
|
|
<use xlinkHref="#icon-arrow-up"></use>
|
|
|
|
</svg>
|
2019-08-19 22:32:32 +00:00
|
|
|
</button>
|
2020-03-03 07:29:45 +00:00
|
|
|
<div class={`unselectable font-weight-bold text-muted px-1`}>
|
2020-03-01 02:04:42 +00:00
|
|
|
{this.state.score}
|
|
|
|
</div>
|
2019-12-11 20:21:47 +00:00
|
|
|
{WebSocketService.Instance.site.enable_downvotes && (
|
|
|
|
<button
|
2020-02-09 20:04:41 +00:00
|
|
|
className={`vote-animate btn btn-link p-0 ${
|
|
|
|
this.state.my_vote == -1 ? 'text-danger' : 'text-muted'
|
2019-12-11 20:21:47 +00:00
|
|
|
}`}
|
|
|
|
onClick={linkEvent(this, this.handlePostDisLike)}
|
2020-03-03 07:29:45 +00:00
|
|
|
data-tippy-content={i18n.t('downvote')}
|
2019-12-11 20:21:47 +00:00
|
|
|
>
|
2020-02-09 20:04:41 +00:00
|
|
|
<svg class="icon downvote">
|
|
|
|
<use xlinkHref="#icon-arrow-down"></use>
|
|
|
|
</svg>
|
2019-12-11 20:21:47 +00:00
|
|
|
</button>
|
|
|
|
)}
|
2019-04-03 06:49:32 +00:00
|
|
|
</div>
|
2020-02-29 18:03:41 +00:00
|
|
|
{!this.state.imageExpanded && (
|
2020-03-01 23:19:48 +00:00
|
|
|
<div class="col-3 col-sm-2 pr-0 mt-1">
|
2020-02-29 18:03:41 +00:00
|
|
|
<div class="position-relative">{this.thumbnail()}</div>
|
2020-02-21 16:26:42 +00:00
|
|
|
</div>
|
2020-01-20 19:38:41 +00:00
|
|
|
)}
|
2020-02-17 21:00:18 +00:00
|
|
|
{this.state.url && isVideo(this.state.url) && (
|
2019-10-19 00:20:27 +00:00
|
|
|
<video
|
|
|
|
playsinline
|
|
|
|
muted
|
|
|
|
loop
|
|
|
|
controls
|
2020-03-01 02:04:42 +00:00
|
|
|
class="col-11 col-sm-2 pr-0 mt-1"
|
2019-10-19 00:20:27 +00:00
|
|
|
height="100"
|
|
|
|
width="150"
|
|
|
|
>
|
2020-02-17 21:00:18 +00:00
|
|
|
<source src={this.state.url} type="video/mp4" />
|
2019-09-08 03:42:01 +00:00
|
|
|
</video>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2020-03-02 15:48:06 +00:00
|
|
|
<div
|
|
|
|
class={`${this.state.imageExpanded ? 'col-12' : 'col-8 col-sm-9'}`}
|
|
|
|
>
|
2020-02-29 18:03:41 +00:00
|
|
|
<div class="row">
|
|
|
|
<div className="col-12">
|
|
|
|
<div className="post-title">
|
|
|
|
<h5 className="mb-0 d-inline">
|
|
|
|
{this.props.showBody && this.state.url ? (
|
|
|
|
<a
|
|
|
|
className="text-body"
|
|
|
|
href={this.state.url}
|
|
|
|
target="_blank"
|
|
|
|
title={this.state.url}
|
2019-10-19 00:20:27 +00:00
|
|
|
>
|
2020-02-29 18:03:41 +00:00
|
|
|
{post.name}
|
|
|
|
</a>
|
|
|
|
) : (
|
|
|
|
<Link
|
|
|
|
className="text-body"
|
|
|
|
to={`/post/${post.id}`}
|
|
|
|
title={i18n.t('comments')}
|
|
|
|
>
|
|
|
|
{post.name}
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
</h5>
|
|
|
|
{this.state.url &&
|
|
|
|
!(
|
|
|
|
new URL(this.state.url).hostname == window.location.hostname
|
|
|
|
) && (
|
|
|
|
<small class="d-inline-block">
|
|
|
|
<a
|
|
|
|
className="ml-2 text-muted font-italic"
|
|
|
|
href={this.state.url}
|
|
|
|
target="_blank"
|
|
|
|
title={this.state.url}
|
|
|
|
>
|
|
|
|
{new URL(this.state.url).hostname}
|
|
|
|
<svg class="ml-1 icon">
|
|
|
|
<use xlinkHref="#icon-external-link"></use>
|
|
|
|
</svg>
|
|
|
|
</a>
|
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
{this.state.thumbnail && (
|
|
|
|
<>
|
|
|
|
{!this.state.imageExpanded ? (
|
2019-10-19 00:20:27 +00:00
|
|
|
<span
|
2020-03-03 07:29:45 +00:00
|
|
|
class="text-monospace unselectable pointer ml-2 text-muted small"
|
|
|
|
data-tippy-content={i18n.t('expand_here')}
|
2019-10-19 00:20:27 +00:00
|
|
|
onClick={linkEvent(this, this.handleImageExpandClick)}
|
|
|
|
>
|
2020-02-29 18:03:41 +00:00
|
|
|
[+]
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span>
|
|
|
|
<span
|
2020-03-03 07:29:45 +00:00
|
|
|
class="text-monospace unselectable pointer ml-2 text-muted small"
|
2020-02-29 18:03:41 +00:00
|
|
|
onClick={linkEvent(this, this.handleImageExpandClick)}
|
2020-02-24 22:38:05 +00:00
|
|
|
>
|
2020-02-29 18:03:41 +00:00
|
|
|
[-]
|
|
|
|
</span>
|
|
|
|
<div>
|
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleImageExpandClick
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
class="img-fluid img-expanded"
|
|
|
|
src={this.state.thumbnail}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
</span>
|
2020-02-29 18:03:41 +00:00
|
|
|
)}
|
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2020-02-29 18:03:41 +00:00
|
|
|
{post.removed && (
|
|
|
|
<small className="ml-2 text-muted font-italic">
|
|
|
|
{i18n.t('removed')}
|
|
|
|
</small>
|
2019-12-29 20:39:48 +00:00
|
|
|
)}
|
2020-02-29 18:03:41 +00:00
|
|
|
{post.deleted && (
|
|
|
|
<small className="ml-2 text-muted font-italic">
|
|
|
|
{i18n.t('deleted')}
|
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
{post.locked && (
|
|
|
|
<small className="ml-2 text-muted font-italic">
|
|
|
|
{i18n.t('locked')}
|
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
{post.stickied && (
|
|
|
|
<small className="ml-2 text-muted font-italic">
|
|
|
|
{i18n.t('stickied')}
|
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
{post.nsfw && (
|
|
|
|
<small className="ml-2 text-muted font-italic">
|
|
|
|
{i18n.t('nsfw')}
|
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row">
|
|
|
|
<div className="details col-12">
|
|
|
|
<ul class="list-inline mb-0 text-muted small">
|
|
|
|
<li className="list-inline-item">
|
|
|
|
<span>{i18n.t('by')} </span>
|
|
|
|
<Link className="text-info" to={`/u/${post.creator_name}`}>
|
|
|
|
{post.creator_avatar && showAvatars() && (
|
|
|
|
<img
|
|
|
|
height="32"
|
|
|
|
width="32"
|
|
|
|
src={pictshareAvatarThumbnail(post.creator_avatar)}
|
|
|
|
class="rounded-circle mr-1"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<span>{post.creator_name}</span>
|
2019-10-19 00:20:27 +00:00
|
|
|
</Link>
|
2020-02-29 18:03:41 +00:00
|
|
|
{this.isMod && (
|
|
|
|
<span className="mx-1 badge badge-light">
|
|
|
|
{i18n.t('mod')}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{this.isAdmin && (
|
|
|
|
<span className="mx-1 badge badge-light">
|
|
|
|
{i18n.t('admin')}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{(post.banned_from_community || post.banned) && (
|
|
|
|
<span className="mx-1 badge badge-danger">
|
|
|
|
{i18n.t('banned')}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{this.props.showCommunity && (
|
|
|
|
<span>
|
|
|
|
<span> {i18n.t('to')} </span>
|
|
|
|
<Link to={`/c/${post.community_name}`}>
|
|
|
|
{post.community_name}
|
2019-10-19 00:20:27 +00:00
|
|
|
</Link>
|
2020-02-29 18:03:41 +00:00
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</li>
|
|
|
|
<li className="list-inline-item">
|
|
|
|
<span>
|
|
|
|
<MomentTime data={post} />
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
<li className="list-inline-item">
|
2020-03-03 07:29:45 +00:00
|
|
|
<span className="text-info">
|
|
|
|
<svg class="small icon icon-inline mr-1">
|
|
|
|
<use xlinkHref="#icon-arrow-up"></use>
|
|
|
|
</svg>
|
|
|
|
{this.state.upvotes}
|
2020-02-29 18:03:41 +00:00
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
<li className="list-inline-item">
|
2020-03-03 07:29:45 +00:00
|
|
|
<span className="text-danger">
|
|
|
|
<svg class="small icon icon-inline mr-1">
|
|
|
|
<use xlinkHref="#icon-arrow-down"></use>
|
|
|
|
</svg>
|
|
|
|
{this.state.downvotes}
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
<li className="list-inline-item">
|
|
|
|
<Link
|
|
|
|
className="text-muted"
|
|
|
|
title={i18n.t('number_of_comments', {
|
2020-02-29 18:03:41 +00:00
|
|
|
count: post.number_of_comments,
|
|
|
|
})}
|
2020-03-03 07:29:45 +00:00
|
|
|
to={`/post/${post.id}`}
|
|
|
|
>
|
|
|
|
<svg class="mr-1 icon icon-inline">
|
|
|
|
<use xlinkHref="#icon-message-square"></use>
|
|
|
|
</svg>
|
|
|
|
{post.number_of_comments}
|
2020-02-29 18:03:41 +00:00
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2020-03-03 14:16:36 +00:00
|
|
|
<ul class="list-inline mb-1 small text-muted">
|
2020-02-29 18:03:41 +00:00
|
|
|
{this.props.post.duplicates && (
|
2019-09-08 18:00:08 +00:00
|
|
|
<>
|
|
|
|
<li className="list-inline-item mr-2">
|
2020-02-29 18:03:41 +00:00
|
|
|
{i18n.t('cross_posted_to')}
|
2019-09-06 00:18:48 +00:00
|
|
|
</li>
|
2020-02-29 18:03:41 +00:00
|
|
|
{this.props.post.duplicates.map(post => (
|
|
|
|
<li className="list-inline-item mr-2">
|
|
|
|
<Link to={`/post/${post.id}`}>
|
|
|
|
{post.community_name}
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
2019-09-08 18:00:08 +00:00
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2020-02-29 18:03:41 +00:00
|
|
|
</ul>
|
2020-03-03 07:29:45 +00:00
|
|
|
<ul class="list-inline mb-1 text-muted h6 font-weight-bold">
|
2020-02-29 18:03:41 +00:00
|
|
|
{UserService.Instance.user && (
|
2019-09-08 18:00:08 +00:00
|
|
|
<>
|
2020-02-29 18:03:41 +00:00
|
|
|
{this.props.showBody && (
|
|
|
|
<>
|
2020-03-03 07:29:45 +00:00
|
|
|
<li className="list-inline-item-action">
|
2020-02-29 18:03:41 +00:00
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(this, this.handleSavePostClick)}
|
2020-03-03 07:29:45 +00:00
|
|
|
data-tippy-content={
|
|
|
|
post.saved ? i18n.t('unsave') : i18n.t('save')
|
|
|
|
}
|
2020-02-29 18:03:41 +00:00
|
|
|
>
|
2020-03-03 07:29:45 +00:00
|
|
|
<svg
|
|
|
|
class={`icon icon-inline ${post.saved &&
|
|
|
|
'text-warning'}`}
|
|
|
|
>
|
|
|
|
<use xlinkHref="#icon-star"></use>
|
|
|
|
</svg>
|
2020-02-29 18:03:41 +00:00
|
|
|
</span>
|
|
|
|
</li>
|
2020-03-03 07:29:45 +00:00
|
|
|
<li className="list-inline-item-action">
|
2020-02-29 18:03:41 +00:00
|
|
|
<Link
|
|
|
|
className="text-muted"
|
|
|
|
to={`/create_post${this.crossPostParams}`}
|
2020-03-03 07:29:45 +00:00
|
|
|
title={i18n.t('cross_post')}
|
2020-02-29 18:03:41 +00:00
|
|
|
>
|
2020-03-03 07:29:45 +00:00
|
|
|
<svg class="icon icon-inline">
|
|
|
|
<use xlinkHref="#icon-copy"></use>
|
|
|
|
</svg>
|
2020-02-29 18:03:41 +00:00
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2020-02-29 18:03:41 +00:00
|
|
|
{this.myPost && this.props.showBody && (
|
|
|
|
<>
|
2020-03-03 07:29:45 +00:00
|
|
|
<li className="list-inline-item-action">
|
2020-02-29 18:03:41 +00:00
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(this, this.handleEditClick)}
|
2020-03-03 07:29:45 +00:00
|
|
|
data-tippy-content={i18n.t('edit')}
|
2020-02-29 18:03:41 +00:00
|
|
|
>
|
2020-03-03 07:29:45 +00:00
|
|
|
<svg class="icon icon-inline">
|
|
|
|
<use xlinkHref="#icon-edit"></use>
|
|
|
|
</svg>
|
2020-02-29 18:03:41 +00:00
|
|
|
</span>
|
|
|
|
</li>
|
2020-03-03 07:29:45 +00:00
|
|
|
<li className="list-inline-item-action">
|
2020-02-29 18:03:41 +00:00
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(this, this.handleDeleteClick)}
|
2020-03-03 07:29:45 +00:00
|
|
|
data-tippy-content={
|
|
|
|
!post.deleted
|
|
|
|
? i18n.t('delete')
|
|
|
|
: i18n.t('restore')
|
|
|
|
}
|
2020-02-29 18:03:41 +00:00
|
|
|
>
|
2020-03-03 07:29:45 +00:00
|
|
|
<svg
|
|
|
|
class={`icon icon-inline ${post.deleted &&
|
|
|
|
'text-danger'}`}
|
|
|
|
>
|
|
|
|
<use xlinkHref="#icon-trash"></use>
|
|
|
|
</svg>
|
2020-02-29 18:03:41 +00:00
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
</>
|
|
|
|
)}
|
2020-03-01 03:06:42 +00:00
|
|
|
|
|
|
|
{!this.state.showAdvanced && this.props.showBody ? (
|
2020-03-03 07:29:45 +00:00
|
|
|
<li className="list-inline-item-action">
|
2020-03-01 03:06:42 +00:00
|
|
|
<span
|
|
|
|
className="pointer"
|
|
|
|
onClick={linkEvent(this, this.handleShowAdvanced)}
|
2020-03-03 07:29:45 +00:00
|
|
|
data-tippy-content={i18n.t('more')}
|
2020-03-01 03:06:42 +00:00
|
|
|
>
|
2020-03-03 07:29:45 +00:00
|
|
|
<svg class="icon icon-inline">
|
|
|
|
<use xlinkHref="#icon-more-vertical"></use>
|
|
|
|
</svg>
|
2020-03-01 03:06:42 +00:00
|
|
|
</span>
|
2019-09-08 18:00:08 +00:00
|
|
|
</li>
|
2020-03-01 03:06:42 +00:00
|
|
|
) : (
|
2019-10-19 00:20:27 +00:00
|
|
|
<>
|
2020-03-01 03:16:52 +00:00
|
|
|
{this.props.showBody && post.body && (
|
2020-03-03 07:29:45 +00:00
|
|
|
<li className="list-inline-item-action">
|
2020-03-01 03:16:52 +00:00
|
|
|
<span
|
|
|
|
className="pointer"
|
|
|
|
onClick={linkEvent(this, this.handleViewSource)}
|
2020-03-03 15:14:50 +00:00
|
|
|
data-tippy-content={i18n.t('view_source')}
|
2020-03-01 03:16:52 +00:00
|
|
|
>
|
2020-03-03 15:14:50 +00:00
|
|
|
<svg
|
|
|
|
class={`icon icon-inline ${this.state
|
|
|
|
.viewSource && 'text-success'}`}
|
|
|
|
>
|
|
|
|
<use xlinkHref="#icon-eye"></use>
|
|
|
|
</svg>
|
2020-03-01 03:16:52 +00:00
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
)}
|
2020-03-01 03:06:42 +00:00
|
|
|
{this.canModOnSelf && (
|
|
|
|
<>
|
2020-03-03 07:29:45 +00:00
|
|
|
<li className="list-inline-item-action">
|
2020-03-01 03:06:42 +00:00
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(this, this.handleModLock)}
|
2020-03-03 07:29:45 +00:00
|
|
|
data-tippy-content={
|
|
|
|
post.locked
|
|
|
|
? i18n.t('unlock')
|
|
|
|
: i18n.t('lock')
|
|
|
|
}
|
2020-03-01 03:06:42 +00:00
|
|
|
>
|
2020-03-03 07:29:45 +00:00
|
|
|
<svg
|
|
|
|
class={`icon icon-inline ${post.locked &&
|
|
|
|
'text-danger'}`}
|
|
|
|
>
|
|
|
|
<use xlinkHref="#icon-lock"></use>
|
|
|
|
</svg>
|
2020-03-01 03:06:42 +00:00
|
|
|
</span>
|
|
|
|
</li>
|
2020-03-03 07:29:45 +00:00
|
|
|
<li className="list-inline-item-action">
|
2020-03-01 03:06:42 +00:00
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(this, this.handleModSticky)}
|
2020-03-03 07:29:45 +00:00
|
|
|
data-tippy-content={
|
|
|
|
post.stickied
|
|
|
|
? i18n.t('unsticky')
|
|
|
|
: i18n.t('sticky')
|
|
|
|
}
|
2020-03-01 03:06:42 +00:00
|
|
|
>
|
2020-03-03 07:29:45 +00:00
|
|
|
<svg
|
|
|
|
class={`icon icon-inline ${post.stickied &&
|
|
|
|
'text-success'}`}
|
|
|
|
>
|
|
|
|
<use xlinkHref="#icon-pin"></use>
|
|
|
|
</svg>
|
2020-03-01 03:06:42 +00:00
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{/* Mods can ban from community, and appoint as mods to community */}
|
|
|
|
{(this.canMod || this.canAdmin) && (
|
2020-02-29 18:03:41 +00:00
|
|
|
<li className="list-inline-item">
|
2020-03-01 03:06:42 +00:00
|
|
|
{!post.removed ? (
|
2020-02-29 18:03:41 +00:00
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2020-03-01 03:06:42 +00:00
|
|
|
this.handleModRemoveShow
|
2020-02-29 18:03:41 +00:00
|
|
|
)}
|
|
|
|
>
|
2020-03-01 03:06:42 +00:00
|
|
|
{i18n.t('remove')}
|
2020-02-29 18:03:41 +00:00
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2020-03-01 03:06:42 +00:00
|
|
|
this.handleModRemoveSubmit
|
2020-02-29 18:03:41 +00:00
|
|
|
)}
|
|
|
|
>
|
2020-03-01 03:06:42 +00:00
|
|
|
{i18n.t('restore')}
|
2020-02-29 18:03:41 +00:00
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</li>
|
|
|
|
)}
|
2020-03-01 03:06:42 +00:00
|
|
|
{this.canMod && (
|
2020-02-29 18:03:41 +00:00
|
|
|
<>
|
2020-03-01 03:06:42 +00:00
|
|
|
{!this.isMod && (
|
|
|
|
<li className="list-inline-item">
|
|
|
|
{!post.banned_from_community ? (
|
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModBanFromCommunityShow
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('ban')}
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModBanFromCommunitySubmit
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('unban')}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
{!post.banned_from_community && (
|
|
|
|
<li className="list-inline-item">
|
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleAddModToCommunity
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{this.isMod
|
|
|
|
? i18n.t('remove_as_mod')
|
|
|
|
: i18n.t('appoint_as_mod')}
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{/* Community creators and admins can transfer community to another mod */}
|
|
|
|
{(this.amCommunityCreator || this.canAdmin) &&
|
|
|
|
this.isMod && (
|
|
|
|
<li className="list-inline-item">
|
|
|
|
{!this.state.showConfirmTransferCommunity ? (
|
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleShowConfirmTransferCommunity
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('transfer_community')}
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<span class="d-inline-block mr-1">
|
|
|
|
{i18n.t('are_you_sure')}
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
class="pointer d-inline-block mr-1"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleTransferCommunity
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('yes')}
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
class="pointer d-inline-block"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this
|
|
|
|
.handleCancelShowConfirmTransferCommunity
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('no')}
|
|
|
|
</span>
|
|
|
|
</>
|
2020-02-29 18:03:41 +00:00
|
|
|
)}
|
2020-03-01 03:06:42 +00:00
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
{/* Admins can ban from all, and appoint other admins */}
|
|
|
|
{this.canAdmin && (
|
|
|
|
<>
|
|
|
|
{!this.isAdmin && (
|
|
|
|
<li className="list-inline-item">
|
|
|
|
{!post.banned ? (
|
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModBanShow
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('ban_from_site')}
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleModBanSubmit
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('unban_from_site')}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
{!post.banned && (
|
|
|
|
<li className="list-inline-item">
|
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(this, this.handleAddAdmin)}
|
|
|
|
>
|
|
|
|
{this.isAdmin
|
|
|
|
? i18n.t('remove_as_admin')
|
|
|
|
: i18n.t('appoint_as_admin')}
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
)}
|
2020-02-29 18:03:41 +00:00
|
|
|
</>
|
|
|
|
)}
|
2020-03-01 03:06:42 +00:00
|
|
|
{/* Site Creator can transfer to another admin */}
|
|
|
|
{this.amSiteCreator && this.isAdmin && (
|
2020-02-29 18:03:41 +00:00
|
|
|
<li className="list-inline-item">
|
2020-03-01 03:06:42 +00:00
|
|
|
{!this.state.showConfirmTransferSite ? (
|
2020-02-29 18:03:41 +00:00
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
2020-03-01 03:06:42 +00:00
|
|
|
this.handleShowConfirmTransferSite
|
2020-02-29 18:03:41 +00:00
|
|
|
)}
|
|
|
|
>
|
2020-03-01 03:06:42 +00:00
|
|
|
{i18n.t('transfer_site')}
|
2020-02-29 18:03:41 +00:00
|
|
|
</span>
|
2020-03-01 03:06:42 +00:00
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<span class="d-inline-block mr-1">
|
|
|
|
{i18n.t('are_you_sure')}
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
class="pointer d-inline-block mr-1"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleTransferSite
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('yes')}
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
class="pointer d-inline-block"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleCancelShowConfirmTransferSite
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n.t('no')}
|
|
|
|
</span>
|
|
|
|
</>
|
2020-02-29 18:03:41 +00:00
|
|
|
)}
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
2019-09-08 18:00:08 +00:00
|
|
|
</>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2020-02-29 18:03:41 +00:00
|
|
|
</ul>
|
|
|
|
{this.state.showRemoveDialog && (
|
|
|
|
<form
|
|
|
|
class="form-inline"
|
|
|
|
onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
|
2019-10-19 00:20:27 +00:00
|
|
|
>
|
2020-02-29 18:03:41 +00:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
class="form-control mr-2"
|
|
|
|
placeholder={i18n.t('reason')}
|
|
|
|
value={this.state.removeReason}
|
|
|
|
onInput={linkEvent(this, this.handleModRemoveReasonChange)}
|
|
|
|
/>
|
|
|
|
<button type="submit" class="btn btn-secondary">
|
|
|
|
{i18n.t('remove_post')}
|
|
|
|
</button>
|
|
|
|
</form>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2020-02-29 18:03:41 +00:00
|
|
|
{this.state.showBanDialog && (
|
|
|
|
<form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-form-label" htmlFor="post-listing-reason">
|
|
|
|
{i18n.t('reason')}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="post-listing-reason"
|
|
|
|
class="form-control mr-2"
|
|
|
|
placeholder={i18n.t('reason')}
|
|
|
|
value={this.state.banReason}
|
|
|
|
onInput={linkEvent(this, this.handleModBanReasonChange)}
|
|
|
|
/>
|
|
|
|
</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> */}
|
|
|
|
<div class="form-group row">
|
|
|
|
<button type="submit" class="btn btn-secondary">
|
|
|
|
{i18n.t('ban')} {post.creator_name}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-04-03 06:49:32 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-03 06:49:32 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 20:59:37 +00:00
|
|
|
private get myPost(): boolean {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
UserService.Instance.user &&
|
|
|
|
this.props.post.creator_id == UserService.Instance.user.id
|
|
|
|
);
|
2019-04-03 20:59:37 +00:00
|
|
|
}
|
2019-04-03 06:49:32 +00:00
|
|
|
|
2019-04-21 20:52:55 +00:00
|
|
|
get isMod(): boolean {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
this.props.moderators &&
|
|
|
|
isMod(
|
|
|
|
this.props.moderators.map(m => m.user_id),
|
|
|
|
this.props.post.creator_id
|
|
|
|
)
|
|
|
|
);
|
2019-04-21 20:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get isAdmin(): boolean {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
this.props.admins &&
|
2020-01-14 03:57:32 +00:00
|
|
|
isMod(
|
|
|
|
this.props.admins.map(a => a.id),
|
|
|
|
this.props.post.creator_id
|
|
|
|
)
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-21 20:52:55 +00:00
|
|
|
}
|
|
|
|
|
2019-04-20 07:24:59 +00:00
|
|
|
get canMod(): boolean {
|
2019-10-14 00:36:35 +00:00
|
|
|
if (this.props.admins && this.props.moderators) {
|
2019-10-19 00:20:27 +00:00
|
|
|
let adminsThenMods = this.props.admins
|
|
|
|
.map(a => a.id)
|
|
|
|
.concat(this.props.moderators.map(m => m.user_id));
|
|
|
|
|
|
|
|
return canMod(
|
|
|
|
UserService.Instance.user,
|
|
|
|
adminsThenMods,
|
|
|
|
this.props.post.creator_id
|
|
|
|
);
|
|
|
|
} else {
|
2019-10-14 00:36:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-09-09 19:58:04 +00:00
|
|
|
}
|
2019-04-20 07:24:59 +00:00
|
|
|
|
2019-09-09 19:58:04 +00:00
|
|
|
get canModOnSelf(): boolean {
|
2019-10-14 00:36:35 +00:00
|
|
|
if (this.props.admins && this.props.moderators) {
|
2019-10-19 00:20:27 +00:00
|
|
|
let adminsThenMods = this.props.admins
|
|
|
|
.map(a => a.id)
|
|
|
|
.concat(this.props.moderators.map(m => m.user_id));
|
|
|
|
|
|
|
|
return canMod(
|
|
|
|
UserService.Instance.user,
|
|
|
|
adminsThenMods,
|
|
|
|
this.props.post.creator_id,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
} else {
|
2019-10-14 00:36:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-20 07:24:59 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 00:18:48 +00:00
|
|
|
get canAdmin(): boolean {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
this.props.admins &&
|
|
|
|
canMod(
|
|
|
|
UserService.Instance.user,
|
|
|
|
this.props.admins.map(a => a.id),
|
|
|
|
this.props.post.creator_id
|
|
|
|
)
|
|
|
|
);
|
2019-09-06 00:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get amCommunityCreator(): boolean {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
this.props.moderators &&
|
|
|
|
UserService.Instance.user &&
|
|
|
|
this.props.post.creator_id != UserService.Instance.user.id &&
|
|
|
|
UserService.Instance.user.id == this.props.moderators[0].user_id
|
|
|
|
);
|
2019-09-06 00:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get amSiteCreator(): boolean {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
this.props.admins &&
|
|
|
|
UserService.Instance.user &&
|
|
|
|
this.props.post.creator_id != UserService.Instance.user.id &&
|
|
|
|
UserService.Instance.user.id == this.props.admins[0].id
|
|
|
|
);
|
2019-09-06 00:18:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 16:18:01 +00:00
|
|
|
fetchIframely() {
|
2020-02-17 21:00:18 +00:00
|
|
|
fetch(`/iframely/oembed?url=${this.state.url}`)
|
2020-02-17 16:18:01 +00:00
|
|
|
.then(res => res.json())
|
|
|
|
.then(res => {
|
|
|
|
this.state.iframely = res;
|
|
|
|
this.setState(this.state);
|
2020-02-27 17:55:23 +00:00
|
|
|
|
|
|
|
// Store and fetch the image in pictshare
|
|
|
|
if (
|
|
|
|
this.state.iframely.thumbnail_url &&
|
|
|
|
isImage(this.state.iframely.thumbnail_url)
|
|
|
|
) {
|
|
|
|
fetch(
|
|
|
|
`/pictshare/api/geturl.php?url=${this.state.iframely.thumbnail_url}`
|
|
|
|
)
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(res => {
|
2020-02-27 19:06:29 +00:00
|
|
|
if (res.status == 'ok') {
|
|
|
|
let url = `${window.location.origin}/pictshare/${res.url}`;
|
|
|
|
if (res.filetype == 'mp4') {
|
|
|
|
url += '/raw';
|
|
|
|
}
|
|
|
|
this.state.thumbnail = url;
|
|
|
|
this.setState(this.state);
|
|
|
|
} else {
|
|
|
|
console.error(
|
|
|
|
`Couldn't cache pictshare url: ${this.state.iframely.thumbnail_url}`
|
|
|
|
);
|
|
|
|
console.error(res);
|
2020-02-27 17:55:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-02-17 16:18:01 +00:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(`Iframely service not set up properly. ${error}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-27 17:55:23 +00:00
|
|
|
setThumbnail() {
|
2020-02-17 21:00:18 +00:00
|
|
|
let simpleImg = isImage(this.state.url);
|
2020-02-17 16:18:01 +00:00
|
|
|
if (simpleImg) {
|
2020-02-27 17:55:23 +00:00
|
|
|
this.state.thumbnail = this.state.url;
|
|
|
|
} else {
|
|
|
|
this.state.thumbnail = null;
|
2020-02-17 16:18:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
handlePostLike(i: PostListing) {
|
2020-02-09 20:04:41 +00:00
|
|
|
let new_vote = i.state.my_vote == 1 ? 0 : 1;
|
|
|
|
|
|
|
|
if (i.state.my_vote == 1) {
|
|
|
|
i.state.score--;
|
|
|
|
i.state.upvotes--;
|
|
|
|
} else if (i.state.my_vote == -1) {
|
|
|
|
i.state.downvotes--;
|
|
|
|
i.state.upvotes++;
|
|
|
|
i.state.score += 2;
|
|
|
|
} else {
|
|
|
|
i.state.upvotes++;
|
|
|
|
i.state.score++;
|
2020-01-25 18:39:22 +00:00
|
|
|
}
|
2020-01-14 03:57:32 +00:00
|
|
|
|
2020-02-09 20:04:41 +00:00
|
|
|
i.state.my_vote = new_vote;
|
|
|
|
|
2019-04-03 06:49:32 +00:00
|
|
|
let form: CreatePostLikeForm = {
|
|
|
|
post_id: i.props.post.id,
|
2020-02-09 20:04:41 +00:00
|
|
|
score: i.state.my_vote,
|
2019-04-03 06:49:32 +00:00
|
|
|
};
|
2020-01-25 18:39:22 +00:00
|
|
|
|
2019-04-03 06:49:32 +00:00
|
|
|
WebSocketService.Instance.likePost(form);
|
2020-02-09 20:04:41 +00:00
|
|
|
i.setState(i.state);
|
2019-04-03 06:49:32 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
handlePostDisLike(i: PostListing) {
|
2020-02-09 20:04:41 +00:00
|
|
|
let new_vote = i.state.my_vote == -1 ? 0 : -1;
|
|
|
|
|
|
|
|
if (i.state.my_vote == 1) {
|
|
|
|
i.state.score -= 2;
|
|
|
|
i.state.upvotes--;
|
|
|
|
i.state.downvotes++;
|
|
|
|
} else if (i.state.my_vote == -1) {
|
|
|
|
i.state.downvotes--;
|
|
|
|
i.state.score++;
|
|
|
|
} else {
|
|
|
|
i.state.downvotes++;
|
|
|
|
i.state.score--;
|
2020-01-25 18:39:22 +00:00
|
|
|
}
|
2020-01-14 03:57:32 +00:00
|
|
|
|
2020-02-09 20:04:41 +00:00
|
|
|
i.state.my_vote = new_vote;
|
|
|
|
|
2019-04-03 06:49:32 +00:00
|
|
|
let form: CreatePostLikeForm = {
|
|
|
|
post_id: i.props.post.id,
|
2020-02-09 20:04:41 +00:00
|
|
|
score: i.state.my_vote,
|
2019-04-03 06:49:32 +00:00
|
|
|
};
|
2020-02-09 20:04:41 +00:00
|
|
|
|
2019-04-03 06:49:32 +00:00
|
|
|
WebSocketService.Instance.likePost(form);
|
2020-02-09 20:04:41 +00:00
|
|
|
i.setState(i.state);
|
2019-04-03 06:49:32 +00:00
|
|
|
}
|
2019-04-03 20:59:37 +00:00
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
handleEditClick(i: PostListing) {
|
2019-04-03 20:59:37 +00:00
|
|
|
i.state.showEdit = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-04-05 02:08:21 +00:00
|
|
|
handleEditCancel() {
|
|
|
|
this.state.showEdit = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
2019-04-04 22:29:14 +00:00
|
|
|
// The actual editing is done in the recieve for post
|
2019-04-08 05:19:02 +00:00
|
|
|
handleEditPost() {
|
2019-04-03 20:59:37 +00:00
|
|
|
this.state.showEdit = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
handleDeleteClick(i: PostListing) {
|
2019-04-03 20:59:37 +00:00
|
|
|
let deleteForm: PostFormI = {
|
2019-04-29 19:14:54 +00:00
|
|
|
body: i.props.post.body,
|
2019-04-03 20:59:37 +00:00
|
|
|
community_id: i.props.post.community_id,
|
2019-04-29 19:14:54 +00:00
|
|
|
name: i.props.post.name,
|
|
|
|
url: i.props.post.url,
|
2019-04-03 20:59:37 +00:00
|
|
|
edit_id: i.props.post.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
creator_id: i.props.post.creator_id,
|
2019-04-29 19:14:54 +00:00
|
|
|
deleted: !i.props.post.deleted,
|
2019-08-14 02:52:43 +00:00
|
|
|
nsfw: i.props.post.nsfw,
|
2019-10-19 00:20:27 +00:00
|
|
|
auth: null,
|
2019-04-03 20:59:37 +00:00
|
|
|
};
|
|
|
|
WebSocketService.Instance.editPost(deleteForm);
|
|
|
|
}
|
2019-04-05 00:01:10 +00:00
|
|
|
|
2019-04-20 04:06:25 +00:00
|
|
|
handleSavePostClick(i: PostListing) {
|
2019-10-19 00:20:27 +00:00
|
|
|
let saved = i.props.post.saved == undefined ? true : !i.props.post.saved;
|
2019-04-20 04:06:25 +00:00
|
|
|
let form: SavePostForm = {
|
|
|
|
post_id: i.props.post.id,
|
2019-10-19 00:20:27 +00:00
|
|
|
save: saved,
|
2019-04-20 04:06:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
WebSocketService.Instance.savePost(form);
|
|
|
|
}
|
|
|
|
|
2019-08-22 23:13:26 +00:00
|
|
|
get crossPostParams(): string {
|
2020-01-20 16:08:51 +00:00
|
|
|
let params = `?title=${this.props.post.name}`;
|
2020-02-17 21:00:18 +00:00
|
|
|
if (this.state.url) {
|
|
|
|
params += `&url=${this.state.url}`;
|
2019-08-22 18:46:54 +00:00
|
|
|
}
|
2019-08-22 23:13:26 +00:00
|
|
|
if (this.props.post.body) {
|
|
|
|
params += `&body=${this.props.post.body}`;
|
2019-08-22 18:46:54 +00:00
|
|
|
}
|
2019-08-22 23:13:26 +00:00
|
|
|
return params;
|
2019-08-22 18:46:54 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 23:12:06 +00:00
|
|
|
handleModRemoveShow(i: PostListing) {
|
|
|
|
i.state.showRemoveDialog = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveReasonChange(i: PostListing, event: any) {
|
|
|
|
i.state.removeReason = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveSubmit(i: PostListing) {
|
2019-04-16 23:04:23 +00:00
|
|
|
event.preventDefault();
|
2019-04-15 23:12:06 +00:00
|
|
|
let form: PostFormI = {
|
|
|
|
name: i.props.post.name,
|
|
|
|
community_id: i.props.post.community_id,
|
|
|
|
edit_id: i.props.post.id,
|
|
|
|
creator_id: i.props.post.creator_id,
|
|
|
|
removed: !i.props.post.removed,
|
|
|
|
reason: i.state.removeReason,
|
2019-08-14 02:52:43 +00:00
|
|
|
nsfw: i.props.post.nsfw,
|
2019-04-15 23:12:06 +00:00
|
|
|
auth: null,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.editPost(form);
|
|
|
|
|
|
|
|
i.state.showRemoveDialog = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModLock(i: PostListing) {
|
|
|
|
let form: PostFormI = {
|
|
|
|
name: i.props.post.name,
|
|
|
|
community_id: i.props.post.community_id,
|
|
|
|
edit_id: i.props.post.id,
|
|
|
|
creator_id: i.props.post.creator_id,
|
2019-08-14 02:52:43 +00:00
|
|
|
nsfw: i.props.post.nsfw,
|
2019-04-15 23:12:06 +00:00
|
|
|
locked: !i.props.post.locked,
|
|
|
|
auth: null,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.editPost(form);
|
|
|
|
}
|
|
|
|
|
2019-09-09 06:14:13 +00:00
|
|
|
handleModSticky(i: PostListing) {
|
|
|
|
let form: PostFormI = {
|
|
|
|
name: i.props.post.name,
|
|
|
|
community_id: i.props.post.community_id,
|
|
|
|
edit_id: i.props.post.id,
|
|
|
|
creator_id: i.props.post.creator_id,
|
|
|
|
nsfw: i.props.post.nsfw,
|
|
|
|
stickied: !i.props.post.stickied,
|
|
|
|
auth: null,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.editPost(form);
|
|
|
|
}
|
|
|
|
|
2019-09-06 00:18:48 +00:00
|
|
|
handleModBanFromCommunityShow(i: PostListing) {
|
|
|
|
i.state.showBanDialog = true;
|
|
|
|
i.state.banType = BanType.Community;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanShow(i: PostListing) {
|
|
|
|
i.state.showBanDialog = true;
|
|
|
|
i.state.banType = BanType.Site;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanReasonChange(i: PostListing, event: any) {
|
|
|
|
i.state.banReason = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanExpiresChange(i: PostListing, event: any) {
|
|
|
|
i.state.banExpires = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanFromCommunitySubmit(i: PostListing) {
|
|
|
|
i.state.banType = BanType.Community;
|
|
|
|
i.setState(i.state);
|
|
|
|
i.handleModBanBothSubmit(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanSubmit(i: PostListing) {
|
|
|
|
i.state.banType = BanType.Site;
|
|
|
|
i.setState(i.state);
|
|
|
|
i.handleModBanBothSubmit(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModBanBothSubmit(i: PostListing) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if (i.state.banType == BanType.Community) {
|
|
|
|
let form: BanFromCommunityForm = {
|
|
|
|
user_id: i.props.post.creator_id,
|
|
|
|
community_id: i.props.post.community_id,
|
|
|
|
ban: !i.props.post.banned_from_community,
|
|
|
|
reason: i.state.banReason,
|
|
|
|
expires: getUnixTime(i.state.banExpires),
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.banFromCommunity(form);
|
|
|
|
} else {
|
|
|
|
let form: BanUserForm = {
|
|
|
|
user_id: i.props.post.creator_id,
|
|
|
|
ban: !i.props.post.banned,
|
|
|
|
reason: i.state.banReason,
|
|
|
|
expires: getUnixTime(i.state.banExpires),
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.banUser(form);
|
|
|
|
}
|
|
|
|
|
|
|
|
i.state.showBanDialog = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleAddModToCommunity(i: PostListing) {
|
|
|
|
let form: AddModToCommunityForm = {
|
|
|
|
user_id: i.props.post.creator_id,
|
|
|
|
community_id: i.props.post.community_id,
|
|
|
|
added: !i.isMod,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.addModToCommunity(form);
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleAddAdmin(i: PostListing) {
|
|
|
|
let form: AddAdminForm = {
|
|
|
|
user_id: i.props.post.creator_id,
|
|
|
|
added: !i.isAdmin,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.addAdmin(form);
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
handleShowConfirmTransferCommunity(i: PostListing) {
|
2019-09-06 00:18:48 +00:00
|
|
|
i.state.showConfirmTransferCommunity = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
handleCancelShowConfirmTransferCommunity(i: PostListing) {
|
2019-09-06 00:18:48 +00:00
|
|
|
i.state.showConfirmTransferCommunity = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleTransferCommunity(i: PostListing) {
|
|
|
|
let form: TransferCommunityForm = {
|
|
|
|
community_id: i.props.post.community_id,
|
|
|
|
user_id: i.props.post.creator_id,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.transferCommunity(form);
|
|
|
|
i.state.showConfirmTransferCommunity = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
handleShowConfirmTransferSite(i: PostListing) {
|
2019-09-06 00:18:48 +00:00
|
|
|
i.state.showConfirmTransferSite = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
handleCancelShowConfirmTransferSite(i: PostListing) {
|
2019-09-06 00:18:48 +00:00
|
|
|
i.state.showConfirmTransferSite = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleTransferSite(i: PostListing) {
|
|
|
|
let form: TransferSiteForm = {
|
|
|
|
user_id: i.props.post.creator_id,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.transferSite(form);
|
|
|
|
i.state.showConfirmTransferSite = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-04-24 16:28:20 +00:00
|
|
|
handleImageExpandClick(i: PostListing) {
|
|
|
|
i.state.imageExpanded = !i.state.imageExpanded;
|
2019-04-05 00:01:10 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
2019-09-08 18:00:08 +00:00
|
|
|
|
|
|
|
handleViewSource(i: PostListing) {
|
|
|
|
i.state.viewSource = !i.state.viewSource;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
2020-03-01 03:06:42 +00:00
|
|
|
|
|
|
|
handleShowAdvanced(i: PostListing) {
|
|
|
|
i.state.showAdvanced = !i.state.showAdvanced;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
2019-04-03 06:49:32 +00:00
|
|
|
}
|