refactor: improve nostr connection and message handling
- Add WebSocket manager class for better connection handling - Split message handling into separate store - Add encryption service class - Create chat composable for reusable chat logic - Add error handling service - Add connection status indicators throughout app - Add message persistence service - Improve subscription reliability with EOSE handling - Add connection state management - Hide status text on mobile for better space usage These changes improve code organization, reliability, and user experience by: - Better separation of concerns - More robust error handling - Clearer connection status feedback - Improved message persistence - More maintainable WebSocket management - Better mobile responsiveness Breaking changes: - Message handling moved to separate store - WebSocket connections now managed through NostrWebSocketManager - Encryption now handled through NostrEncryption service
This commit is contained in:
parent
be93965e13
commit
5eb46e96c3
11 changed files with 169 additions and 26 deletions
23
src/composables/useChat.ts
Normal file
23
src/composables/useChat.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
export function useChat(pubkey: string) {
|
||||
const messageStore = useMessageStore()
|
||||
const nostrStore = useNostrStore()
|
||||
|
||||
const messages = computed(() =>
|
||||
messageStore.messages.get(pubkey) || []
|
||||
)
|
||||
|
||||
const sendMessage = async (content: string) => {
|
||||
if (!content.trim()) return
|
||||
await nostrStore.sendMessage(pubkey, content)
|
||||
}
|
||||
|
||||
const loadHistory = async () => {
|
||||
await nostrStore.subscribeToMessages()
|
||||
}
|
||||
|
||||
return {
|
||||
messages,
|
||||
sendMessage,
|
||||
loadHistory
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue