Refactor chat and market modules for improved integration and maintainability
- Remove deprecated Nostr chat and relay hub components, transitioning to a modular chat service for better encapsulation. - Update App.vue and Navbar.vue to utilize the new chat module, enhancing user experience with automatic peer management. - Simplify event handling and connection logic in ChatComponent.vue, ensuring compatibility with the new chat service architecture. - Adjust market settings and order history components to reflect changes in the chat module, improving overall coherence in the application structure. - Clean up unused imports and streamline configuration access for better performance and maintainability.
This commit is contained in:
parent
63de083909
commit
17c07c37a0
17 changed files with 63 additions and 2222 deletions
|
|
@ -375,7 +375,7 @@ import { Input } from '@/components/ui/input'
|
|||
import { Badge } from '@/components/ui/badge'
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar'
|
||||
import { nostrChat } from '@/composables/useNostrChat'
|
||||
import { useChat } from '../composables/useChat'
|
||||
|
||||
import { useFuzzySearch } from '@/composables/useFuzzySearch'
|
||||
|
||||
|
|
@ -386,8 +386,11 @@ interface Peer {
|
|||
pubkey: string
|
||||
}
|
||||
|
||||
// Initialize chat composable
|
||||
const chat = useChat()
|
||||
|
||||
// State
|
||||
const peers = computed(() => nostrChat.peers.value)
|
||||
const peers = computed(() => chat.peers.value)
|
||||
const selectedPeer = ref<Peer | null>(null)
|
||||
const messageInput = ref('')
|
||||
|
||||
|
|
@ -400,20 +403,30 @@ const scrollTarget = ref<HTMLElement | null>(null)
|
|||
// Mobile detection
|
||||
const isMobile = ref(false)
|
||||
|
||||
// Nostr chat composable (singleton)
|
||||
const {
|
||||
isConnected,
|
||||
messages,
|
||||
connect,
|
||||
disconnect,
|
||||
subscribeToPeer,
|
||||
sendMessage: sendNostrMessage,
|
||||
onMessageAdded,
|
||||
markMessagesAsRead,
|
||||
getUnreadCount,
|
||||
totalUnreadCount,
|
||||
getLatestMessageTimestamp
|
||||
} = nostrChat
|
||||
// Get methods and state from chat composable
|
||||
// Note: The modular chat service handles connection and peer management automatically
|
||||
const isConnected = computed(() => true) // Chat service manages connection
|
||||
const messages = ref(new Map()) // Local messages map for compatibility
|
||||
const totalUnreadCount = computed(() => chat.totalUnreadCount.value)
|
||||
|
||||
// Adapter functions for compatibility with existing code
|
||||
const connect = async () => {} // Connection handled by chat service
|
||||
const disconnect = () => {} // Handled by chat service
|
||||
const subscribeToPeer = async (peer: string) => {} // Handled by chat service
|
||||
const sendNostrMessage = async (peer: string, content: string) => {
|
||||
chat.selectPeer(peer)
|
||||
await chat.sendMessage(content)
|
||||
}
|
||||
const onMessageAdded = (callback: Function) => {} // Event handling via chat service
|
||||
const markMessagesAsRead = (peer: string) => chat.markAsRead(peer)
|
||||
const getUnreadCount = (peer: string) => {
|
||||
const peerData = chat.peers.value.find(p => p.pubkey === peer)
|
||||
return peerData?.unreadCount || 0
|
||||
}
|
||||
const getLatestMessageTimestamp = (peer: string) => {
|
||||
const msgs = messages.value.get(peer) || []
|
||||
return msgs.length > 0 ? msgs[msgs.length - 1].created_at : 0
|
||||
}
|
||||
|
||||
// Computed
|
||||
const currentMessages = computed(() => {
|
||||
|
|
@ -498,7 +511,7 @@ const goBackToPeers = () => {
|
|||
const refreshPeers = async () => {
|
||||
isLoading.value = true
|
||||
try {
|
||||
await nostrChat.loadPeers()
|
||||
// Peers are loaded automatically by the chat service
|
||||
} catch (error) {
|
||||
console.error('Failed to refresh peers:', error)
|
||||
} finally {
|
||||
|
|
@ -601,7 +614,7 @@ onMounted(async () => {
|
|||
|
||||
// If no peers loaded, load them
|
||||
if (peers.value.length === 0) {
|
||||
await nostrChat.loadPeers()
|
||||
// Peers are loaded automatically by the chat service
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue