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