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