improve subscribe to messages
This commit is contained in:
parent
32b0bf7247
commit
8b3f1aa14b
3 changed files with 45 additions and 4 deletions
|
|
@ -1,5 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, computed, nextTick, onMounted, watch } from 'vue'
|
||||
import { ref, computed, nextTick, onMounted, watch, onUnmounted } from 'vue'
|
||||
import { useNostrStore } from '@/stores/nostr'
|
||||
import { npubToHex } from '@/lib/nostr'
|
||||
import type { DirectMessage } from '@/types/nostr'
|
||||
|
|
@ -79,6 +79,25 @@ onMounted(async () => {
|
|||
}
|
||||
})
|
||||
|
||||
// Add cleanup on unmount
|
||||
onUnmounted(() => {
|
||||
if (nostrStore.activeChat) {
|
||||
nostrStore.unsubscribeFromMessages()
|
||||
}
|
||||
})
|
||||
|
||||
// Watch for changes in activeChat
|
||||
watch(() => nostrStore.activeChat, async (newChat) => {
|
||||
if (newChat) {
|
||||
try {
|
||||
await nostrStore.subscribeToMessages()
|
||||
} catch (err) {
|
||||
console.error('Failed to subscribe to messages:', err)
|
||||
error.value = 'Failed to connect to chat. Please try again later.'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function scrollToBottom() {
|
||||
if (messagesEndRef.value) {
|
||||
messagesEndRef.value.scrollIntoView({ behavior: 'smooth' })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue