From 3bf1cc2797261343ba45bcbe12113009243021cd Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 17 Aug 2022 19:26:50 -0400 Subject: [PATCH] Adding mod / admin distinguish. (#744) --- lemmy-translations | 2 +- package.json | 2 +- .../components/comment/comment-form.tsx | 3 +- .../components/comment/comment-node.tsx | 68 +++++++++++++++++-- src/shared/components/post/post.tsx | 1 + src/shared/utils.ts | 6 +- yarn.lock | 8 +-- 7 files changed, 77 insertions(+), 13 deletions(-) diff --git a/lemmy-translations b/lemmy-translations index 7c39457..9ba11fa 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit 7c3945745dcd07774b19453803f7f14ab80ab3d3 +Subproject commit 9ba11fa31001baac6bacb4eea651942cc48d41a9 diff --git a/package.json b/package.json index 31e9c87..853c4fa 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "eslint-plugin-prettier": "^4.2.1", "husky": "^8.0.1", "import-sort-style-module": "^6.0.0", - "lemmy-js-client": "0.17.0-rc.39", + "lemmy-js-client": "0.17.0-rc.41", "lint-staged": "^13.0.3", "mini-css-extract-plugin": "^2.6.1", "node-fetch": "^2.6.1", diff --git a/src/shared/components/comment/comment-form.tsx b/src/shared/components/comment/comment-form.tsx index 64841e7..6778b68 100644 --- a/src/shared/components/comment/comment-form.tsx +++ b/src/shared/components/comment/comment-form.tsx @@ -112,7 +112,8 @@ export class CommentForm extends Component { left: node => { if (this.props.edit) { let form = new EditComment({ - content, + content: Some(content), + distinguished: None, form_id: this.state.formId, comment_id: node.comment_view.comment.id, auth: auth().unwrap(), diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index d4bd1fe..f654b65 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -15,6 +15,7 @@ import { CreateCommentLike, CreateCommentReport, DeleteComment, + EditComment, GetComments, ListingType, MarkCommentReplyAsRead, @@ -171,7 +172,20 @@ export class CommentNode extends Component { this.props.admins, cv.creator.id ); + let canModOnSelf = canMod( + this.props.moderators, + this.props.admins, + cv.creator.id, + UserService.Instance.myUserInfo, + true + ); let canAdmin_ = canAdmin(this.props.admins, cv.creator.id); + let canAdminOnSelf = canAdmin( + this.props.admins, + cv.creator.id, + UserService.Instance.myUserInfo, + true + ); let isMod_ = isMod(this.props.moderators, cv.creator.id); let isAdmin_ = isAdmin(this.props.admins, cv.creator.id); let amCommunityCreator_ = amCommunityCreator( @@ -200,9 +214,12 @@ export class CommentNode extends Component { >
{ - + {cv.comment.distinguished && ( + + )} {isMod_ && (
{i18n.t("mod")} @@ -516,6 +535,34 @@ export class CommentNode extends Component { }`} /> + + {(canModOnSelf || canAdminOnSelf) && ( + + )} )} {/* Admins and mods can remove comments */} @@ -1204,6 +1251,19 @@ export class CommentNode extends Component { i.setState(i.state); } + handleDistinguishClick(i: CommentNode) { + let comment = i.props.node.comment_view.comment; + let form = new EditComment({ + comment_id: comment.id, + form_id: None, // TODO not sure about this + content: None, + distinguished: Some(!comment.distinguished), + auth: auth().unwrap(), + }); + WebSocketService.Instance.send(wsClient.editComment(form)); + i.setState(i.state); + } + isPersonMentionType( item: CommentView | PersonMentionView | CommentReplyView ): item is PersonMentionView { diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index 33e0978..58cf71e 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -721,6 +721,7 @@ export class Post extends Component { this.state.commentsRes.map(r => r.comments).unwrapOr([]) ); this.setState(this.state); + setupTippy(); } else if (op == UserOperation.SaveComment) { let data = wsJsonToRes(msg, CommentResponse); saveCommentRes( diff --git a/src/shared/utils.ts b/src/shared/utils.ts index b19ee22..3354fcc 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -210,9 +210,10 @@ export function canMod( export function canAdmin( admins: Option, creator_id: number, - myUserInfo = UserService.Instance.myUserInfo + myUserInfo = UserService.Instance.myUserInfo, + onSelf = false ): boolean { - return canMod(None, admins, creator_id, myUserInfo); + return canMod(None, admins, creator_id, myUserInfo, onSelf); } export function isMod( @@ -830,6 +831,7 @@ export function editCommentRes(data: CommentView, comments: CommentView[]) { let found = comments.find(c => c.comment.id == data.comment.id); if (found) { found.comment.content = data.comment.content; + found.comment.distinguished = data.comment.distinguished; found.comment.updated = data.comment.updated; found.comment.removed = data.comment.removed; found.comment.deleted = data.comment.deleted; diff --git a/yarn.lock b/yarn.lock index f972e11..5549562 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5056,10 +5056,10 @@ lcid@^1.0.0: dependencies: invert-kv "^1.0.0" -lemmy-js-client@0.17.0-rc.39: - version "0.17.0-rc.39" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.39.tgz#b17c5c0d9a0f36c90c17be99845a5703091ab306" - integrity sha512-MsKavo5xOob6DgfjyhbmXyFvXwdW4iwftStJ7Bz3ArlHXy6zGBp+2uy2rU2c5ujivNDX72ol3TupTHBtSXLs4w== +lemmy-js-client@0.17.0-rc.41: + version "0.17.0-rc.41" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.41.tgz#a72bd41b76af834d97914d3790810efa610a6e89" + integrity sha512-VJ0qMXaEuOvmUxWR/jWnnoWknpNSXxbz/J29ADTn9arJEbOfTQB60ILeg8wICSRI23jzU9/0lqAZ+rjgXN0p4w== levn@^0.4.1: version "0.4.1" -- 2.44.1