diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 005d900..52b7edb 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,14 +4,8 @@
-
-
-
-
-
-
-
-
+
+
@@ -151,7 +145,6 @@
-
@@ -174,7 +167,8 @@
-
+
+
true
diff --git a/web/src/stores/notifications.ts b/web/src/stores/notifications.ts
index 54cd327..784f582 100755
--- a/web/src/stores/notifications.ts
+++ b/web/src/stores/notifications.ts
@@ -1,64 +1,66 @@
-import { defineStore } from "pinia";
-import { ref } from "vue";
-import { checkLoggedIn, getAtk } from "@/stores/userinfo";
-import { request } from "@/scripts/request";
+import { defineStore } from "pinia"
+import { ref } from "vue"
+import { checkLoggedIn, getAtk } from "@/stores/userinfo"
+import { request } from "@/scripts/request"
export const useNotifications = defineStore("notifications", () => {
- let socket: WebSocket;
+ let socket: WebSocket
- const loading = ref(false);
+ const loading = ref(false)
- const notifications = ref([]);
+ const notifications = ref([])
const total = ref(0)
async function list() {
- loading.value = true;
+ loading.value = true
const res = await request(
"/api/notifications?" +
new URLSearchParams({
take: (25).toString(),
- offset: (0).toString()
+ offset: (0).toString(),
}),
{
- headers: { Authorization: `Bearer ${getAtk()}` }
- }
- );
+ headers: { Authorization: `Bearer ${getAtk()}` },
+ },
+ )
if (res.status === 200) {
- const data = await res.json();
- notifications.value = data["data"];
- total.value = data["count"];
+ const data = await res.json()
+ notifications.value = data["data"]
+ total.value = data["count"]
}
- loading.value = false;
+ loading.value = false
}
function remove(idx: number) {
notifications.value.splice(idx, 1)
- total.value--;
+ total.value--
}
async function connect() {
- if (!(checkLoggedIn())) return;
+ if (!(checkLoggedIn())) return
- const uri = `ws://${window.location.host}/api/ws`;
+ const uri = `ws://${window.location.host}/api/ws`
- socket = new WebSocket(uri + `?tk=${getAtk() as string}`);
+ socket = new WebSocket(uri + `?tk=${getAtk() as string}`)
socket.addEventListener("open", (event) => {
- console.log("[NOTIFICATIONS] The listen websocket has been established... ", event.type);
- });
+ console.log("[NOTIFICATIONS] The listen websocket has been established... ", event.type)
+ })
socket.addEventListener("close", (event) => {
- console.warn("[NOTIFICATIONS] The listen websocket is disconnected... ", event.reason, event.code);
- });
+ console.warn("[NOTIFICATIONS] The listen websocket is disconnected... ", event.reason, event.code)
+ })
socket.addEventListener("message", (event) => {
- const data = JSON.parse(event.data);
- notifications.value.push(data);
- total.value++;
- });
+ const data = JSON.parse(event.data)
+ if (data["w"] == "notifications.new") {
+ notifications.value.push(data["p"])
+ total.value++
+ }
+ })
}
function disconnect() {
- socket.close();
+ socket.close()
}
- return { loading, notifications, total, list, remove, connect, disconnect };
-});
\ No newline at end of file
+ return { loading, notifications, total, list, remove, connect, disconnect }
+})
\ No newline at end of file