perf: 优化引用消息

This commit is contained in:
kuaifan 2025-03-14 19:53:00 +08:00
parent 69fc0a118b
commit cf5e126eaa
8 changed files with 101 additions and 37 deletions

View File

@ -548,7 +548,7 @@ export default {
'isModKey',
]),
...mapGetters(['getDialogDraft']),
...mapGetters(['getDialogDraft', 'getDialogQuote']),
isEnterSend({cacheKeyboard}) {
if (this.$isEEUiApp) {
@ -687,16 +687,16 @@ export default {
return this.dialogId > 0 ? (this.cacheDialogs.find(({id}) => id == this.dialogId) || {}) : {};
},
quoteUpdate() {
return this.dialogData.extra_quote_type === 'update'
draftData() {
return this.getDialogDraft(this.dialogId)?.content || ''
},
quoteData() {
const {extra_quote_id} = this.dialogData;
if (extra_quote_id) {
return this.dialogMsgs.find(item => item.id === extra_quote_id)
}
return null;
return this.getDialogQuote(this.dialogId)?.content || null
},
quoteUpdate() {
return this.getDialogQuote(this.dialogId)?.type === 'update'
},
chatInputBoxStyle({iOSDevices, fullInput, viewportHeight}) {
@ -705,10 +705,6 @@ export default {
style.height = Math.max(100, viewportHeight - 70) + 'px'
}
return style
},
inputDraft() {
return this.getDialogDraft(this.dialogId)
}
},
watch: {
@ -750,7 +746,7 @@ export default {
this.loadInputDraft()
},
inputDraft() {
draftData() {
if (this.isFocus) {
return
}
@ -1214,12 +1210,12 @@ export default {
},
loadInputDraft() {
if (this.simpleMode || !this.inputDraft) {
if (this.simpleMode || !this.draftData) {
this.$emit('input', '')
return
}
this.pasteClean = false
this.$emit('input', this.inputDraft)
this.$emit('input', this.draftData)
this.$nextTick(_ => this.pasteClean = true)
},
@ -1718,10 +1714,18 @@ export default {
},
setQuote(id, type = 'reply') {
this.dialogId > 0 && this.$store.dispatch("saveDialog", {
if (this.dialogId <= 0) {
return
}
const content = this.dialogMsgs.find(item => item.id == id && item.dialog_id == this.dialogId)
if (!content) {
this.$store.dispatch("removeDialogQuote", this.dialogId);
return
}
this.$store.dispatch("saveDialogQuote", {
id: this.dialogId,
extra_quote_id: id,
extra_quote_type: type === 'update' ? 'update' : 'reply'
type: type === 'update' ? 'update' : 'reply',
content
});
},

View File

@ -18,7 +18,7 @@
</template>
<script>
import {mapState} from "vuex";
import {mapGetters} from "vuex";
export default {
name: 'DialogUpload',
@ -42,7 +42,7 @@ export default {
},
computed: {
...mapState(['cacheDialogs']),
...mapGetters(['getDialogQuote']),
headers() {
return {
@ -54,12 +54,12 @@ export default {
params() {
return {
dialog_id: this.dialogId,
reply_id: this.dialogData.extra_quote_id || 0,
reply_id: this.quoteData?.id || 0,
}
},
dialogData() {
return this.cacheDialogs.find(({id}) => id == this.dialogId) || {};
quoteData() {
return this.getDialogQuote(this.dialogId)?.content || null
},
},

View File

@ -952,7 +952,7 @@ export default {
'cacheTranslationLanguage'
]),
...mapGetters(['isLoad']),
...mapGetters(['isLoad', 'getDialogQuote']),
isReady() {
return this.dialogId > 0 && this.dialogData.id > 0
@ -1191,15 +1191,19 @@ export default {
return this.dialogData.is_disable ?? false
},
quoteData() {
return this.getDialogQuote(this.dialogId)?.content || null
},
quoteUpdate() {
return this.getDialogQuote(this.dialogId)?.type === 'update'
},
quoteId() {
if (this.msgId > 0) {
return this.msgId
}
return this.dialogData.extra_quote_id || 0
},
quoteData() {
return this.quoteId ? this.allMsgs.find(({id}) => id === this.quoteId) : null
return this.quoteData?.id || 0
},
todoViewMsg() {
@ -1662,7 +1666,7 @@ export default {
.replace(/(<span\s+class="mention"(.*?)>.*?<\/span>.*?<\/span>.*?<\/span>)(\x20)?/, "$1 ")
}
//
if (this.dialogData.extra_quote_type === 'update') {
if (this.quoteUpdate) {
//
if (textType === "text") {
textBody = textBody.replace(new RegExp(`src=(["'])${$A.mainUrl()}`, "g"), "src=$1{{RemoteURL}}")

View File

@ -109,7 +109,7 @@
<div class="dialog-text no-dark-content">
<template v-if="dialog.id != dialogId && tagDialogDraft(dialog.id)">
<div class="last-draft">[{{$L('草稿')}}]</div>
<div class="last-text"><span>{{formatDraft(getDialogDraft(dialog.id))}}</span></div>
<div class="last-text"><span>{{formatDraft(getDialogDraft(dialog.id)?.content)}}</span></div>
</template>
<template v-else>
<template v-if="dialog.type=='group' && dialog.last_msg && dialog.last_msg.userid">

View File

@ -982,6 +982,7 @@ export default {
'cacheTranslations',
'dialogMsgs',
'dialogDrafts',
'dialogQuotes',
'fileLists',
'callAt',
'cacheEmojis',
@ -3209,6 +3210,24 @@ export default {
}, (immediate || !content) ? 0 : 600)
},
/**
* 保存引用
* @param commit
* @param data {id, type, content}
*/
saveDialogQuote({commit}, data) {
commit('quote/set', data)
},
/**
* 移除引用
* @param commit
* @param id
*/
removeDialogQuote({commit}, id) {
commit('quote/remove', id)
},
/** *****************************************************************************************/
/** ************************************** 消息 **********************************************/
/** *****************************************************************************************/

View File

@ -246,7 +246,7 @@ export default {
*/
getDialogDraft: (state) => (id) => {
const draft = state.dialogDrafts.find(item => item.id === id)
return draft ? draft.content : ''
return draft || null
},
/**
@ -258,4 +258,14 @@ export default {
const draft = state.dialogDrafts.find(item => item.id === id)
return !!draft?.tag
},
/**
* 获取引用
* @param state
* @returns {function(*): *}
*/
getDialogQuote: (state) => (id) => {
const quote = state.dialogQuotes.find(item => item.id === id)
return quote || null
}
}

View File

@ -81,7 +81,6 @@ export default {
return
}
// 草稿标签
if (state.dialogId == id) {
item.tag = index !== -1 ? state.dialogDrafts[index].tag : false
} else {
@ -89,14 +88,11 @@ export default {
}
if (index !== -1) {
// 更新已存在的草稿
state.dialogDrafts.splice(index, 1, item)
} else {
// 添加新草稿
state.dialogDrafts.push(item)
}
// 保存到 IndexedDB
$A.IDBSave("dialogDrafts", state.dialogDrafts)
},
@ -110,4 +106,34 @@ export default {
$A.IDBSave("dialogDrafts", state.dialogDrafts)
}
},
// 引用管理
'quote/set': function(state, {id, type, content}) {
const index = state.dialogQuotes.findIndex(item => item.id === id)
const item = {
id,
type,
content,
time: new Date().getTime()
}
if (index === -1 && !item.content) {
return
}
if (index !== -1) {
state.dialogQuotes.splice(index, 1, item)
} else {
state.dialogQuotes.push(item)
}
$A.IDBSave("dialogQuotes", state.dialogQuotes)
},
'quote/remove': function(state, id) {
const index = state.dialogQuotes.findIndex(item => item.id === id)
if (index !== -1) {
state.dialogQuotes.splice(index, 1)
$A.IDBSave("dialogQuotes", state.dialogQuotes)
}
},
}

View File

@ -7,7 +7,7 @@ export default {
clientId: "",
// 缓存版本号(如果想升级后清除客户端缓存则修改此参数值)
cacheVersion: "v13",
cacheVersion: "v14",
// 窗口是否激活
windowActive: true,
@ -125,6 +125,7 @@ export default {
dialogMsgTops: [],
dialogHistory: [],
dialogDrafts: [],
dialogQuotes: [],
dialogMsgTransfer: {time: 0},
dialogSseList: [],
dialogDroupWordChain: {},