-
{{ selectedPeer.username || 'Unknown User' }}
-
- {{ formatPubkey(selectedPeer.pubkey) }}
+
+
+
+
+
+ {{ getPeerInitials(selectedPeer) }}
+
+
+
{{ selectedPeer.username || 'Unknown User' }}
+
+ {{ formatPubkey(selectedPeer.pubkey) }}
+
+
+
+
+
+
+
+
+
+
+
+
{{ message.content }}
+
+ {{ formatTime(message.created_at) }}
+
+
+
-
-
-
-
-
-
{{ message.content }}
-
- {{ formatTime(message.created_at) }}
-
-
-
-
-
-
-
-
-
-
-
+
+
+
@@ -300,9 +300,12 @@ interface ChatMessage {
const peers = ref
([])
const selectedPeer = ref(null)
const messageInput = ref('')
-const messagesEndRef = ref(null)
+
const isLoading = ref(false)
const showChat = ref(false)
+const messagesScrollArea = ref(null)
+const messagesContainer = ref(null)
+const scrollTarget = ref(null)
// Mobile detection
const isMobile = ref(false)
@@ -400,10 +403,8 @@ const selectPeer = async (peer: Peer) => {
// Subscribe to messages from this peer
await subscribeToPeer(peer.pubkey)
- // Scroll to bottom after messages load
- nextTick(() => {
- scrollToBottom()
- })
+ // Don't scroll when selecting a peer - let user see existing messages
+ // Only scroll when new messages arrive
}
const sendMessage = async () => {
@@ -423,9 +424,15 @@ const sendMessage = async () => {
}
const scrollToBottom = () => {
- if (messagesEndRef.value) {
- messagesEndRef.value.scrollIntoView({ behavior: 'smooth' })
- }
+ nextTick(() => {
+ if (scrollTarget.value) {
+ // Scroll to the hidden target element at the bottom
+ scrollTarget.value.scrollIntoView({
+ behavior: 'smooth',
+ block: 'end'
+ })
+ }
+ })
}
const formatPubkey = (pubkey: string) => {
@@ -466,9 +473,12 @@ onUnmounted(() => {
})
// Watch for new messages and scroll to bottom
-watch(currentMessages, () => {
- nextTick(() => {
- scrollToBottom()
- })
+watch(currentMessages, (newMessages, oldMessages) => {
+ // Only scroll if messages were added (not just peer selection)
+ if (newMessages.length > 0 && oldMessages && newMessages.length > oldMessages.length) {
+ nextTick(() => {
+ scrollToBottom()
+ })
+ }
})
\ No newline at end of file