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