[sms-center-prototype-migration-SMS-06] isolate conversation content on switch

This commit is contained in:
yibaiba committed 2026-08-13 20:04:20 +08:00
1 parent e1c4eab446
commit 4dc0b25564
2 files changed
+23

No files matched your search

+8
View File
@@ -254,6 +254,7 @@ async function loadMoreHistory() {
const wrap = getDetailWrap()
const prevTop = wrap?.scrollTop || 0
const prevHeight = wrap?.scrollHeight || 0
const requestThreadKey = selectedThreadKey.value
loadingHistoryMore.value = true
try {
const oldest = threadMessages.value[0]
@@ -270,6 +271,7 @@ async function loadMoreHistory() {
params.imsi = selectedThread.value.imsi
}
const result = await smsStore.fetchThread(params)
if (selectedThreadKey.value !== requestThreadKey) return
if (!result.ok) {
messagesError.value = result.error
return
@@ -288,6 +290,7 @@ async function loadMoreHistory() {
})
messagesError.value = null
} catch (error: unknown) {
if (selectedThreadKey.value !== requestThreadKey) return
messagesError.value = toAppError(error)
} finally {
loadingHistoryMore.value = false
@@ -444,6 +447,11 @@ async function selectThread(key: string, options: { syncRoute?: boolean; silent?
const scrollToBottom = options.scrollToBottom !== false
selectedThreadKey.value = key
threadFetchSeq += 1
threadMessages.value = []
threadHasMore.value = false
threadLoading.value = false
messagesError.value = null
if (syncRoute) {
void router.replace({ query: buildSmsQuery(selectedDevice.value, key) })
}
+15
View File
@@ -70,3 +70,18 @@ test('unread presentation and history failures stay explicit', () => {
assert.doesNotMatch(smsView, /Ignore history load errors/)
assert.match(messageTimeline, /当前接口未返回此会话的历史短信/)
})
test('switching conversations clears prior content before requesting the next thread', () => {
const selectionStart = smsView.indexOf('async function selectThread')
const selectionEnd = smsView.indexOf('async function applyThreadSeen', selectionStart)
const selectionSource = smsView.slice(selectionStart, selectionEnd)
const keyUpdate = selectionSource.indexOf('selectedThreadKey.value = key')
const contentReset = selectionSource.indexOf('threadMessages.value = []')
const nextRequest = selectionSource.indexOf('await fetchThreadLatest(silent)')
assert.ok(keyUpdate >= 0)
assert.ok(contentReset > keyUpdate)
assert.ok(nextRequest > contentReset)
assert.match(smsView, /const requestThreadKey = selectedThreadKey\.value/)
assert.match(smsView, /if \(selectedThreadKey\.value !== requestThreadKey\) return/)
})