]> Untitled Git - lemmy-ui.git/blobdiff - src/shared/components/comment/comment-node.tsx
Changes to language tag
[lemmy-ui.git] / src / shared / components / comment / comment-node.tsx
index 50da45614ef9f9ba9b5043a1c1136e737ec1905b..83477864574e1c7855a3c38a36b07d55c733f425 100644 (file)
@@ -7,21 +7,19 @@ import {
   BanFromCommunity,
   BanPerson,
   BlockPerson,
-  CommentNode as CommentNodeI,
   CommentReplyView,
   CommentView,
   CommunityModeratorView,
   CreateCommentLike,
   CreateCommentReport,
   DeleteComment,
-  EditComment,
+  DistinguishComment,
   GetComments,
   Language,
-  ListingType,
   MarkCommentReplyAsRead,
   MarkPersonMentionAsRead,
   PersonMentionView,
-  PersonViewSafe,
+  PersonView,
   PurgeComment,
   PurgePerson,
   RemoveComment,
@@ -30,7 +28,12 @@ import {
 } from "lemmy-js-client";
 import moment from "moment";
 import { i18n } from "../../i18next";
-import { BanType, CommentViewType, PurgeType } from "../../interfaces";
+import {
+  BanType,
+  CommentNodeI,
+  CommentViewType,
+  PurgeType,
+} from "../../interfaces";
 import { UserService, WebSocketService } from "../../services";
 import {
   amCommunityCreator,
@@ -39,6 +42,7 @@ import {
   colorList,
   commentTreeMaxDepth,
   futureDaysToUnixTime,
+  getCommentParentId,
   isAdmin,
   isBanned,
   isMod,
@@ -91,7 +95,7 @@ interface CommentNodeState {
 interface CommentNodeProps {
   node: CommentNodeI;
   moderators?: CommunityModeratorView[];
-  admins?: PersonViewSafe[];
+  admins?: PersonView[];
   noBorder?: boolean;
   noIndent?: boolean;
   viewOnly?: boolean;
@@ -163,27 +167,29 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
         ? i18n.t("purge_comment")
         : `${i18n.t("purge")} ${cv.creator.name}`;
 
-    let canMod_ = canMod(
-      cv.creator.id,
-      this.props.moderators,
-      this.props.admins
-    );
-    let canModOnSelf = canMod(
-      cv.creator.id,
-      this.props.moderators,
-      this.props.admins,
-      UserService.Instance.myUserInfo,
-      true
-    );
-    let canAdmin_ = canAdmin(cv.creator.id, this.props.admins);
-    let canAdminOnSelf = canAdmin(
-      cv.creator.id,
-      this.props.admins,
-      UserService.Instance.myUserInfo,
-      true
-    );
+    let canMod_ =
+      canMod(cv.creator.id, this.props.moderators, this.props.admins) &&
+      cv.community.local;
+    let canModOnSelf =
+      canMod(
+        cv.creator.id,
+        this.props.moderators,
+        this.props.admins,
+        UserService.Instance.myUserInfo,
+        true
+      ) && cv.community.local;
+    let canAdmin_ =
+      canAdmin(cv.creator.id, this.props.admins) && cv.community.local;
+    let canAdminOnSelf =
+      canAdmin(
+        cv.creator.id,
+        this.props.admins,
+        UserService.Instance.myUserInfo,
+        true
+      ) && cv.community.local;
     let isMod_ = isMod(cv.creator.id, this.props.moderators);
-    let isAdmin_ = isAdmin(cv.creator.id, this.props.admins);
+    let isAdmin_ =
+      isAdmin(cv.creator.id, this.props.admins) && cv.community.local;
     let amCommunityCreator_ = amCommunityCreator(
       cv.creator.id,
       this.props.moderators
@@ -254,11 +260,6 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
                   {i18n.t("bot_account").toLowerCase()}
                 </div>
               )}
-              {(cv.creator_banned_from_community || isBanned(cv.creator)) && (
-                <div className="badge badge-danger mr-2">
-                  {i18n.t("banned")}
-                </div>
-              )}
               {this.props.showCommunity && (
                 <>
                   <span className="mx-1">{i18n.t("to")}</span>
@@ -282,8 +283,17 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
                 )}
               </button>
               {this.linkBtn(true)}
+              {cv.comment.language_id != 0 && (
+                <span className="">
+                  {
+                    this.props.allLanguages.find(
+                      lang => lang.id === cv.comment.language_id
+                    )?.name
+                  }
+                </span>
+              )}
               {/* This is an expanding spacer for mobile */}
-              <div className="mr-lg-5 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2"></div>
+              <div className="mr-lg-5 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2" />
               {showScores() && (
                 <>
                   <a
@@ -294,8 +304,8 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
                     <span
                       className="mr-1 font-weight-bold"
                       aria-label={i18n.t("number_of_points", {
-                        count: this.state.score,
-                        formattedCount: this.state.score,
+                        count: Number(this.state.score),
+                        formattedCount: numToSI(this.state.score),
                       })}
                     >
                       {numToSI(this.state.score)}
@@ -428,7 +438,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
                               <button className="btn btn-link btn-animate">
                                 <Link
                                   className="text-muted"
-                                  to={`/create_private_message/recipient/${cv.creator.id}`}
+                                  to={`/create_private_message/${cv.creator.id}`}
                                   title={i18n.t("message").toLowerCase()}
                                 >
                                   <Icon icon="mail" />
@@ -599,9 +609,9 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
                                       this,
                                       this.handleModBanFromCommunityShow
                                     )}
-                                    aria-label={i18n.t("ban")}
+                                    aria-label={i18n.t("ban_from_community")}
                                   >
-                                    {i18n.t("ban")}
+                                    {i18n.t("ban_from_community")}
                                   </button>
                                 ) : (
                                   <button
@@ -1044,11 +1054,14 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
       ? i18n.t("show_context")
       : i18n.t("link");
 
+    // The context button should show the parent comment by default
+    const parentCommentId = getCommentParentId(cv.comment) ?? cv.comment.id;
+
     return (
       <>
         <Link
           className={classnames}
-          to={`/comment/${cv.comment.id}`}
+          to={`/comment/${parentCommentId}`}
           title={title}
         >
           <Icon icon="link" classes="icon-inline" />
@@ -1276,7 +1289,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
     let comment = i.props.node.comment_view.comment;
     let auth = myAuth();
     if (auth) {
-      let form: EditComment = {
+      let form: DistinguishComment = {
         comment_id: comment.id,
         distinguished: !comment.distinguished,
         auth,
@@ -1541,7 +1554,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
       parent_id: i.props.node.comment_view.comment.id,
       max_depth: commentTreeMaxDepth,
       limit: 999, // TODO
-      type_: ListingType.All,
+      type_: "All",
       saved_only: false,
       auth: myAuth(false),
     };
@@ -1561,18 +1574,18 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
 
   get pointsTippy(): string {
     let points = i18n.t("number_of_points", {
-      count: this.state.score,
-      formattedCount: this.state.score,
+      count: Number(this.state.score),
+      formattedCount: numToSI(this.state.score),
     });
 
     let upvotes = i18n.t("number_of_upvotes", {
-      count: this.state.upvotes,
-      formattedCount: this.state.upvotes,
+      count: Number(this.state.upvotes),
+      formattedCount: numToSI(this.state.upvotes),
     });
 
     let downvotes = i18n.t("number_of_downvotes", {
-      count: this.state.downvotes,
-      formattedCount: this.state.downvotes,
+      count: Number(this.state.downvotes),
+      formattedCount: numToSI(this.state.downvotes),
     });
 
     return `${points} • ${upvotes} • ${downvotes}`;