+ {/* Back button for mobile */}
+
+
{conversationName}
{!selectedConversation.is_group && selectedConversation.other_user && selectedConversation.other_user.id ? (
- 0 && 'text-primary')}>
+ 0 && 'text-primary')}>
{name}
{conversation.last_message_at && (
-
+
{formatDistanceToNow(new Date(conversation.last_message_at), { addSuffix: true })}
)}
0 ? 'font-medium text-foreground' : 'text-muted-foreground'
)}>
{conversation.last_message_content || 'No messages yet'}
{conversation.unread_count > 0 && (
-
+
{conversation.unread_count}
)}
diff --git a/components/messages/MessageInput.tsx b/components/messages/MessageInput.tsx
index c3ccaa43..566f274c 100644
--- a/components/messages/MessageInput.tsx
+++ b/components/messages/MessageInput.tsx
@@ -90,7 +90,7 @@ export function MessageInput({ onSend, disabled, placeholder = 'Type a message..
}, [content, isTyping, onTyping])
return (
-
diff --git a/components/messages/TypingIndicator.tsx b/components/messages/TypingIndicator.tsx
index 01c170cd..eee93492 100644
--- a/components/messages/TypingIndicator.tsx
+++ b/components/messages/TypingIndicator.tsx
@@ -9,16 +9,6 @@ interface TypingIndicatorProps {
export function TypingIndicator({ usernames }: TypingIndicatorProps) {
if (usernames.length === 0) return null
- const getTypingText = () => {
- if (usernames.length === 1) {
- return `${usernames[0]} is typing...`
- } else if (usernames.length === 2) {
- return `${usernames[0]} and ${usernames[1]} are typing...`
- } else {
- return `${usernames[0]} and ${usernames.length - 1} others are typing...`
- }
- }
-
return (
@@ -26,7 +16,7 @@ export function TypingIndicator({ usernames }: TypingIndicatorProps) {
-
{getTypingText()}
+
Typing...
)
}
diff --git a/hooks/useMessages.ts b/hooks/useMessages.ts
index 2e3a98d7..def11e1a 100644
--- a/hooks/useMessages.ts
+++ b/hooks/useMessages.ts
@@ -42,6 +42,8 @@ export function useMessages(conversationId: string | null) {
const supabase = createClient()
+ console.log('📡 Setting up message subscription for conversation:', conversationId)
+
const subscription = supabase
.channel(`messages:${conversationId}`)
.on(
@@ -53,6 +55,8 @@ export function useMessages(conversationId: string | null) {
filter: `conversation_id=eq.${conversationId}`
},
async (payload) => {
+ console.log('🔔 New message received via realtime:', payload)
+
// Fetch the complete message with sender details
const { data } = await supabase
.from('messages')
@@ -70,6 +74,8 @@ export function useMessages(conversationId: string | null) {
.single()
if (data) {
+ console.log('📨 Fetched complete message data:', data)
+
// Decrypt the message content
const decryptResponse = await fetch('/api/messages/decrypt', {
method: 'POST',
@@ -79,11 +85,17 @@ export function useMessages(conversationId: string | null) {
const { decrypted } = await decryptResponse.json()
const decryptedMessage = { ...data, content: decrypted }
+
+ console.log('🔓 Decrypted message:', decrypted)
setMessages(prev => {
// Avoid duplicates
const exists = prev.some(msg => msg.id === data.id)
- if (exists) return prev
+ if (exists) {
+ console.log('⚠️ Message already exists, skipping')
+ return prev
+ }
+ console.log('✅ Adding new message to state')
return [...prev, decryptedMessage as Message]
})
// Mark as read
@@ -91,9 +103,12 @@ export function useMessages(conversationId: string | null) {
}
}
)
- .subscribe()
+ .subscribe((status) => {
+ console.log('Message subscription status:', status)
+ })
return () => {
+ console.log('🔌 Unsubscribing from messages')
subscription.unsubscribe()
}
}, [conversationId])