]> Untitled Git - lemmy-ui.git/blobdiff - src/shared/components/comment/comment-node.tsx
Feature/user community block (#362)
[lemmy-ui.git] / src / shared / components / comment / comment-node.tsx
index e276b512fc4f912bd8afe80577164f6869ec855f..1007866708aaedab5299ce6a236421390ef7e886 100644 (file)
@@ -5,6 +5,7 @@ import {
   AddModToCommunity,
   BanFromCommunity,
   BanPerson,
+  BlockPerson,
   CommentView,
   CommunityModeratorView,
   CreateCommentLike,
@@ -279,7 +280,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
                       )}
                     </button>
                   )}
-                  {UserService.Instance.localUserView && !this.props.viewOnly && (
+                  {UserService.Instance.myUserInfo && !this.props.viewOnly && (
                     <>
                       <button
                         className={`btn btn-link btn-animate ${
@@ -333,15 +334,28 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
                       ) : (
                         <>
                           {!this.myComment && (
-                            <button class="btn btn-link btn-animate">
-                              <Link
-                                className="text-muted"
-                                to={`/create_private_message/recipient/${cv.creator.id}`}
-                                title={i18n.t("message").toLowerCase()}
+                            <>
+                              <button class="btn btn-link btn-animate">
+                                <Link
+                                  className="text-muted"
+                                  to={`/create_private_message/recipient/${cv.creator.id}`}
+                                  title={i18n.t("message").toLowerCase()}
+                                >
+                                  <Icon icon="mail" />
+                                </Link>
+                              </button>
+                              <button
+                                class="btn btn-link btn-animate text-muted"
+                                onClick={linkEvent(
+                                  this,
+                                  this.handleBlockUserClick
+                                )}
+                                data-tippy-content={i18n.t("block_user")}
+                                aria-label={i18n.t("block_user")}
                               >
-                                <Icon icon="mail" />
-                              </Link>
-                            </button>
+                                <Icon icon="slash" />
+                              </button>
+                            </>
                           )}
                           <button
                             class="btn btn-link btn-animate text-muted"
@@ -829,7 +843,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
   get myComment(): boolean {
     return (
       this.props.node.comment_view.creator.id ==
-      UserService.Instance.localUserView?.person.id
+      UserService.Instance.myUserInfo?.local_user_view.person.id
     );
   }
 
@@ -864,7 +878,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
         .concat(this.props.moderators.map(m => m.moderator.id));
 
       return canMod(
-        UserService.Instance.localUserView,
+        UserService.Instance.myUserInfo,
         adminsThenMods,
         this.props.node.comment_view.creator.id
       );
@@ -877,7 +891,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
     return (
       this.props.admins &&
       canMod(
-        UserService.Instance.localUserView,
+        UserService.Instance.myUserInfo,
         this.props.admins.map(a => a.person.id),
         this.props.node.comment_view.creator.id
       )
@@ -887,10 +901,10 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
   get amCommunityCreator(): boolean {
     return (
       this.props.moderators &&
-      UserService.Instance.localUserView &&
+      UserService.Instance.myUserInfo &&
       this.props.node.comment_view.creator.id !=
-        UserService.Instance.localUserView.person.id &&
-      UserService.Instance.localUserView.person.id ==
+        UserService.Instance.myUserInfo.local_user_view.person.id &&
+      UserService.Instance.myUserInfo.local_user_view.person.id ==
         this.props.moderators[0].moderator.id
     );
   }
@@ -898,10 +912,10 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
   get amSiteCreator(): boolean {
     return (
       this.props.admins &&
-      UserService.Instance.localUserView &&
+      UserService.Instance.myUserInfo &&
       this.props.node.comment_view.creator.id !=
-        UserService.Instance.localUserView.person.id &&
-      UserService.Instance.localUserView.person.id ==
+        UserService.Instance.myUserInfo.local_user_view.person.id &&
+      UserService.Instance.myUserInfo.local_user_view.person.id ==
         this.props.admins[0].person.id
     );
   }
@@ -925,6 +939,15 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
     i.setState(i.state);
   }
 
+  handleBlockUserClick(i: CommentNode) {
+    let blockUserForm: BlockPerson = {
+      person_id: i.props.node.comment_view.creator.id,
+      block: true,
+      auth: authField(),
+    };
+    WebSocketService.Instance.send(wsClient.blockPerson(blockUserForm));
+  }
+
   handleDeleteClick(i: CommentNode) {
     let comment = i.props.node.comment_view.comment;
     let deleteForm: DeleteComment = {