From 043381963bf7c3899c3224c05c18ff8542773a3e Mon Sep 17 00:00:00 2001 From: Manti <67705577+mantikafasi@users.noreply.github.com> Date: Sun, 30 Apr 2023 01:53:37 +0300 Subject: [PATCH] ReviewDB: make warning review disableable; add timestamps (#948) --- src/plugins/reviewDB/Utils/ReviewDBAPI.ts | 18 ++++++++---- src/plugins/reviewDB/Utils/Utils.tsx | 9 ++---- .../reviewDB/components/ReviewComponent.tsx | 15 ++++++++-- .../reviewDB/components/ReviewsView.tsx | 19 +++++++++++-- src/plugins/reviewDB/entities/Review.ts | 1 + src/plugins/reviewDB/entities/User.ts | 28 +++++++++++++++++++ src/plugins/reviewDB/index.tsx | 26 ++++++++++++----- 7 files changed, 93 insertions(+), 23 deletions(-) create mode 100644 src/plugins/reviewDB/entities/User.ts diff --git a/src/plugins/reviewDB/Utils/ReviewDBAPI.ts b/src/plugins/reviewDB/Utils/ReviewDBAPI.ts index 74415bb..b9f48d2 100644 --- a/src/plugins/reviewDB/Utils/ReviewDBAPI.ts +++ b/src/plugins/reviewDB/Utils/ReviewDBAPI.ts @@ -19,6 +19,7 @@ import { Settings } from "@api/settings"; import { Review } from "../entities/Review"; +import { ReviewDBUser } from "../entities/User"; import { authorize, showToast } from "./Utils"; const API_URL = "https://manti.vendicated.dev"; @@ -32,8 +33,12 @@ interface Response { updated: boolean; } +const WarningFlag = 0b00000010; + export async function getReviews(id: string): Promise { - const req = await fetch(API_URL + `/api/reviewdb/users/${id}/reviews`); + var flags = 0; + if (!Settings.plugins.ReviewDB.showWarning) flags |= WarningFlag; + const req = await fetch(API_URL + `/api/reviewdb/users/${id}/reviews?flags=${flags}`); const res = (req.status === 200) ? await req.json() as Response : { success: false, message: "An Error occured while fetching reviews. Please try again later.", reviews: [], updated: false }; if (!res.success) { @@ -43,6 +48,7 @@ export async function getReviews(id: string): Promise { id: 0, comment: "An Error occured while fetching reviews. Please try again later.", star: 0, + timestamp: 0, sender: { id: 0, username: "Error", @@ -108,8 +114,10 @@ export async function reportReview(id: number) { showToast(await res.message); } -export function getLastReviewID(id: string): Promise { - return fetch(API_URL + "/getLastReviewID?discordid=" + id) - .then(r => r.text()) - .then(Number); +export function getCurrentUserInfo(token: string): Promise { + return fetch(API_URL + "/api/reviewdb/users", { + body: JSON.stringify({ token }), + method: "POST", + }) + .then(r => r.json()); } diff --git a/src/plugins/reviewDB/Utils/Utils.tsx b/src/plugins/reviewDB/Utils/Utils.tsx index b3cb6cd..7fb907b 100644 --- a/src/plugins/reviewDB/Utils/Utils.tsx +++ b/src/plugins/reviewDB/Utils/Utils.tsx @@ -17,13 +17,13 @@ */ import { Settings } from "@api/settings"; -import { Devs } from "@utils/constants"; import Logger from "@utils/Logger"; import { openModal } from "@utils/modal"; import { findByProps } from "@webpack"; import { FluxDispatcher, React, SelectedChannelStore, Toasts, UserUtils } from "@webpack/common"; import { Review } from "../entities/Review"; +import { UserType } from "../entities/User"; export async function openUserProfileModal(userId: string) { await UserUtils.fetchUser(userId); @@ -86,10 +86,5 @@ export function showToast(text: string) { export const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); export function canDeleteReview(review: Review, userId: string) { - if (review.sender.discordID === userId) return true; - - const myId = BigInt(userId); - return myId === Devs.mantikafasi.id || - myId === Devs.Ven.id || - myId === Devs.rushii.id; + if (review.sender.discordID === userId || Settings.plugins.ReviewDB.userType === UserType.Admin) return true; } diff --git a/src/plugins/reviewDB/components/ReviewComponent.tsx b/src/plugins/reviewDB/components/ReviewComponent.tsx index 7eadeff..76497d1 100644 --- a/src/plugins/reviewDB/components/ReviewComponent.tsx +++ b/src/plugins/reviewDB/components/ReviewComponent.tsx @@ -16,9 +16,10 @@ * along with this program. If not, see . */ +import { Settings } from "@api/settings"; import { classes, LazyComponent } from "@utils/misc"; import { filters, findBulk } from "@webpack"; -import { Alerts, UserStore } from "@webpack/common"; +import { Alerts, moment, Timestamp, UserStore } from "@webpack/common"; import { Review } from "../entities/Review"; import { deleteReview, reportReview } from "../Utils/ReviewDBAPI"; @@ -32,7 +33,7 @@ export default LazyComponent(() => { const [ { cozyMessage, buttons, message, groupStart }, { container, isHeader }, - { avatar, clickable, username, messageContent, wrapper, cozy }, + { avatar, clickable, username, messageContent, wrapper, cozy, timestampInline, timestamp }, { contents }, buttonClasses, { defaultColor } @@ -102,6 +103,16 @@ export default LazyComponent(() => { {review.sender.username} {review.sender.badges.map(badge => )} + + { + !Settings.plugins.ReviewDB.hideTimestamps && ( + + ) + } +

. */ +import { Settings } from "@api/settings"; import { classes, useAwaiter } from "@utils/misc"; import { findLazy } from "@webpack"; import { Forms, React, Text, UserStore } from "@webpack/common"; import type { KeyboardEvent } from "react"; import { addReview, getReviews } from "../Utils/ReviewDBAPI"; -import { showToast } from "../Utils/Utils"; +import { authorize, showToast } from "../Utils/Utils"; import ReviewComponent from "./ReviewComponent"; const Classes = findLazy(m => typeof m.textarea === "string"); export default function ReviewsView({ userId }: { userId: string; }) { + const { token } = Settings.plugins.ReviewDB; const [refetchCount, setRefetchCount] = React.useState(0); const [reviews, _, isLoading] = useAwaiter(() => getReviews(userId), { fallbackValue: [], @@ -83,8 +85,21 @@ export default function ReviewsView({ userId }: { userId: string; }) {