]> Untitled Git - lemmy-ui.git/blob - src/shared/components/post/post-listing.tsx
fix: Undo some extraneous changes
[lemmy-ui.git] / src / shared / components / post / post-listing.tsx
1 import { myAuthRequired, newVote } from "@utils/app";
2 import { canShare, share } from "@utils/browser";
3 import { getExternalHost, getHttpBase } from "@utils/env";
4 import {
5   capitalizeFirstLetter,
6   futureDaysToUnixTime,
7   hostname,
8 } from "@utils/helpers";
9 import { isImage, isVideo } from "@utils/media";
10 import {
11   amAdmin,
12   amCommunityCreator,
13   amMod,
14   canAdmin,
15   canMod,
16   isAdmin,
17   isBanned,
18   isMod,
19 } from "@utils/roles";
20 import classNames from "classnames";
21 import { Component, linkEvent } from "inferno";
22 import { Link } from "inferno-router";
23 import {
24   AddAdmin,
25   AddModToCommunity,
26   BanFromCommunity,
27   BanPerson,
28   BlockPerson,
29   CommunityModeratorView,
30   CreatePostLike,
31   CreatePostReport,
32   DeletePost,
33   EditPost,
34   FeaturePost,
35   Language,
36   LockPost,
37   PersonView,
38   PostView,
39   PurgePerson,
40   PurgePost,
41   RemovePost,
42   SavePost,
43   TransferCommunity,
44 } from "lemmy-js-client";
45 import { relTags } from "../../config";
46 import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
47 import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
48 import { I18NextService, UserService } from "../../services";
49 import { setupTippy } from "../../tippy";
50 import { Icon, PurgeWarning, Spinner } from "../common/icon";
51 import { MomentTime } from "../common/moment-time";
52 import { PictrsImage } from "../common/pictrs-image";
53 import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons";
54 import { CommunityLink } from "../community/community-link";
55 import { PersonListing } from "../person/person-listing";
56 import { MetadataCard } from "./metadata-card";
57 import { PostForm } from "./post-form";
58
59 interface PostListingState {
60   showEdit: boolean;
61   showRemoveDialog: boolean;
62   showPurgeDialog: boolean;
63   purgeReason?: string;
64   purgeType?: PurgeType;
65   purgeLoading: boolean;
66   removeReason?: string;
67   showBanDialog: boolean;
68   banReason?: string;
69   banExpireDays?: number;
70   banType?: BanType;
71   removeData?: boolean;
72   showConfirmTransferSite: boolean;
73   showConfirmTransferCommunity: boolean;
74   imageExpanded: boolean;
75   viewSource: boolean;
76   showAdvanced: boolean;
77   showMoreMobile: boolean;
78   showBody: boolean;
79   showReportDialog: boolean;
80   reportReason?: string;
81   upvoteLoading: boolean;
82   downvoteLoading: boolean;
83   reportLoading: boolean;
84   blockLoading: boolean;
85   lockLoading: boolean;
86   deleteLoading: boolean;
87   removeLoading: boolean;
88   saveLoading: boolean;
89   featureCommunityLoading: boolean;
90   featureLocalLoading: boolean;
91   banLoading: boolean;
92   addModLoading: boolean;
93   addAdminLoading: boolean;
94   transferLoading: boolean;
95 }
96
97 interface PostListingProps {
98   post_view: PostView;
99   crossPosts?: PostView[];
100   moderators?: CommunityModeratorView[];
101   admins?: PersonView[];
102   allLanguages: Language[];
103   siteLanguages: number[];
104   showCommunity?: boolean;
105   showBody?: boolean;
106   hideImage?: boolean;
107   enableDownvotes?: boolean;
108   enableNsfw?: boolean;
109   viewOnly?: boolean;
110   onPostEdit(form: EditPost): void;
111   onPostVote(form: CreatePostLike): void;
112   onPostReport(form: CreatePostReport): void;
113   onBlockPerson(form: BlockPerson): void;
114   onLockPost(form: LockPost): void;
115   onDeletePost(form: DeletePost): void;
116   onRemovePost(form: RemovePost): void;
117   onSavePost(form: SavePost): void;
118   onFeaturePost(form: FeaturePost): void;
119   onPurgePerson(form: PurgePerson): void;
120   onPurgePost(form: PurgePost): void;
121   onBanPersonFromCommunity(form: BanFromCommunity): void;
122   onBanPerson(form: BanPerson): void;
123   onAddModToCommunity(form: AddModToCommunity): void;
124   onAddAdmin(form: AddAdmin): void;
125   onTransferCommunity(form: TransferCommunity): void;
126 }
127
128 export class PostListing extends Component<PostListingProps, PostListingState> {
129   state: PostListingState = {
130     showEdit: false,
131     showRemoveDialog: false,
132     showPurgeDialog: false,
133     purgeType: PurgeType.Person,
134     showBanDialog: false,
135     banType: BanType.Community,
136     removeData: false,
137     showConfirmTransferSite: false,
138     showConfirmTransferCommunity: false,
139     imageExpanded: false,
140     viewSource: false,
141     showAdvanced: false,
142     showMoreMobile: false,
143     showBody: false,
144     showReportDialog: false,
145     upvoteLoading: false,
146     downvoteLoading: false,
147     purgeLoading: false,
148     reportLoading: false,
149     blockLoading: false,
150     lockLoading: false,
151     deleteLoading: false,
152     removeLoading: false,
153     saveLoading: false,
154     featureCommunityLoading: false,
155     featureLocalLoading: false,
156     banLoading: false,
157     addModLoading: false,
158     addAdminLoading: false,
159     transferLoading: false,
160   };
161
162   constructor(props: any, context: any) {
163     super(props, context);
164
165     this.handleEditPost = this.handleEditPost.bind(this);
166     this.handleEditCancel = this.handleEditCancel.bind(this);
167   }
168
169   componentWillReceiveProps(nextProps: PostListingProps) {
170     if (this.props !== nextProps) {
171       this.setState({
172         upvoteLoading: false,
173         downvoteLoading: false,
174         purgeLoading: false,
175         reportLoading: false,
176         blockLoading: false,
177         lockLoading: false,
178         deleteLoading: false,
179         removeLoading: false,
180         saveLoading: false,
181         featureCommunityLoading: false,
182         featureLocalLoading: false,
183         banLoading: false,
184         addModLoading: false,
185         addAdminLoading: false,
186         transferLoading: false,
187         imageExpanded: false,
188       });
189     }
190   }
191
192   get postView(): PostView {
193     return this.props.post_view;
194   }
195
196   render() {
197     const post = this.postView.post;
198
199     return (
200       <div className="post-listing mt-2">
201         {!this.state.showEdit ? (
202           <>
203             {this.listing()}
204             {this.state.imageExpanded && !this.props.hideImage && this.img}
205             {post.url && this.state.showBody && post.embed_title && (
206               <MetadataCard post={post} />
207             )}
208             {this.showBody && this.body()}
209           </>
210         ) : (
211           <PostForm
212             post_view={this.postView}
213             crossPosts={this.props.crossPosts}
214             onEdit={this.handleEditPost}
215             onCancel={this.handleEditCancel}
216             enableNsfw={this.props.enableNsfw}
217             enableDownvotes={this.props.enableDownvotes}
218             allLanguages={this.props.allLanguages}
219             siteLanguages={this.props.siteLanguages}
220           />
221         )}
222       </div>
223     );
224   }
225
226   body() {
227     const body = this.postView.post.body;
228     return body ? (
229       <article id="postContent" className="col-12 card my-2 p-2">
230         {this.state.viewSource ? (
231           <pre>{body}</pre>
232         ) : (
233           <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
234         )}
235       </article>
236     ) : (
237       <></>
238     );
239   }
240
241   get img() {
242     if (this.imageSrc) {
243       return (
244         <>
245           <div className="offset-sm-3 my-2 d-none d-sm-block">
246             <a href={this.imageSrc} className="d-inline-block">
247               <PictrsImage src={this.imageSrc} />
248             </a>
249           </div>
250           <div className="my-2 d-block d-sm-none">
251             <a
252               className="d-inline-block"
253               onClick={linkEvent(this, this.handleImageExpandClick)}
254             >
255               <PictrsImage src={this.imageSrc} />
256             </a>
257           </div>
258         </>
259       );
260     }
261
262     const { post } = this.postView;
263     const { url } = post;
264
265     if (url && isVideo(url)) {
266       return (
267         <div className="embed-responsive mt-3">
268           <video muted controls className="embed-responsive-item col-12">
269             <source src={url} type="video/mp4" />
270           </video>
271         </div>
272       );
273     }
274
275     return <></>;
276   }
277
278   imgThumb(src: string) {
279     const post_view = this.postView;
280     return (
281       <PictrsImage
282         src={src}
283         thumbnail
284         alt=""
285         nsfw={post_view.post.nsfw || post_view.community.nsfw}
286       />
287     );
288   }
289
290   get imageSrc(): string | undefined {
291     const post = this.postView.post;
292     const url = post.url;
293     const thumbnail = post.thumbnail_url;
294
295     if (url && isImage(url)) {
296       if (url.includes("pictrs")) {
297         return url;
298       } else if (thumbnail) {
299         return thumbnail;
300       } else {
301         return url;
302       }
303     } else if (thumbnail) {
304       return thumbnail;
305     } else {
306       return undefined;
307     }
308   }
309
310   thumbnail() {
311     const post = this.postView.post;
312     const url = post.url;
313     const thumbnail = post.thumbnail_url;
314
315     if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
316       return (
317         <a
318           href={this.imageSrc}
319           className="text-body d-inline-block position-relative mb-2"
320           data-tippy-content={I18NextService.i18n.t("expand_here")}
321           onClick={linkEvent(this, this.handleImageExpandClick)}
322           aria-label={I18NextService.i18n.t("expand_here")}
323         >
324           {this.imgThumb(this.imageSrc)}
325           <Icon icon="image" classes="mini-overlay" />
326         </a>
327       );
328     } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
329       return (
330         <a
331           className="text-body d-inline-block position-relative mb-2"
332           href={url}
333           rel={relTags}
334           title={url}
335         >
336           {this.imgThumb(this.imageSrc)}
337           <Icon icon="external-link" classes="mini-overlay" />
338         </a>
339       );
340     } else if (url) {
341       if (!this.props.hideImage && isVideo(url)) {
342         return (
343           <a
344             className="text-body"
345             href={url}
346             title={url}
347             rel={relTags}
348             data-tippy-content={I18NextService.i18n.t("expand_here")}
349             onClick={linkEvent(this, this.handleImageExpandClick)}
350             aria-label={I18NextService.i18n.t("expand_here")}
351           >
352             <div className="thumbnail rounded bg-light d-flex justify-content-center">
353               <Icon icon="play" classes="d-flex align-items-center" />
354             </div>
355           </a>
356         );
357       } else {
358         return (
359           <a className="text-body" href={url} title={url} rel={relTags}>
360             <div className="thumbnail rounded bg-light d-flex justify-content-center">
361               <Icon icon="external-link" classes="d-flex align-items-center" />
362             </div>
363           </a>
364         );
365       }
366     } else {
367       return (
368         <Link
369           className="text-body"
370           to={`/post/${post.id}`}
371           title={I18NextService.i18n.t("comments")}
372         >
373           <div className="thumbnail rounded bg-light d-flex justify-content-center">
374             <Icon icon="message-square" classes="d-flex align-items-center" />
375           </div>
376         </Link>
377       );
378     }
379   }
380
381   createdLine() {
382     const post_view = this.postView;
383     return (
384       <ul className="list-inline mb-1 text-muted small mt-2">
385         <li className="list-inline-item">
386           <PersonListing person={post_view.creator} />
387
388           {this.creatorIsMod_ && (
389             <span className="mx-1 badge text-bg-light">
390               {I18NextService.i18n.t("mod")}
391             </span>
392           )}
393           {this.creatorIsAdmin_ && (
394             <span className="mx-1 badge text-bg-light">
395               {I18NextService.i18n.t("admin")}
396             </span>
397           )}
398           {post_view.creator.bot_account && (
399             <span className="mx-1 badge text-bg-light">
400               {I18NextService.i18n.t("bot_account").toLowerCase()}
401             </span>
402           )}
403           {this.props.showCommunity && (
404             <>
405               {" "}
406               {I18NextService.i18n.t("to")}{" "}
407               <CommunityLink community={post_view.community} />
408             </>
409           )}
410         </li>
411         {post_view.post.language_id !== 0 && (
412           <span className="mx-1 badge text-bg-light">
413             {
414               this.props.allLanguages.find(
415                 lang => lang.id === post_view.post.language_id
416               )?.name
417             }
418           </span>
419         )}
420         <li className="list-inline-item">•</li>
421         <li className="list-inline-item">
422           <span>
423             <MomentTime
424               published={post_view.post.published}
425               updated={post_view.post.updated}
426             />
427           </span>
428         </li>
429       </ul>
430     );
431   }
432
433   get postLink() {
434     const post = this.postView.post;
435     return (
436       <Link
437         className={`d-inline ${
438           !post.featured_community && !post.featured_local
439             ? "text-body"
440             : "text-primary"
441         }`}
442         to={`/post/${post.id}`}
443         title={I18NextService.i18n.t("comments")}
444       >
445         <span
446           className="d-inline"
447           dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
448         />
449       </Link>
450     );
451   }
452
453   postTitleLine() {
454     const post = this.postView.post;
455     const url = post.url;
456
457     return (
458       <>
459         <div className="post-title overflow-hidden">
460           <h5 className="d-inline">
461             {url && this.props.showBody ? (
462               <a
463                 className={
464                   !post.featured_community && !post.featured_local
465                     ? "text-body"
466                     : "text-primary"
467                 }
468                 href={url}
469                 title={url}
470                 rel={relTags}
471                 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
472               ></a>
473             ) : (
474               this.postLink
475             )}
476           </h5>
477           {(url && isImage(url)) ||
478             (post.thumbnail_url && (
479               <button
480                 className="btn btn-sm text-monospace text-muted d-inline-block"
481                 data-tippy-content={I18NextService.i18n.t("expand_here")}
482                 onClick={linkEvent(this, this.handleImageExpandClick)}
483               >
484                 <Icon
485                   icon={
486                     !this.state.imageExpanded ? "plus-square" : "minus-square"
487                   }
488                   classes="icon-inline"
489                 />
490               </button>
491             ))}
492           {post.removed && (
493             <small className="ms-2 badge text-bg-secondary">
494               {I18NextService.i18n.t("removed")}
495             </small>
496           )}
497           {post.deleted && (
498             <small
499               className="unselectable pointer ms-2 text-muted font-italic"
500               data-tippy-content={I18NextService.i18n.t("deleted")}
501             >
502               <Icon icon="trash" classes="icon-inline text-danger" />
503             </small>
504           )}
505           {post.locked && (
506             <small
507               className="unselectable pointer ms-2 text-muted font-italic"
508               data-tippy-content={I18NextService.i18n.t("locked")}
509             >
510               <Icon icon="lock" classes="icon-inline text-danger" />
511             </small>
512           )}
513           {post.featured_community && (
514             <small
515               className="unselectable pointer ms-2 text-muted font-italic"
516               data-tippy-content={I18NextService.i18n.t(
517                 "featured_in_community"
518               )}
519               aria-label={I18NextService.i18n.t("featured_in_community")}
520             >
521               <Icon icon="pin" classes="icon-inline text-primary" />
522             </small>
523           )}
524           {post.featured_local && (
525             <small
526               className="unselectable pointer ms-2 text-muted font-italic"
527               data-tippy-content={I18NextService.i18n.t("featured_in_local")}
528               aria-label={I18NextService.i18n.t("featured_in_local")}
529             >
530               <Icon icon="pin" classes="icon-inline text-secondary" />
531             </small>
532           )}
533           {post.nsfw && (
534             <small className="ms-2 badge text-bg-danger">
535               {I18NextService.i18n.t("nsfw")}
536             </small>
537           )}
538         </div>
539         {url && this.urlLine()}
540       </>
541     );
542   }
543
544   urlLine() {
545     const post = this.postView.post;
546     const url = post.url;
547
548     return (
549       <p className="d-flex text-muted align-items-center gap-1 small m-0">
550         {url && !(hostname(url) === getExternalHost()) && (
551           <a
552             className="text-muted font-italic"
553             href={url}
554             title={url}
555             rel={relTags}
556           >
557             {hostname(url)}
558           </a>
559         )}
560       </p>
561     );
562   }
563
564   duplicatesLine() {
565     const dupes = this.props.crossPosts;
566     return dupes && dupes.length > 0 ? (
567       <ul className="list-inline mb-1 small text-muted">
568         <>
569           <li className="list-inline-item me-2">
570             {I18NextService.i18n.t("cross_posted_to")}
571           </li>
572           {dupes.map(pv => (
573             <li key={pv.post.id} className="list-inline-item me-2">
574               <Link to={`/post/${pv.post.id}`}>
575                 {pv.community.local
576                   ? pv.community.name
577                   : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
578               </Link>
579             </li>
580           ))}
581         </>
582       </ul>
583     ) : (
584       <></>
585     );
586   }
587
588   commentsLine(mobile = false) {
589     const post = this.postView.post;
590
591     return (
592       <div className="d-flex align-items-center justify-content-start flex-wrap text-muted">
593         {this.commentsButton}
594         {canShare() && (
595           <button
596             className="btn btn-sm btn-animate text-muted py-0"
597             onClick={linkEvent(this, this.handleShare)}
598             type="button"
599           >
600             <Icon icon="share" inline />
601           </button>
602         )}
603         {!post.local && (
604           <a
605             className="btn btn-sm btn-animate text-muted py-0"
606             title={I18NextService.i18n.t("link")}
607             href={post.ap_id}
608           >
609             <Icon icon="fedilink" inline />
610           </a>
611         )}
612         {mobile && !this.props.viewOnly && (
613           <VoteButtonsCompact
614             postListing={this}
615             enableDownvotes={this.props.enableDownvotes}
616             handleUpvote={this.handleUpvote}
617             handleDownvote={this.handleDownvote}
618             counts={this.postView.counts}
619             my_vote={this.postView.my_vote}
620           />
621         )}
622         {UserService.Instance.myUserInfo &&
623           !this.props.viewOnly &&
624           this.postActions()}
625       </div>
626     );
627   }
628
629   showPreviewButton() {
630     const post_view = this.postView;
631     const body = post_view.post.body;
632
633     return (
634       <button
635         className="btn btn-sm btn-animate text-muted py-0"
636         data-tippy-content={body && mdNoImages.render(body)}
637         data-tippy-allowHtml={true}
638         onClick={linkEvent(this, this.handleShowBody)}
639       >
640         <Icon
641           icon="book-open"
642           classes={classNames("icon-inline me-1", {
643             "text-success": this.state.showBody,
644           })}
645         />
646       </button>
647     );
648   }
649
650   postActions() {
651     // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
652     // Possible enhancement: Make each button a component.
653     const post_view = this.postView;
654     const post = post_view.post;
655
656     return (
657       <>
658         {this.saveButton}
659
660         {/**
661          * If there is a URL, or if the post has a body and we were told not to
662          * show the body, show the MetadataCard/body toggle.
663          */}
664         {(post.url || (post.body && !this.props.showBody)) &&
665           this.showPreviewButton()}
666
667         {this.showBody && post_view.post.body && this.viewSourceButton}
668
669         <div className="dropdown">
670           <button
671             className="btn btn-sm btn-animate text-muted py-0 dropdown-toggle"
672             onClick={linkEvent(this, this.handleShowAdvanced)}
673             data-tippy-content={I18NextService.i18n.t("more")}
674             data-bs-toggle="dropdown"
675             aria-expanded="false"
676             aria-controls="advancedButtonsDropdown"
677             aria-label={I18NextService.i18n.t("more")}
678           >
679             <Icon icon="more-vertical" inline />
680           </button>
681
682           <ul className="dropdown-menu" id="advancedButtonsDropdown">
683             <li>{this.crossPostButton}</li>
684             <li>
685               <hr className="dropdown-divider" />
686             </li>
687
688             {!this.myPost ? (
689               <>
690                 <li>{this.reportButton}</li>
691                 <li>{this.blockButton}</li>
692               </>
693             ) : (
694               <>
695                 <li>{this.editButton}</li>
696                 <li>{this.deleteButton}</li>
697               </>
698             )}
699
700             {/* Any mod can do these, not limited to hierarchy*/}
701             {(amMod(this.props.moderators) || amAdmin()) && (
702               <>
703                 <li>
704                   <hr className="dropdown-divider" />
705                 </li>
706                 <li>{this.lockButton}</li>
707                 {this.featureButtons}
708               </>
709             )}
710
711             {(this.canMod_ || this.canAdmin_) && (
712               <li>{this.modRemoveButton}</li>
713             )}
714           </ul>
715         </div>
716       </>
717     );
718   }
719
720   get commentsButton() {
721     const post_view = this.postView;
722     const title = I18NextService.i18n.t("number_of_comments", {
723       count: Number(post_view.counts.comments),
724       formattedCount: Number(post_view.counts.comments),
725     });
726
727     return (
728       <Link
729         className="btn btn-link btn-sm text-muted ps-0"
730         title={title}
731         to={`/post/${post_view.post.id}?scrollToComments=true`}
732         data-tippy-content={title}
733       >
734         <span className="me-1">
735           <Icon icon="message-square" classes="me-1" inline />
736           {post_view.counts.comments}
737         </span>
738         {this.unreadCount && (
739           <span className="text-muted fst-italic">
740             ({this.unreadCount} {I18NextService.i18n.t("new")})
741           </span>
742         )}
743       </Link>
744     );
745   }
746
747   get unreadCount(): number | undefined {
748     const pv = this.postView;
749     return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
750       ? undefined
751       : pv.unread_comments;
752   }
753
754   get saveButton() {
755     const saved = this.postView.saved;
756     const label = saved
757       ? I18NextService.i18n.t("unsave")
758       : I18NextService.i18n.t("save");
759     return (
760       <button
761         className="btn btn-sm btn-animate text-muted py-0"
762         onClick={linkEvent(this, this.handleSavePostClick)}
763         data-tippy-content={label}
764         aria-label={label}
765       >
766         {this.state.saveLoading ? (
767           <Spinner />
768         ) : (
769           <Icon
770             icon="star"
771             classes={classNames({ "text-warning": saved })}
772             inline
773           />
774         )}
775       </button>
776     );
777   }
778
779   get crossPostButton() {
780     return (
781       <Link
782         className="btn-animate text-muted py-0"
783         to={{
784           /* Empty string properties are required to satisfy type*/
785           pathname: "/create_post",
786           state: { ...this.crossPostParams },
787           hash: "",
788           key: "",
789           search: "",
790         }}
791         title={I18NextService.i18n.t("cross_post")}
792         data-tippy-content={I18NextService.i18n.t("cross_post")}
793         aria-label={I18NextService.i18n.t("cross_post")}
794       >
795         <Icon icon="copy" inline />
796       </Link>
797     );
798   }
799
800   get reportButton() {
801     return (
802       <button
803         className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
804         onClick={linkEvent(this, this.handleShowReportDialog)}
805         aria-label={I18NextService.i18n.t("show_report_dialog")}
806       >
807         <Icon classes="me-1" icon="flag" inline />
808         {I18NextService.i18n.t("create_report")}
809       </button>
810     );
811   }
812
813   get blockButton() {
814     return (
815       <button
816         className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
817         onClick={linkEvent(this, this.handleBlockPersonClick)}
818         aria-label={I18NextService.i18n.t("block_user")}
819       >
820         {this.state.blockLoading ? (
821           <Spinner />
822         ) : (
823           <Icon classes="me-1" icon="slash" inline />
824         )}
825         {I18NextService.i18n.t("block_user")}
826       </button>
827     );
828   }
829
830   get editButton() {
831     return (
832       <button
833         className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
834         onClick={linkEvent(this, this.handleEditClick)}
835         aria-label={I18NextService.i18n.t("edit")}
836       >
837         <Icon classes="me-1" icon="edit" inline />
838         {I18NextService.i18n.t("edit")}
839       </button>
840     );
841   }
842
843   get deleteButton() {
844     const deleted = this.postView.post.deleted;
845     const label = !deleted
846       ? I18NextService.i18n.t("delete")
847       : I18NextService.i18n.t("restore");
848     return (
849       <button
850         className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
851         onClick={linkEvent(this, this.handleDeleteClick)}
852       >
853         {this.state.deleteLoading ? (
854           <Spinner />
855         ) : (
856           <>
857             <Icon
858               icon="trash"
859               classes={classNames("me-1", { "text-danger": deleted })}
860               inline
861             />
862             {label}
863           </>
864         )}
865       </button>
866     );
867   }
868
869   get viewSourceButton() {
870     return (
871       <button
872         className="btn btn-sm btn-animate text-muted py-0"
873         onClick={linkEvent(this, this.handleViewSource)}
874         data-tippy-content={I18NextService.i18n.t("view_source")}
875         aria-label={I18NextService.i18n.t("view_source")}
876       >
877         <Icon
878           icon="file-text"
879           classes={classNames({ "text-success": this.state.viewSource })}
880           inline
881         />
882       </button>
883     );
884   }
885
886   get lockButton() {
887     const locked = this.postView.post.locked;
888     const label = locked
889       ? I18NextService.i18n.t("unlock")
890       : I18NextService.i18n.t("lock");
891     return (
892       <button
893         className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
894         onClick={linkEvent(this, this.handleModLock)}
895         aria-label={label}
896       >
897         {this.state.lockLoading ? (
898           <Spinner />
899         ) : (
900           <>
901             <Icon
902               icon="lock"
903               classes={classNames("me-1", { "text-danger": locked })}
904               inline
905             />
906             {capitalizeFirstLetter(label)}
907           </>
908         )}
909       </button>
910     );
911   }
912
913   get featureButtons() {
914     const featuredCommunity = this.postView.post.featured_community;
915     const labelCommunity = featuredCommunity
916       ? I18NextService.i18n.t("unfeature_from_community")
917       : I18NextService.i18n.t("feature_in_community");
918
919     const featuredLocal = this.postView.post.featured_local;
920     const labelLocal = featuredLocal
921       ? I18NextService.i18n.t("unfeature_from_local")
922       : I18NextService.i18n.t("feature_in_local");
923     return (
924       <>
925         <li>
926           <button
927             className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
928             onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
929             data-tippy-content={labelCommunity}
930             aria-label={labelCommunity}
931           >
932             {this.state.featureCommunityLoading ? (
933               <Spinner />
934             ) : (
935               <>
936                 <Icon
937                   icon="pin"
938                   classes={classNames("me-1", {
939                     "text-success": featuredCommunity,
940                   })}
941                   inline
942                 />
943                 {I18NextService.i18n.t("community")}
944               </>
945             )}
946           </button>
947         </li>
948         <li>
949           {amAdmin() && (
950             <button
951               className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
952               onClick={linkEvent(this, this.handleModFeaturePostLocal)}
953               data-tippy-content={labelLocal}
954               aria-label={labelLocal}
955             >
956               {this.state.featureLocalLoading ? (
957                 <Spinner />
958               ) : (
959                 <>
960                   <Icon
961                     icon="pin"
962                     classes={classNames("me-1", {
963                       "text-success": featuredLocal,
964                     })}
965                     inline
966                   />
967                   {I18NextService.i18n.t("local")}
968                 </>
969               )}
970             </button>
971           )}
972         </li>
973       </>
974     );
975   }
976
977   get modRemoveButton() {
978     const removed = this.postView.post.removed;
979     return (
980       <button
981         className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
982         onClick={linkEvent(
983           this,
984           !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
985         )}
986       >
987         {/* TODO: Find an icon for this. */}
988         {this.state.removeLoading ? (
989           <Spinner />
990         ) : !removed ? (
991           I18NextService.i18n.t("remove")
992         ) : (
993           I18NextService.i18n.t("restore")
994         )}
995       </button>
996     );
997   }
998
999   /**
1000    * Mod/Admin actions to be taken against the author.
1001    */
1002   userActionsLine() {
1003     // TODO: make nicer
1004     const post_view = this.postView;
1005     return (
1006       this.state.showAdvanced && (
1007         <>
1008           {this.canMod_ && (
1009             <>
1010               {!this.creatorIsMod_ &&
1011                 (!post_view.creator_banned_from_community ? (
1012                   <button
1013                     className="btn btn-link btn-animate text-muted py-0"
1014                     onClick={linkEvent(
1015                       this,
1016                       this.handleModBanFromCommunityShow
1017                     )}
1018                     aria-label={I18NextService.i18n.t("ban_from_community")}
1019                   >
1020                     {I18NextService.i18n.t("ban_from_community")}
1021                   </button>
1022                 ) : (
1023                   <button
1024                     className="btn btn-link btn-animate text-muted py-0"
1025                     onClick={linkEvent(
1026                       this,
1027                       this.handleModBanFromCommunitySubmit
1028                     )}
1029                     aria-label={I18NextService.i18n.t("unban")}
1030                   >
1031                     {this.state.banLoading ? (
1032                       <Spinner />
1033                     ) : (
1034                       I18NextService.i18n.t("unban")
1035                     )}
1036                   </button>
1037                 ))}
1038               {!post_view.creator_banned_from_community && (
1039                 <button
1040                   className="btn btn-link btn-animate text-muted py-0"
1041                   onClick={linkEvent(this, this.handleAddModToCommunity)}
1042                   aria-label={
1043                     this.creatorIsMod_
1044                       ? I18NextService.i18n.t("remove_as_mod")
1045                       : I18NextService.i18n.t("appoint_as_mod")
1046                   }
1047                 >
1048                   {this.state.addModLoading ? (
1049                     <Spinner />
1050                   ) : this.creatorIsMod_ ? (
1051                     I18NextService.i18n.t("remove_as_mod")
1052                   ) : (
1053                     I18NextService.i18n.t("appoint_as_mod")
1054                   )}
1055                 </button>
1056               )}
1057             </>
1058           )}
1059           {/* Community creators and admins can transfer community to another mod */}
1060           {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1061             this.canAdmin_) &&
1062             this.creatorIsMod_ &&
1063             (!this.state.showConfirmTransferCommunity ? (
1064               <button
1065                 className="btn btn-link btn-animate text-muted py-0"
1066                 onClick={linkEvent(
1067                   this,
1068                   this.handleShowConfirmTransferCommunity
1069                 )}
1070                 aria-label={I18NextService.i18n.t("transfer_community")}
1071               >
1072                 {I18NextService.i18n.t("transfer_community")}
1073               </button>
1074             ) : (
1075               <>
1076                 <button
1077                   className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
1078                   aria-label={I18NextService.i18n.t("are_you_sure")}
1079                 >
1080                   {I18NextService.i18n.t("are_you_sure")}
1081                 </button>
1082                 <button
1083                   className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
1084                   aria-label={I18NextService.i18n.t("yes")}
1085                   onClick={linkEvent(this, this.handleTransferCommunity)}
1086                 >
1087                   {this.state.transferLoading ? (
1088                     <Spinner />
1089                   ) : (
1090                     I18NextService.i18n.t("yes")
1091                   )}
1092                 </button>
1093                 <button
1094                   className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1095                   onClick={linkEvent(
1096                     this,
1097                     this.handleCancelShowConfirmTransferCommunity
1098                   )}
1099                   aria-label={I18NextService.i18n.t("no")}
1100                 >
1101                   {I18NextService.i18n.t("no")}
1102                 </button>
1103               </>
1104             ))}
1105           {/* Admins can ban from all, and appoint other admins */}
1106           {this.canAdmin_ && (
1107             <>
1108               {!this.creatorIsAdmin_ && (
1109                 <>
1110                   {!isBanned(post_view.creator) ? (
1111                     <button
1112                       className="btn btn-link btn-animate text-muted py-0"
1113                       onClick={linkEvent(this, this.handleModBanShow)}
1114                       aria-label={I18NextService.i18n.t("ban_from_site")}
1115                     >
1116                       {I18NextService.i18n.t("ban_from_site")}
1117                     </button>
1118                   ) : (
1119                     <button
1120                       className="btn btn-link btn-animate text-muted py-0"
1121                       onClick={linkEvent(this, this.handleModBanSubmit)}
1122                       aria-label={I18NextService.i18n.t("unban_from_site")}
1123                     >
1124                       {this.state.banLoading ? (
1125                         <Spinner />
1126                       ) : (
1127                         I18NextService.i18n.t("unban_from_site")
1128                       )}
1129                     </button>
1130                   )}
1131                   <button
1132                     className="btn btn-link btn-animate text-muted py-0"
1133                     onClick={linkEvent(this, this.handlePurgePersonShow)}
1134                     aria-label={I18NextService.i18n.t("purge_user")}
1135                   >
1136                     {I18NextService.i18n.t("purge_user")}
1137                   </button>
1138                   <button
1139                     className="btn btn-link btn-animate text-muted py-0"
1140                     onClick={linkEvent(this, this.handlePurgePostShow)}
1141                     aria-label={I18NextService.i18n.t("purge_post")}
1142                   >
1143                     {I18NextService.i18n.t("purge_post")}
1144                   </button>
1145                 </>
1146               )}
1147               {!isBanned(post_view.creator) && post_view.creator.local && (
1148                 <button
1149                   className="btn btn-link btn-animate text-muted py-0"
1150                   onClick={linkEvent(this, this.handleAddAdmin)}
1151                   aria-label={
1152                     this.creatorIsAdmin_
1153                       ? I18NextService.i18n.t("remove_as_admin")
1154                       : I18NextService.i18n.t("appoint_as_admin")
1155                   }
1156                 >
1157                   {this.state.addAdminLoading ? (
1158                     <Spinner />
1159                   ) : this.creatorIsAdmin_ ? (
1160                     I18NextService.i18n.t("remove_as_admin")
1161                   ) : (
1162                     I18NextService.i18n.t("appoint_as_admin")
1163                   )}
1164                 </button>
1165               )}
1166             </>
1167           )}
1168         </>
1169       )
1170     );
1171   }
1172
1173   removeAndBanDialogs() {
1174     const post = this.postView;
1175     const purgeTypeText =
1176       this.state.purgeType == PurgeType.Post
1177         ? I18NextService.i18n.t("purge_post")
1178         : `${I18NextService.i18n.t("purge")} ${post.creator.name}`;
1179     return (
1180       <>
1181         {this.state.showRemoveDialog && (
1182           <form
1183             className="form-inline"
1184             onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1185           >
1186             <label
1187               className="visually-hidden"
1188               htmlFor="post-listing-remove-reason"
1189             >
1190               {I18NextService.i18n.t("reason")}
1191             </label>
1192             <input
1193               type="text"
1194               id="post-listing-remove-reason"
1195               className="form-control me-2"
1196               placeholder={I18NextService.i18n.t("reason")}
1197               value={this.state.removeReason}
1198               onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1199             />
1200             <button
1201               type="submit"
1202               className="btn btn-secondary"
1203               aria-label={I18NextService.i18n.t("remove_post")}
1204             >
1205               {this.state.removeLoading ? (
1206                 <Spinner />
1207               ) : (
1208                 I18NextService.i18n.t("remove_post")
1209               )}
1210             </button>
1211           </form>
1212         )}
1213         {this.state.showBanDialog && (
1214           <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1215             <div className="mb-3 row col-12">
1216               <label
1217                 className="col-form-label"
1218                 htmlFor="post-listing-ban-reason"
1219               >
1220                 {I18NextService.i18n.t("reason")}
1221               </label>
1222               <input
1223                 type="text"
1224                 id="post-listing-ban-reason"
1225                 className="form-control me-2"
1226                 placeholder={I18NextService.i18n.t("reason")}
1227                 value={this.state.banReason}
1228                 onInput={linkEvent(this, this.handleModBanReasonChange)}
1229               />
1230               <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1231                 {I18NextService.i18n.t("expires")}
1232               </label>
1233               <input
1234                 type="number"
1235                 id={`mod-ban-expires`}
1236                 className="form-control me-2"
1237                 placeholder={I18NextService.i18n.t("number_of_days")}
1238                 value={this.state.banExpireDays}
1239                 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1240               />
1241               <div className="input-group mb-3">
1242                 <div className="form-check">
1243                   <input
1244                     className="form-check-input"
1245                     id="mod-ban-remove-data"
1246                     type="checkbox"
1247                     checked={this.state.removeData}
1248                     onChange={linkEvent(this, this.handleModRemoveDataChange)}
1249                   />
1250                   <label
1251                     className="form-check-label"
1252                     htmlFor="mod-ban-remove-data"
1253                     title={I18NextService.i18n.t("remove_content_more")}
1254                   >
1255                     {I18NextService.i18n.t("remove_content")}
1256                   </label>
1257                 </div>
1258               </div>
1259             </div>
1260             {/* TODO hold off on expires until later */}
1261             {/* <div class="mb-3 row"> */}
1262             {/*   <label class="col-form-label">Expires</label> */}
1263             {/*   <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1264             {/* </div> */}
1265             <div className="mb-3 row">
1266               <button
1267                 type="submit"
1268                 className="btn btn-secondary"
1269                 aria-label={I18NextService.i18n.t("ban")}
1270               >
1271                 {this.state.banLoading ? (
1272                   <Spinner />
1273                 ) : (
1274                   <span>
1275                     {I18NextService.i18n.t("ban")} {post.creator.name}
1276                   </span>
1277                 )}
1278               </button>
1279             </div>
1280           </form>
1281         )}
1282         {this.state.showReportDialog && (
1283           <form
1284             className="form-inline"
1285             onSubmit={linkEvent(this, this.handleReportSubmit)}
1286           >
1287             <label className="visually-hidden" htmlFor="post-report-reason">
1288               {I18NextService.i18n.t("reason")}
1289             </label>
1290             <input
1291               type="text"
1292               id="post-report-reason"
1293               className="form-control me-2"
1294               placeholder={I18NextService.i18n.t("reason")}
1295               required
1296               value={this.state.reportReason}
1297               onInput={linkEvent(this, this.handleReportReasonChange)}
1298             />
1299             <button
1300               type="submit"
1301               className="btn btn-secondary"
1302               aria-label={I18NextService.i18n.t("create_report")}
1303             >
1304               {this.state.reportLoading ? (
1305                 <Spinner />
1306               ) : (
1307                 I18NextService.i18n.t("create_report")
1308               )}
1309             </button>
1310           </form>
1311         )}
1312         {this.state.showPurgeDialog && (
1313           <form
1314             className="form-inline"
1315             onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1316           >
1317             <PurgeWarning />
1318             <label className="visually-hidden" htmlFor="purge-reason">
1319               {I18NextService.i18n.t("reason")}
1320             </label>
1321             <input
1322               type="text"
1323               id="purge-reason"
1324               className="form-control me-2"
1325               placeholder={I18NextService.i18n.t("reason")}
1326               value={this.state.purgeReason}
1327               onInput={linkEvent(this, this.handlePurgeReasonChange)}
1328             />
1329             {this.state.purgeLoading ? (
1330               <Spinner />
1331             ) : (
1332               <button
1333                 type="submit"
1334                 className="btn btn-secondary"
1335                 aria-label={purgeTypeText}
1336               >
1337                 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1338               </button>
1339             )}
1340           </form>
1341         )}
1342       </>
1343     );
1344   }
1345
1346   mobileThumbnail() {
1347     const post = this.postView.post;
1348     return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1349       <div className="row">
1350         <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1351           {this.postTitleLine()}
1352         </div>
1353         <div className="col-4">
1354           {/* Post thumbnail */}
1355           {!this.state.imageExpanded && this.thumbnail()}
1356         </div>
1357       </div>
1358     ) : (
1359       this.postTitleLine()
1360     );
1361   }
1362
1363   showMobilePreview() {
1364     const { body, id } = this.postView.post;
1365
1366     return !this.showBody && body ? (
1367       <Link className="text-body" to={`/post/${id}`}>
1368         <div className="md-div mb-1 preview-lines">{body}</div>
1369       </Link>
1370     ) : (
1371       <></>
1372     );
1373   }
1374
1375   listing() {
1376     return (
1377       <>
1378         {/* The mobile view*/}
1379         <div className="d-block d-sm-none">
1380           <article className="row post-container">
1381             <div className="col-12">
1382               {this.createdLine()}
1383
1384               {/* If it has a thumbnail, do a right aligned thumbnail */}
1385               {this.mobileThumbnail()}
1386
1387               {/* Show a preview of the post body */}
1388               {this.showMobilePreview()}
1389
1390               {this.commentsLine(true)}
1391               {this.userActionsLine()}
1392               {this.duplicatesLine()}
1393               {this.removeAndBanDialogs()}
1394             </div>
1395           </article>
1396         </div>
1397
1398         {/* The larger view*/}
1399         <div className="d-none d-sm-block">
1400           <article className="row post-container">
1401             {!this.props.viewOnly && (
1402               <VoteButtons
1403                 postListing={this}
1404                 enableDownvotes={this.props.enableDownvotes}
1405                 handleUpvote={this.handleUpvote}
1406                 handleDownvote={this.handleDownvote}
1407                 counts={this.postView.counts}
1408                 my_vote={this.postView.my_vote}
1409               />
1410             )}
1411             <div className="col-sm-2 pe-0 post-media">
1412               <div className="">{this.thumbnail()}</div>
1413             </div>
1414             <div className="col-12 col-sm-9">
1415               <div className="row">
1416                 <div className="col-12">
1417                   {this.postTitleLine()}
1418                   {this.createdLine()}
1419                   {this.commentsLine()}
1420                   {this.duplicatesLine()}
1421                   {this.userActionsLine()}
1422                   {this.removeAndBanDialogs()}
1423                 </div>
1424               </div>
1425             </div>
1426           </article>
1427         </div>
1428       </>
1429     );
1430   }
1431
1432   private get myPost(): boolean {
1433     return (
1434       this.postView.creator.id ==
1435       UserService.Instance.myUserInfo?.local_user_view.person.id
1436     );
1437   }
1438   handleEditClick(i: PostListing) {
1439     i.setState({ showEdit: true });
1440   }
1441
1442   handleEditCancel() {
1443     this.setState({ showEdit: false });
1444   }
1445
1446   // The actual editing is done in the receive for post
1447   handleEditPost(form: EditPost) {
1448     this.setState({ showEdit: false });
1449     this.props.onPostEdit(form);
1450   }
1451
1452   handleShare(i: PostListing) {
1453     const { name, body, id } = i.props.post_view.post;
1454     share({
1455       title: name,
1456       text: body?.slice(0, 50),
1457       url: `${getHttpBase()}/post/${id}`,
1458     });
1459   }
1460
1461   handleShowReportDialog(i: PostListing) {
1462     i.setState({ showReportDialog: !i.state.showReportDialog });
1463   }
1464
1465   handleReportReasonChange(i: PostListing, event: any) {
1466     i.setState({ reportReason: event.target.value });
1467   }
1468
1469   handleReportSubmit(i: PostListing, event: any) {
1470     event.preventDefault();
1471     i.setState({ reportLoading: true });
1472     i.props.onPostReport({
1473       post_id: i.postView.post.id,
1474       reason: i.state.reportReason ?? "",
1475       auth: myAuthRequired(),
1476     });
1477   }
1478
1479   handleBlockPersonClick(i: PostListing) {
1480     i.setState({ blockLoading: true });
1481     i.props.onBlockPerson({
1482       person_id: i.postView.creator.id,
1483       block: true,
1484       auth: myAuthRequired(),
1485     });
1486   }
1487
1488   handleDeleteClick(i: PostListing) {
1489     i.setState({ deleteLoading: true });
1490     i.props.onDeletePost({
1491       post_id: i.postView.post.id,
1492       deleted: !i.postView.post.deleted,
1493       auth: myAuthRequired(),
1494     });
1495   }
1496
1497   handleSavePostClick(i: PostListing) {
1498     i.setState({ saveLoading: true });
1499     i.props.onSavePost({
1500       post_id: i.postView.post.id,
1501       save: !i.postView.saved,
1502       auth: myAuthRequired(),
1503     });
1504   }
1505
1506   get crossPostParams(): PostFormParams {
1507     const queryParams: PostFormParams = {};
1508     const { name, url } = this.postView.post;
1509
1510     queryParams.name = name;
1511
1512     if (url) {
1513       queryParams.url = url;
1514     }
1515
1516     const crossPostBody = this.crossPostBody();
1517     if (crossPostBody) {
1518       queryParams.body = crossPostBody;
1519     }
1520
1521     return queryParams;
1522   }
1523
1524   crossPostBody(): string | undefined {
1525     const post = this.postView.post;
1526     const body = post.body;
1527
1528     return body
1529       ? `${I18NextService.i18n.t("cross_posted_from")} ${
1530           post.ap_id
1531         }\n\n${body.replace(/^/gm, "> ")}`
1532       : undefined;
1533   }
1534
1535   get showBody(): boolean {
1536     return this.props.showBody || this.state.showBody;
1537   }
1538
1539   handleModRemoveShow(i: PostListing) {
1540     i.setState({
1541       showRemoveDialog: !i.state.showRemoveDialog,
1542       showBanDialog: false,
1543     });
1544   }
1545
1546   handleModRemoveReasonChange(i: PostListing, event: any) {
1547     i.setState({ removeReason: event.target.value });
1548   }
1549
1550   handleModRemoveDataChange(i: PostListing, event: any) {
1551     i.setState({ removeData: event.target.checked });
1552   }
1553
1554   handleModRemoveSubmit(i: PostListing, event: any) {
1555     event.preventDefault();
1556     i.setState({ removeLoading: true });
1557     i.props.onRemovePost({
1558       post_id: i.postView.post.id,
1559       removed: !i.postView.post.removed,
1560       auth: myAuthRequired(),
1561     });
1562   }
1563
1564   handleModLock(i: PostListing) {
1565     i.setState({ lockLoading: true });
1566     i.props.onLockPost({
1567       post_id: i.postView.post.id,
1568       locked: !i.postView.post.locked,
1569       auth: myAuthRequired(),
1570     });
1571   }
1572
1573   handleModFeaturePostLocal(i: PostListing) {
1574     i.setState({ featureLocalLoading: true });
1575     i.props.onFeaturePost({
1576       post_id: i.postView.post.id,
1577       featured: !i.postView.post.featured_local,
1578       feature_type: "Local",
1579       auth: myAuthRequired(),
1580     });
1581   }
1582
1583   handleModFeaturePostCommunity(i: PostListing) {
1584     i.setState({ featureCommunityLoading: true });
1585     i.props.onFeaturePost({
1586       post_id: i.postView.post.id,
1587       featured: !i.postView.post.featured_community,
1588       feature_type: "Community",
1589       auth: myAuthRequired(),
1590     });
1591   }
1592
1593   handleModBanFromCommunityShow(i: PostListing) {
1594     i.setState({
1595       showBanDialog: true,
1596       banType: BanType.Community,
1597       showRemoveDialog: false,
1598     });
1599   }
1600
1601   handleModBanShow(i: PostListing) {
1602     i.setState({
1603       showBanDialog: true,
1604       banType: BanType.Site,
1605       showRemoveDialog: false,
1606     });
1607   }
1608
1609   handlePurgePersonShow(i: PostListing) {
1610     i.setState({
1611       showPurgeDialog: true,
1612       purgeType: PurgeType.Person,
1613       showRemoveDialog: false,
1614     });
1615   }
1616
1617   handlePurgePostShow(i: PostListing) {
1618     i.setState({
1619       showPurgeDialog: true,
1620       purgeType: PurgeType.Post,
1621       showRemoveDialog: false,
1622     });
1623   }
1624
1625   handlePurgeReasonChange(i: PostListing, event: any) {
1626     i.setState({ purgeReason: event.target.value });
1627   }
1628
1629   handlePurgeSubmit(i: PostListing, event: any) {
1630     event.preventDefault();
1631     i.setState({ purgeLoading: true });
1632     if (i.state.purgeType == PurgeType.Person) {
1633       i.props.onPurgePerson({
1634         person_id: i.postView.creator.id,
1635         reason: i.state.purgeReason,
1636         auth: myAuthRequired(),
1637       });
1638     } else if (i.state.purgeType == PurgeType.Post) {
1639       i.props.onPurgePost({
1640         post_id: i.postView.post.id,
1641         reason: i.state.purgeReason,
1642         auth: myAuthRequired(),
1643       });
1644     }
1645   }
1646
1647   handleModBanReasonChange(i: PostListing, event: any) {
1648     i.setState({ banReason: event.target.value });
1649   }
1650
1651   handleModBanExpireDaysChange(i: PostListing, event: any) {
1652     i.setState({ banExpireDays: event.target.value });
1653   }
1654
1655   handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1656     i.setState({ banType: BanType.Community });
1657     i.handleModBanBothSubmit(i, event);
1658   }
1659
1660   handleModBanSubmit(i: PostListing, event: any) {
1661     i.setState({ banType: BanType.Site });
1662     i.handleModBanBothSubmit(i, event);
1663   }
1664
1665   handleModBanBothSubmit(i: PostListing, event: any) {
1666     event.preventDefault();
1667     i.setState({ banLoading: true });
1668
1669     const ban = !i.props.post_view.creator_banned_from_community;
1670     // If its an unban, restore all their data
1671     if (ban == false) {
1672       i.setState({ removeData: false });
1673     }
1674     const person_id = i.props.post_view.creator.id;
1675     const remove_data = i.state.removeData;
1676     const reason = i.state.banReason;
1677     const expires = futureDaysToUnixTime(i.state.banExpireDays);
1678
1679     if (i.state.banType == BanType.Community) {
1680       const community_id = i.postView.community.id;
1681       i.props.onBanPersonFromCommunity({
1682         community_id,
1683         person_id,
1684         ban,
1685         remove_data,
1686         reason,
1687         expires,
1688         auth: myAuthRequired(),
1689       });
1690     } else {
1691       i.props.onBanPerson({
1692         person_id,
1693         ban,
1694         remove_data,
1695         reason,
1696         expires,
1697         auth: myAuthRequired(),
1698       });
1699     }
1700   }
1701
1702   handleAddModToCommunity(i: PostListing) {
1703     i.setState({ addModLoading: true });
1704     i.props.onAddModToCommunity({
1705       community_id: i.postView.community.id,
1706       person_id: i.postView.creator.id,
1707       added: !i.creatorIsMod_,
1708       auth: myAuthRequired(),
1709     });
1710   }
1711
1712   handleAddAdmin(i: PostListing) {
1713     i.setState({ addAdminLoading: true });
1714     i.props.onAddAdmin({
1715       person_id: i.postView.creator.id,
1716       added: !i.creatorIsAdmin_,
1717       auth: myAuthRequired(),
1718     });
1719   }
1720
1721   handleShowConfirmTransferCommunity(i: PostListing) {
1722     i.setState({ showConfirmTransferCommunity: true });
1723   }
1724
1725   handleCancelShowConfirmTransferCommunity(i: PostListing) {
1726     i.setState({ showConfirmTransferCommunity: false });
1727   }
1728
1729   handleTransferCommunity(i: PostListing) {
1730     i.setState({ transferLoading: true });
1731     i.props.onTransferCommunity({
1732       community_id: i.postView.community.id,
1733       person_id: i.postView.creator.id,
1734       auth: myAuthRequired(),
1735     });
1736   }
1737
1738   handleShowConfirmTransferSite(i: PostListing) {
1739     i.setState({ showConfirmTransferSite: true });
1740   }
1741
1742   handleCancelShowConfirmTransferSite(i: PostListing) {
1743     i.setState({ showConfirmTransferSite: false });
1744   }
1745
1746   handleImageExpandClick(i: PostListing, event: any) {
1747     event.preventDefault();
1748     i.setState({ imageExpanded: !i.state.imageExpanded });
1749     setupTippy();
1750   }
1751
1752   handleViewSource(i: PostListing) {
1753     i.setState({ viewSource: !i.state.viewSource });
1754   }
1755
1756   handleShowAdvanced(i: PostListing) {
1757     i.setState({ showAdvanced: !i.state.showAdvanced });
1758     setupTippy();
1759   }
1760
1761   handleShowMoreMobile(i: PostListing) {
1762     i.setState({
1763       showMoreMobile: !i.state.showMoreMobile,
1764       showAdvanced: !i.state.showAdvanced,
1765     });
1766     setupTippy();
1767   }
1768
1769   handleShowBody(i: PostListing) {
1770     i.setState({ showBody: !i.state.showBody });
1771     setupTippy();
1772   }
1773
1774   handleUpvote(i: PostListing) {
1775     i.setState({ upvoteLoading: true });
1776     i.props.onPostVote({
1777       post_id: i.postView.post.id,
1778       score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1779       auth: myAuthRequired(),
1780     });
1781   }
1782
1783   handleDownvote(i: PostListing) {
1784     i.setState({ downvoteLoading: true });
1785     i.props.onPostVote({
1786       post_id: i.postView.post.id,
1787       score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1788       auth: myAuthRequired(),
1789     });
1790   }
1791
1792   get pointsTippy(): string {
1793     const points = I18NextService.i18n.t("number_of_points", {
1794       count: Number(this.postView.counts.score),
1795       formattedCount: Number(this.postView.counts.score),
1796     });
1797
1798     const upvotes = I18NextService.i18n.t("number_of_upvotes", {
1799       count: Number(this.postView.counts.upvotes),
1800       formattedCount: Number(this.postView.counts.upvotes),
1801     });
1802
1803     const downvotes = I18NextService.i18n.t("number_of_downvotes", {
1804       count: Number(this.postView.counts.downvotes),
1805       formattedCount: Number(this.postView.counts.downvotes),
1806     });
1807
1808     return `${points} • ${upvotes} • ${downvotes}`;
1809   }
1810
1811   get canModOnSelf_(): boolean {
1812     return canMod(
1813       this.postView.creator.id,
1814       this.props.moderators,
1815       this.props.admins,
1816       undefined,
1817       true
1818     );
1819   }
1820
1821   get canMod_(): boolean {
1822     return canMod(
1823       this.postView.creator.id,
1824       this.props.moderators,
1825       this.props.admins
1826     );
1827   }
1828
1829   get canAdmin_(): boolean {
1830     return canAdmin(this.postView.creator.id, this.props.admins);
1831   }
1832
1833   get creatorIsMod_(): boolean {
1834     return isMod(this.postView.creator.id, this.props.moderators);
1835   }
1836
1837   get creatorIsAdmin_(): boolean {
1838     return isAdmin(this.postView.creator.id, this.props.admins);
1839   }
1840 }