ReviewDB: allow deleting reviews on own profile
This commit is contained in:
parent
f66e35b658
commit
664dd0a992
@ -20,7 +20,7 @@ import { openUserProfile } from "@utils/discord";
|
||||
import { classes } from "@utils/misc";
|
||||
import { LazyComponent } from "@utils/react";
|
||||
import { filters, findBulk } from "@webpack";
|
||||
import { Alerts, moment, Parser, Timestamp, UserStore } from "@webpack/common";
|
||||
import { Alerts, moment, Parser, Timestamp } from "@webpack/common";
|
||||
|
||||
import { Review, ReviewType } from "../entities";
|
||||
import { deleteReview, reportReview } from "../reviewDbApi";
|
||||
@ -30,7 +30,7 @@ import { DeleteButton, ReportButton } from "./MessageButton";
|
||||
import ReviewBadge from "./ReviewBadge";
|
||||
|
||||
export default LazyComponent(() => {
|
||||
// this is terrible, blame ven
|
||||
// this is terrible, blame mantika
|
||||
const p = filters.byProps;
|
||||
const [
|
||||
{ cozyMessage, buttons, message, buttonsInner, groupStart },
|
||||
@ -48,7 +48,7 @@ export default LazyComponent(() => {
|
||||
|
||||
const dateFormat = new Intl.DateTimeFormat();
|
||||
|
||||
return function ReviewComponent({ review, refetch }: { review: Review; refetch(): void; }) {
|
||||
return function ReviewComponent({ review, refetch, profileId }: { review: Review; refetch(): void; profileId: string; }) {
|
||||
function openModal() {
|
||||
openUserProfile(review.sender.discordID);
|
||||
}
|
||||
@ -135,7 +135,7 @@ export default LazyComponent(() => {
|
||||
<div className={classes(buttonClasses.wrapper, buttonsInner)} >
|
||||
<ReportButton onClick={reportRev} />
|
||||
|
||||
{canDeleteReview(review, UserStore.getCurrentUser().id) && (
|
||||
{canDeleteReview(profileId, review) && (
|
||||
<DeleteButton onClick={delReview} />
|
||||
)}
|
||||
</div>
|
||||
|
@ -79,6 +79,7 @@ export default function ReviewsView({
|
||||
refetch={refetch}
|
||||
reviews={reviewData!.reviews}
|
||||
hideOwnReview={hideOwnReview}
|
||||
profileId={discordId}
|
||||
/>
|
||||
|
||||
{showInput && (
|
||||
@ -93,7 +94,7 @@ export default function ReviewsView({
|
||||
);
|
||||
}
|
||||
|
||||
function ReviewList({ refetch, reviews, hideOwnReview }: { refetch(): void; reviews: Review[]; hideOwnReview: boolean; }) {
|
||||
function ReviewList({ refetch, reviews, hideOwnReview, profileId }: { refetch(): void; reviews: Review[]; hideOwnReview: boolean; profileId: string; }) {
|
||||
const myId = UserStore.getCurrentUser().id;
|
||||
|
||||
return (
|
||||
@ -104,6 +105,7 @@ function ReviewList({ refetch, reviews, hideOwnReview }: { refetch(): void; revi
|
||||
key={review.id}
|
||||
review={review}
|
||||
refetch={refetch}
|
||||
profileId={profileId}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
@ -20,7 +20,7 @@ import { classNameFactory } from "@api/Styles";
|
||||
import { Logger } from "@utils/Logger";
|
||||
import { openModal } from "@utils/modal";
|
||||
import { findByProps } from "@webpack";
|
||||
import { React, Toasts } from "@webpack/common";
|
||||
import { React, Toasts, UserStore } from "@webpack/common";
|
||||
|
||||
import { Review, UserType } from "./entities";
|
||||
import { settings } from "./settings";
|
||||
@ -73,9 +73,11 @@ export function showToast(text: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function canDeleteReview(review: Review, userId: string) {
|
||||
export function canDeleteReview(profileId: string, review: Review) {
|
||||
const myId = UserStore.getCurrentUser().id;
|
||||
return (
|
||||
review.sender.discordID === userId
|
||||
myId === profileId
|
||||
|| review.sender.discordID === profileId
|
||||
|| settings.store.user?.type === UserType.Admin
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user