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