aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/reviewDB/index.tsx
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2023-10-06 19:40:53 +0200
committerVendicated <vendicated@riseup.net>2023-10-06 19:43:24 +0200
commitc0f2c974587d75a38e3e753368ef0e2e2be139fd (patch)
treec1e75f84785d10f207f1f142da0cec6ab01d2443 /src/plugins/reviewDB/index.tsx
parent664dd0a9920aa697359b1bb07b98795ff0f1beaf (diff)
downloadVencord-c0f2c974587d75a38e3e753368ef0e2e2be139fd.tar.gz
Vencord-c0f2c974587d75a38e3e753368ef0e2e2be139fd.tar.bz2
Vencord-c0f2c974587d75a38e3e753368ef0e2e2be139fd.zip
ReviewDB: proper multi account support
Diffstat (limited to 'src/plugins/reviewDB/index.tsx')
-rw-r--r--src/plugins/reviewDB/index.tsx45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/plugins/reviewDB/index.tsx b/src/plugins/reviewDB/index.tsx
index a519713..b9350ba 100644
--- a/src/plugins/reviewDB/index.tsx
+++ b/src/plugins/reviewDB/index.tsx
@@ -23,16 +23,17 @@ import ErrorBoundary from "@components/ErrorBoundary";
import ExpandableHeader from "@components/ExpandableHeader";
import { OpenExternalIcon } from "@components/Icons";
import { Devs } from "@utils/constants";
+import { Logger } from "@utils/Logger";
import definePlugin from "@utils/types";
-import { Alerts, Menu, Parser, useState } from "@webpack/common";
+import { Alerts, Menu, Parser, showToast, useState } from "@webpack/common";
import { Guild, User } from "discord-types/general";
+import { Auth, initAuth, updateAuth } from "./auth";
import { openReviewsModal } from "./components/ReviewModal";
import ReviewsView from "./components/ReviewsView";
import { NotificationType } from "./entities";
import { getCurrentUserInfo, readNotification } from "./reviewDbApi";
import { settings } from "./settings";
-import { showToast } from "./utils";
const guildPopoutPatch: NavContextMenuPatchCallback = (children, props: { guild: Guild, onClose(): void; }) => () => {
children.push(
@@ -62,31 +63,48 @@ export default definePlugin({
}
],
+ flux: {
+ CONNECTION_OPEN: initAuth,
+ },
+
async start() {
+ addContextMenuPatch("guild-header-popout", guildPopoutPatch);
+
const s = settings.store;
- const { token, lastReviewId, notifyReviews } = s;
+ const { lastReviewId, notifyReviews } = s;
+
+ const legacy = s as any as { token?: string; };
+ if (legacy.token) {
+ await updateAuth({ token: legacy.token });
+ legacy.token = undefined;
+ new Logger("ReviewDB").info("Migrated legacy settings");
+ }
- if (!notifyReviews || !token) return;
+ await initAuth();
setTimeout(async () => {
- const user = await getCurrentUserInfo(token);
- if (lastReviewId && lastReviewId < user.lastReviewID) {
- s.lastReviewId = user.lastReviewID;
- if (user.lastReviewID !== 0)
- showToast("You have new reviews on your profile!");
- }
+ if (!Auth.token) return;
+
+ const user = await getCurrentUserInfo(Auth.token);
+ updateAuth({ user });
- addContextMenuPatch("guild-header-popout", guildPopoutPatch);
+ if (notifyReviews) {
+ if (lastReviewId && lastReviewId < user.lastReviewID) {
+ s.lastReviewId = user.lastReviewID;
+ if (user.lastReviewID !== 0)
+ showToast("You have new reviews on your profile!");
+ }
+ }
if (user.notification) {
const props = user.notification.type === NotificationType.Ban ? {
cancelText: "Appeal",
confirmText: "Ok",
- onCancel: () =>
+ onCancel: async () =>
VencordNative.native.openExternal(
"https://reviewdb.mantikafasi.dev/api/redirect?"
+ new URLSearchParams({
- token: settings.store.token!,
+ token: Auth.token!,
page: "dashboard/appeal"
})
)
@@ -105,7 +123,6 @@ export default definePlugin({
readNotification(user.notification.id);
}
- s.user = user;
}, 4000);
},