소스 검색

refactor: Register current user in model store

Owen Diffey 1 개월 전
부모
커밋
522d4842f6
3개의 변경된 파일16개의 추가작업 그리고 28개의 파일을 삭제
  1. 6 23
      frontend/src/App.vue
  2. 2 2
      frontend/src/stores/userAuth.ts
  3. 8 3
      frontend/src/stores/websocket.ts

+ 6 - 23
frontend/src/App.vue

@@ -4,7 +4,6 @@ import { defineAsyncComponent, ref, watch, onMounted } from "vue";
 import Toast from "toasters";
 import { storeToRefs } from "pinia";
 import { GenericResponse } from "@musare_types/actions/GenericActions";
-import { GetPreferencesResponse } from "@musare_types/actions/UsersActions";
 import { useWebsocketsStore } from "@/stores/websockets";
 import { useConfigStore } from "@/stores/config";
 import { useUserAuthStore } from "@/stores/userAuth";
@@ -41,14 +40,10 @@ const broadcastChannel = ref({
 const disconnectedMessage = ref();
 
 const { christmas } = storeToRefs(configStore);
-const { loggedIn, banned } = storeToRefs(userAuthStore);
+const { currentUser, loggedIn, banned } = storeToRefs(userAuthStore);
 const { nightmode, activityWatch } = storeToRefs(userPreferencesStore);
 const {
 	changeNightmode,
-	changeAutoSkipDisliked,
-	changeActivityLogPublic,
-	changeAnonymousSongRequests,
-	changeActivityWatch
 } = userPreferencesStore;
 const { activeModals } = storeToRefs(modalsStore);
 const { openModal, closeCurrentModal } = modalsStore;
@@ -102,6 +97,11 @@ watch(christmas, enabled => {
 	if (enabled) enableChristmasMode();
 	else disableChristmasMode();
 });
+watch(currentUser, user => {
+	if (!user) return;
+
+	changeNightmode(user.nightmode);
+});
 
 onMounted(async () => {
 	document.getElementsByTagName("html")[0].style.cssText =
@@ -183,23 +183,6 @@ onMounted(async () => {
 			}
 		});
 
-		socket.dispatch(
-			"users.getPreferences",
-			(res: GetPreferencesResponse) => {
-				if (res.status === "success") {
-					const { preferences } = res.data;
-
-					changeAutoSkipDisliked(preferences.autoSkipDisliked);
-					changeNightmode(preferences.nightmode);
-					changeActivityLogPublic(preferences.activityLogPublic);
-					changeAnonymousSongRequests(
-						preferences.anonymousSongRequests
-					);
-					changeActivityWatch(preferences.activityWatch);
-				}
-			}
-		);
-
 		openModal("whatIsNew");
 
 		router.isReady().then(() => {

+ 2 - 2
frontend/src/stores/userAuth.ts

@@ -3,7 +3,7 @@ import { computed, ref } from "vue";
 import validation from "@/validation";
 import { useWebsocketStore } from "@/stores/websocket";
 import { useConfigStore } from "@/stores/config";
-import { User } from "@/types/user";
+import Model from "@/Model";
 
 export const useUserAuthStore = defineStore("userAuth", () => {
 	const configStore = useConfigStore();
@@ -19,7 +19,7 @@ export const useUserAuthStore = defineStore("userAuth", () => {
 			((basicUser: { name: string; username: string }) => void)[]
 		>
 	>({});
-	const currentUser = ref<User | null>();
+	const currentUser = ref<Model | null>();
 	const banned = ref(false);
 	const ban = ref<{
 		reason?: string;

+ 8 - 3
frontend/src/stores/websocket.ts

@@ -5,6 +5,7 @@ import { forEachIn } from "@common/utils/forEachIn";
 import { useConfigStore } from "./config";
 import { useUserAuthStore } from "./userAuth";
 import ms from "@/ms";
+import { useModelStore } from "./model";
 
 export const useWebsocketStore = defineStore("websocket", () => {
 	const configStore = useConfigStore();
@@ -182,7 +183,13 @@ export const useWebsocketStore = defineStore("websocket", () => {
 	subscribe("ready", async data => {
 		configStore.$patch(data.config);
 
-		userAuthStore.currentUser = data.user;
+		const modelStore = useModelStore();
+
+		ready.value = true;
+
+		userAuthStore.currentUser = data.user
+			? await modelStore.registerModel(data.user)
+			: null;
 		userAuthStore.gotData = true;
 
 		if (userAuthStore.loggedIn) {
@@ -192,8 +199,6 @@ export const useWebsocketStore = defineStore("websocket", () => {
 		if (configStore.experimental.media_session) ms.initialize();
 		else ms.uninitialize();
 
-		ready.value = true;
-
 		await userAuthStore.updatePermissions();
 
 		await forEachIn(