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