feat: Enhance Nostr chat debugging and unread message management
- Introduce debug functions in ChatComponent for resetting unread counts and displaying unread message details for specific peers, improving troubleshooting capabilities. - Update unread count management in useNostrChat to ensure accurate tracking and storage of unread messages, including recalculating counts based on message timestamps. - Implement logic to prevent duplicate message processing and enhance overall message handling efficiency.
This commit is contained in:
parent
94c85e3a0e
commit
de918419fa
2 changed files with 176 additions and 31 deletions
|
|
@ -412,7 +412,10 @@ const {
|
|||
markMessagesAsRead,
|
||||
getUnreadCount,
|
||||
totalUnreadCount,
|
||||
getLatestMessageTimestamp
|
||||
getLatestMessageTimestamp,
|
||||
clearAllUnreadCounts,
|
||||
debugUnreadData,
|
||||
getUnreadData
|
||||
} = nostrChat
|
||||
|
||||
// Computed
|
||||
|
|
@ -602,6 +605,61 @@ const getPeerInitials = (peer: Peer) => {
|
|||
return peer.pubkey.slice(0, 2).toUpperCase()
|
||||
}
|
||||
|
||||
// Debug function to reset unread counts (can be called from browser console)
|
||||
const debugResetUnreadCounts = () => {
|
||||
console.log('🔧 Debug: Resetting all unread counts...')
|
||||
clearAllUnreadCounts()
|
||||
console.log('🔧 Debug: Unread counts reset. You may need to refresh the page to see the changes.')
|
||||
}
|
||||
|
||||
// Debug function to show unread count details for a specific peer
|
||||
const debugPeerUnreadCounts = (peerPubkey?: string) => {
|
||||
if (peerPubkey) {
|
||||
console.log(`🔧 Debug: Unread count details for peer ${peerPubkey}:`)
|
||||
debugUnreadData(peerPubkey)
|
||||
console.log(`Current unread count: ${getUnreadCount(peerPubkey)}`)
|
||||
|
||||
// Show timestamp details for debugging
|
||||
const peerMessages = messages.value.get(peerPubkey) || []
|
||||
const unreadData = getUnreadData(peerPubkey)
|
||||
console.log(`Last read timestamp: ${unreadData.lastReadTimestamp} (${new Date(unreadData.lastReadTimestamp * 1000).toLocaleString()})`)
|
||||
console.log(`Total messages: ${peerMessages.length}`)
|
||||
|
||||
// Show messages that would count as unread
|
||||
const unreadMessages = peerMessages.filter(msg => !msg.sent && msg.created_at > unreadData.lastReadTimestamp)
|
||||
console.log(`Messages that count as unread: ${unreadMessages.length}`)
|
||||
unreadMessages.forEach(msg => {
|
||||
console.log(` - ${msg.content.substring(0, 50)}... (${new Date(msg.created_at * 1000).toLocaleString()})`)
|
||||
})
|
||||
} else {
|
||||
console.log('🔧 Debug: All unread counts:')
|
||||
console.log('Total unread count:', totalUnreadCount.value)
|
||||
// Simplified peer iteration to avoid TypeScript issues
|
||||
const peerList = peers.value
|
||||
if (peerList && peerList.length > 0) {
|
||||
peerList.forEach((peer: any) => {
|
||||
const count = getUnreadCount(peer.pubkey)
|
||||
if (count > 0) {
|
||||
const name = peer.username || peer.pubkey.slice(0, 8)
|
||||
console.log(`${name}: ${count}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make debug functions available globally for browser console access
|
||||
if (typeof window !== 'undefined') {
|
||||
// Use type assertion to avoid TypeScript errors
|
||||
const globalWindow = window as any
|
||||
globalWindow.debugResetUnreadCounts = debugResetUnreadCounts
|
||||
globalWindow.debugPeerUnreadCounts = debugPeerUnreadCounts
|
||||
|
||||
console.log('🔧 Debug functions available:')
|
||||
console.log(' - debugResetUnreadCounts() - reset all unread counts')
|
||||
console.log(' - debugPeerUnreadCounts(peerPubkey?) - show unread count details')
|
||||
}
|
||||
|
||||
// Lifecycle
|
||||
onMounted(async () => {
|
||||
checkMobile()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue