-
{{ channels.current?.name }}
-
{{ channels.current?.description }}
+
{{ channels.current?.name }}
+
{{ channels.current?.description }}
@@ -23,7 +23,7 @@
\ No newline at end of file
diff --git a/src/stores/channels.ts b/src/stores/channels.ts
index a221cf4..8edadf7 100644
--- a/src/stores/channels.ts
+++ b/src/stores/channels.ts
@@ -1,7 +1,8 @@
import { defineStore } from "pinia"
-import { reactive, ref } from "vue"
+import { reactive, ref, watch } from "vue"
import { checkLoggedIn, getAtk } from "@/stores/userinfo"
import { buildRequestUrl, request } from "@/scripts/request"
+import { useRoute } from "vue-router"
export const useChannels = defineStore("channels", () => {
let socket: WebSocket
@@ -11,19 +12,40 @@ export const useChannels = defineStore("channels", () => {
const show = reactive({
members: false,
editor: false,
- delete: false
+ delete: false,
+
+ messages: {
+ delete: false
+ }
})
- const related = reactive<{ edit_to: any; manage_to: any; delete_to: any }>({
+ const related = reactive<{ [id: string]: any }>({
edit_to: null,
manage_to: null,
- delete_to: null
+ delete_to: null,
+
+ messages: {
+ edit_to: null,
+ delete_to: null
+ }
})
const available = ref
([])
const current = ref(null)
const messages = ref([])
+ const route = useRoute()
+ watch(
+ () => route.params.channel,
+ (val) => {
+ if (!val) {
+ messages.value = []
+ current.value = null
+ }
+ },
+ { immediate: true }
+ )
+
async function list() {
if (!(await checkLoggedIn())) return
@@ -57,6 +79,17 @@ export const useChannels = defineStore("channels", () => {
switch (data["w"]) {
case "messages.new":
messages.value.unshift(payload)
+ break
+ case "messages.update":
+ messages.value = messages.value.map((x) => {
+ if (x.id === payload.id) return payload
+ else return x
+ })
+ break
+ case "messages.burnt":
+ messages.value = messages.value.filter((x) => {
+ return x.id !== payload.id
+ })
}
}
})
diff --git a/src/views/chat/page.vue b/src/views/chat/page.vue
index 856da48..bd81860 100644
--- a/src/views/chat/page.vue
+++ b/src/views/chat/page.vue
@@ -1,5 +1,5 @@
-
+
@@ -22,7 +22,7 @@
import { useChannels } from "@/stores/channels"
import { request } from "@/scripts/request"
import { useUI } from "@/stores/ui"
-import { computed, reactive, ref, watch } from "vue"
+import { computed, onUnmounted, reactive, ref, watch } from "vue"
import { useRoute } from "vue-router"
import ChatList from "@/components/chat/ChatList.vue"
import ChatEditor from "@/components/chat/ChatEditor.vue"
@@ -83,7 +83,9 @@ async function readMore({ done }: any) {
}
}
-watch(() => channels.current, (val) => {
+watch(
+ () => channels.current,
+ (val) => {
if (val) {
pagination.page = 1
pagination.total = 0