From cc2ad2d1134cc0c9e1f9efa19f2ff1eb07f9b6e4 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 22 Nov 2023 11:13:00 -0500 Subject: [PATCH] Adding creator_is_admin and creator_is_mod, removing pointless functions (#2228) --- package.json | 2 +- .../components/comment/comment-node.tsx | 17 +--- .../components/comment/comment-report.tsx | 1 + src/shared/components/community/sidebar.tsx | 4 +- src/shared/components/modlog.tsx | 2 +- src/shared/components/person/profile.tsx | 6 +- src/shared/components/post/post-listing.tsx | 95 ++++++++----------- src/shared/components/post/post-report.tsx | 1 + src/shared/utils/roles/am-mod.ts | 9 +- src/shared/utils/roles/index.ts | 4 - src/shared/utils/roles/is-admin.ts | 8 -- src/shared/utils/roles/is-mod.ts | 8 -- yarn.lock | 8 +- 13 files changed, 64 insertions(+), 101 deletions(-) delete mode 100644 src/shared/utils/roles/is-admin.ts delete mode 100644 src/shared/utils/roles/is-mod.ts diff --git a/package.json b/package.json index 6a7965ef..dd61eb1a 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "inferno-router": "^8.2.2", "inferno-server": "^8.2.2", "jwt-decode": "^3.1.2", - "lemmy-js-client": "0.19.0-alpha.16", + "lemmy-js-client": "0.19.0-rc.15", "lodash.isequal": "^4.5.0", "markdown-it": "^13.0.1", "markdown-it-bidi": "^0.1.0", diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index 00f57dc9..09136f35 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -1,13 +1,6 @@ import { colorList, getCommentParentId, showScores } from "@utils/app"; import { futureDaysToUnixTime, numToSI } from "@utils/helpers"; -import { - amCommunityCreator, - canAdmin, - canMod, - isAdmin, - isBanned, - isMod, -} from "@utils/roles"; +import { amCommunityCreator, canAdmin, canMod, isBanned } from "@utils/roles"; import classNames from "classnames"; import isBefore from "date-fns/isBefore"; import parseISO from "date-fns/parseISO"; @@ -257,8 +250,8 @@ export class CommentNode extends Component { UserService.Instance.myUserInfo, true, ); - const isMod_ = isMod(cv.creator.id, this.props.moderators); - const isAdmin_ = isAdmin(cv.creator.id, this.props.admins); + const isMod_ = cv.creator_is_moderator; + const isAdmin_ = cv.creator_is_admin; const amCommunityCreator_ = amCommunityCreator( cv.creator.id, this.props.moderators, @@ -1461,7 +1454,7 @@ export class CommentNode extends Component { handleAddModToCommunity(i: CommentNode) { i.setState({ addModLoading: true }); - const added = !isMod(i.commentView.comment.creator_id, i.props.moderators); + const added = !i.commentView.creator_is_moderator; i.props.onAddModToCommunity({ community_id: i.commentView.community.id, person_id: i.commentView.creator.id, @@ -1472,7 +1465,7 @@ export class CommentNode extends Component { handleAddAdmin(i: CommentNode) { i.setState({ addAdminLoading: true }); - const added = !isAdmin(i.commentView.comment.creator_id, i.props.admins); + const added = !i.commentView.creator_is_admin; i.props.onAddAdmin({ person_id: i.commentView.creator.id, added, diff --git a/src/shared/components/comment/comment-report.tsx b/src/shared/components/comment/comment-report.tsx index 8d2e0401..94fb35c0 100644 --- a/src/shared/components/comment/comment-report.tsx +++ b/src/shared/components/comment/comment-report.tsx @@ -57,6 +57,7 @@ export class CommentReport extends Component< community: r.community, creator_banned_from_community: r.creator_banned_from_community, creator_is_moderator: false, + creator_is_admin: false, counts: r.counts, subscribed: "NotSubscribed", saved: false, diff --git a/src/shared/components/community/sidebar.tsx b/src/shared/components/community/sidebar.tsx index 810f9695..43f27dd1 100644 --- a/src/shared/components/community/sidebar.tsx +++ b/src/shared/components/community/sidebar.tsx @@ -268,7 +268,7 @@ export class Sidebar extends Component { return ( <>
    - {amMod(this.props.moderators) && ( + {amMod(this.props.community_view.community.id) && ( <>
  • @@ -553,7 +553,7 @@ export class Profile extends Component< )} {canMod(pv.person.id, undefined, admins) && - !isAdmin(pv.person.id, admins) && + !pv.is_admin && !showBanDialog && (!isBanned(pv.person) ? (