统一聊天排序并支持公众号跳转小程序

This commit is contained in:
stu2not
2026-06-24 14:59:44 +08:00
parent 31804a78ff
commit e75a9015fa
16 changed files with 668 additions and 72 deletions
+22 -6
View File
@@ -109,6 +109,7 @@ const RECORD_LONG_PRESS_DELAY_MS = 350
type LoadChatOptions = {
showLoading?: boolean
scrollToBottom?: 'jump' | 'animate' | false
}
function compareVersion(left: string, right: string): number {
@@ -232,6 +233,7 @@ export default function ChatDetail() {
const [playingMessageId, setPlayingMessageId] = useState<number | null>(null)
const [recordHint, setRecordHint] = useState('长按开始留言')
const [scrollTarget, setScrollTarget] = useState('')
const [scrollWithAnimation, setScrollWithAnimation] = useState(false)
const audioContextRef = useRef<Taro.InnerAudioContext | null>(null)
const recorderManagerRef = useRef<Taro.RecorderManager | null>(null)
const activeConversationIdRef = useRef(initialConversationId)
@@ -251,12 +253,14 @@ export default function ChatDetail() {
const recordStartPendingRef = useRef(false)
const recordingActiveRef = useRef(false)
const scrollToBottom = () => {
const scrollToBottom = (animated: boolean) => {
if (scrollTimerRef.current) {
clearTimeout(scrollTimerRef.current)
}
setScrollWithAnimation(animated)
setScrollTarget('')
scrollTimerRef.current = setTimeout(() => {
setScrollWithAnimation(animated)
setScrollTarget(CHAT_BOTTOM_ANCHOR_ID)
scrollTimerRef.current = null
}, 80)
@@ -373,8 +377,9 @@ export default function ChatDetail() {
}
const msgs = await getMessages(conversationId, conversationSource, decodedConversationTypeName)
setMessages(msgs)
if (msgs.length > 0) {
scrollToBottom()
const scrollMode = options.scrollToBottom ?? (!hasLoadedChatRef.current ? 'jump' : false)
if (msgs.length > 0 && scrollMode) {
scrollToBottom(scrollMode === 'animate')
}
hasLoadedChatRef.current = true
} catch (error: any) {
@@ -480,9 +485,15 @@ export default function ChatDetail() {
if (response.conversation_id && response.conversation_id !== activeConversationIdRef.current) {
skipNextAutoLoadRef.current = true
setActiveConversationId(response.conversation_id)
await latestLoadChatDataRef.current(response.conversation_id, { showLoading: false })
await latestLoadChatDataRef.current(response.conversation_id, {
showLoading: false,
scrollToBottom: 'animate',
})
} else {
await latestLoadChatDataRef.current(activeConversationIdRef.current, { showLoading: false })
await latestLoadChatDataRef.current(activeConversationIdRef.current, {
showLoading: false,
scrollToBottom: 'animate',
})
}
Taro.showToast({ title: '留言已发送', icon: 'success' })
} catch (error: any) {
@@ -752,7 +763,12 @@ export default function ChatDetail() {
</View>
</View>
<ScrollView className='chat-list' scrollY scrollWithAnimation scrollIntoView={scrollTarget}>
<ScrollView
className='chat-list'
scrollY
scrollWithAnimation={scrollWithAnimation}
scrollIntoView={scrollTarget}
>
{loading ? (
<View className='empty-chat'>
<Text className='empty-chat-text'>加载中...</Text>