From 999b083545d3dacbc119047fecd9b7da95d40a96 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 3 Aug 2024 14:56:19 -0400 Subject: [PATCH] More moderation history (#2649) * Updating translations. * Adding a link to view all a user's moderation history from an item. - Also making moderation history strings more detailed. * Fix. * Adding admin view moderation history to profile page. * Adding admin view moderation history to profile page. --- lemmy-translations | 2 +- .../content-action-dropdown.tsx | 42 +++++++++++++++---- .../components/common/markdown-textarea.tsx | 33 +++++++-------- src/shared/components/person/profile.tsx | 32 +++++++++----- src/shared/markdown.ts | 14 +++---- 5 files changed, 80 insertions(+), 43 deletions(-) diff --git a/lemmy-translations b/lemmy-translations index 088a2770..1f4e378f 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit 088a27703ffa65e069dfbf341ee9bd44ec4c45c5 +Subproject commit 1f4e378f2e18d843aec1e421b99a69a76ce633b7 diff --git a/src/shared/components/common/content-actions/content-action-dropdown.tsx b/src/shared/components/common/content-actions/content-action-dropdown.tsx index 5c7fbb2d..fd3513d8 100644 --- a/src/shared/components/common/content-actions/content-action-dropdown.tsx +++ b/src/shared/components/common/content-actions/content-action-dropdown.tsx @@ -159,6 +159,26 @@ export default class ContentActionDropdown extends Component< (amMod(community.id) || (amAdmin() && community.local)) && !creator_banned_from_community; + const modHistoryUserTranslation = I18NextService.i18n.t( + "user_moderation_history", + { user: creator.name }, + ); + + // The link and translation string for the item + const { modHistoryItemLink, modHistoryItemTranslation } = + type === "post" + ? { + modHistoryItemLink: `/modlog?postId=${id}`, + modHistoryItemTranslation: I18NextService.i18n.t( + "post_moderation_history", + ), + } + : { + modHistoryItemLink: `/modlog?commentId=${id}`, + modHistoryItemTranslation: I18NextService.i18n.t( + "comment_moderation_history", + ), + }; return ( <> {type === "comment" && ( @@ -349,15 +369,23 @@ export default class ContentActionDropdown extends Component<
  • - {I18NextService.i18n.t("moderation_history")} + {modHistoryUserTranslation} + + + + {modHistoryItemTranslation}
  • {(this.canMod || this.canAdmin) && ( diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index 6e5e2f2e..107c152a 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -76,8 +76,6 @@ export class MarkdownTextArea extends Component< private id = `markdown-textarea-${randomStr()}`; private formId = `markdown-form-${randomStr()}`; - private tribute: any; - state: MarkdownTextAreaState = { content: this.props.initialContent, languageId: this.props.initialLanguageId, @@ -91,26 +89,25 @@ export class MarkdownTextArea extends Component< this.handleLanguageChange = this.handleLanguageChange.bind(this); this.handleEmoji = this.handleEmoji.bind(this); - - if (isBrowser()) { - this.tribute = setupTribute(); - } } - componentDidMount() { - const textarea: any = document.getElementById(this.id); - if (textarea) { - autosize(textarea); - this.tribute.attach(textarea); - textarea.addEventListener("tribute-replaced", () => { - this.setState({ content: textarea.value }); - autosize.update(textarea); - }); + async componentDidMount() { + if (isBrowser()) { + const tribute = await setupTribute(); + const textarea: any = document.getElementById(this.id); + if (textarea) { + autosize(textarea); + tribute.attach(textarea); + textarea.addEventListener("tribute-replaced", () => { + this.setState({ content: textarea.value }); + autosize.update(textarea); + }); - this.quoteInsert(); + this.quoteInsert(); - if (this.props.focus) { - textarea.focus(); + if (this.props.focus) { + textarea.focus(); + } } } } diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx index 8f103838..02589271 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -20,7 +20,7 @@ import { resourcesSettled, bareRoutePush, } from "@utils/helpers"; -import { canMod } from "@utils/roles"; +import { amAdmin, canMod } from "@utils/roles"; import type { QueryParams } from "@utils/types"; import { RouteDataResponse } from "@utils/types"; import classNames from "classnames"; @@ -671,15 +671,27 @@ export class Profile extends Component {
    {!this.amCurrentUser && UserService.Instance.myUserInfo && ( <> - - {I18NextService.i18n.t("send_secure_message")} - + {amAdmin() && ( + + {I18NextService.i18n.t("user_moderation_history", { + user: pv.person.name, + })} + + )} + {pv.person.matrix_user_id && ( + + {I18NextService.i18n.t("send_secure_message")} + + )} = new Map< CustomEmojiView >(); -if (isBrowser()) { - Tribute = await import("tributejs"); -} - export function mdToHtml(text: string, rerender: () => void) { return { __html: lazyHighlightjs.render(md, text, rerender) }; } @@ -340,7 +335,12 @@ export function getEmojiMart( return new Picker(pickerOptions); } -export function setupTribute() { +export async function setupTribute() { + if (Tribute === null) { + console.debug("Tribute is null, importing..."); + Tribute = (await import("tributejs")).default; + } + return new Tribute({ noMatchTemplate: function () { return "";