Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ 添加聊天消息右键菜单 #94

Merged
merged 5 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
"dependencies": {
"@formkit/auto-animate": "1.0.0-beta.6",
"@highlightjs/vue-plugin": "^2.1.0",
"@imengyu/vue3-context-menu": "^1.2.10",
"@msgpack/msgpack": "^2.8.0",
"@tauri-apps/api": "^1.4.0",
"@unocss/reset": "^0.54.0",
"@vueuse/components": "^10.0.0",
"@vueuse/core": "^10.0.0",
"@vueuse/rxjs": "^10.0.0",
"ant-design-vue": "^3.2.17",
"clipboard": "^2.0.11",
"dayjs": "^1.11.7",
"dexie": "^3.2.3",
"highlight.js": "^11.7.0",
Expand Down
36 changes: 36 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/components/ChatBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useDebounceFn } from '@vueuse/core'
import { OverlayScrollbarsComponent } from 'overlayscrollbars-vue'
import { watchEffect } from 'vue'
import { onBeforeRouteLeave } from 'vue-router'
import { onBeforeRouteLeave, onBeforeRouteUpdate } from 'vue-router'
import { DynamicScroller, DynamicScrollerItem } from 'vue-virtual-scroller'

import { Behav } from '@/adapter/behav'
Expand All @@ -15,9 +15,10 @@ import ChatRequest from '@/components/ChatRequest.vue'
import SendButton from '@/components/SendButton.vue'
import TimeSeparator from '@/components/TimeSeparator.vue'
import { db } from '@/database'
import { useChatStore, useStatusStore } from '@/stores'
import { useChatStore, useStatusStore, useSessionStore } from '@/stores'

import type { User, Group } from '@/database'
import type { State } from '@/stores/session'
import type { PartialOptions, OverlayScrollbars } from 'overlayscrollbars'

const { chatType, chatId } = defineProps<{
Expand All @@ -38,6 +39,8 @@ const chat = useChatStore()

const status = useStatusStore()

const session = useSessionStore()

const chatInput = $ref<InstanceType<typeof ChatInput> | null>(null)

const scroller = $ref<InstanceType<typeof OverlayScrollbarsComponent> | null>(null)
Expand Down Expand Up @@ -125,6 +128,11 @@ function lockScroll() {
scrollLock = true
}

onBeforeRouteUpdate(async (to, from) => {
session.saveSessionState(from.fullPath)
await session.loadSessionState(to.fullPath, to.params.chatType as State['type'], to.params.chatId as State['id'])
})

onBeforeRouteLeave((_, from) => {
status.latelySession = from.fullPath
})
Expand Down
42 changes: 41 additions & 1 deletion src/components/ChatInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useRoute } from 'vue-router'
import AudioIcon from '@/assets/audio_file.svg?url'
import VideoIcon from '@/assets/video_file.svg?url'
import { db } from '@/database'
import { useStatusStore } from '@/stores'
import { useStatusStore, useSessionStore } from '@/stores'
import { createFileCache, getUserAvatar, getGroupAvatar, nonNullable, getUserNickname } from '@/utils'

import type { Contents } from '@/adapter/content'
Expand All @@ -25,6 +25,8 @@ const route = useRoute()

const status = useStatusStore()

const session = useSessionStore()

const inputBox = $ref<HTMLDivElement | null>(null)

onMounted(() => {
Expand Down Expand Up @@ -106,6 +108,7 @@ function clearContent(): void {
if (inputBox) {
inputBox.textContent = ''
}
clearReplyMessage()
}

/** 获取输入内容 */
Expand All @@ -123,6 +126,14 @@ function getContent(): Contents[] | null {
contents.push(content)
}
}
if (session.state?.replyMessage) {
contents.unshift({
type: 'reply',
data: {
message_id: session.state.replyMessage.id,
},
})
}
return contents
}

Expand Down Expand Up @@ -221,16 +232,45 @@ const tribute = new Tribute<Mentions>({
return item.name + item.id
},
})

function clearReplyMessage(): void {
if (session.state) {
session.state.replyMessage = undefined
}
}

function onBackspace(): void {
if (inputBox?.textContent === '') {
clearReplyMessage()
}
}
</script>

<template>
<OverlayScrollbarsComponent class="h-full max-h-25 w-full rounded-2xl bg-gray-100" defer>
<div v-show="session.state?.replyMessage" class="mx-2 mt-1.5 rounded-lg bg-gray-200 px-3 py-1.5">
<div class="text-sm text-gray-400">
<div>{{ session.state?.replyMessage?.nickname }}:</div>
<div class="flex flex-row items-center justify-between gap-1">
<div class="restrict-rows-1">
{{ session.state?.replyMessage?.message }}
</div>
<span
i="carbon-close-outline"
class="inline-block flex-none text-base"
hover="text-gray-500"
@click="clearReplyMessage"
></span>
</div>
</div>
</div>
<div
ref="inputBox"
class="whitespace-pre-wrap break-all bg-gray-100 px-2 py-1 align-middle text-sm text-gray-500 caret-gray-500/50 outline-none"
contenteditable
@paste.prevent="onPaste"
@keydown.ctrl.enter="$emit('send')"
@keydown.backspace="onBackspace"
></div>
</OverlayScrollbarsComponent>
</template>
Expand Down
1 change: 1 addition & 0 deletions src/components/ChatMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ async function pokeUser(): Promise<void> {
v-show="showMessage"
class="!bg-transparent"
:class="{ 'bubble-padding': !(onlyImage || onlyType('video')) }"
:message-id="scene.message_id"
:messages="scene.message"
:only-image="onlyImage"
/>
Expand Down
Loading
Loading