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