From af27967415b6a91a84085dca9d405511f6c17aa6 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 28 Aug 2025 08:13:44 -0700 Subject: [PATCH 1/3] minor code readability edits --- package.json | 2 +- src/components/app-body/nostr-chat/index.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index dffb931..016fd99 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "@fortawesome/free-regular-svg-icons": "6.7.2", "@fortawesome/free-solid-svg-icons": "6.7.2", "@fortawesome/react-fontawesome": "0.2.2", - "@noble/hashes": "^1.8.0", + "@noble/hashes": "1.8.0", "axios": "0.27.2", "bch-dex-lib": "2.2.0", "bch-message-lib": "2.2.1", diff --git a/src/components/app-body/nostr-chat/index.js b/src/components/app-body/nostr-chat/index.js index dd47b1a..55da003 100644 --- a/src/components/app-body/nostr-chat/index.js +++ b/src/components/app-body/nostr-chat/index.js @@ -6,6 +6,7 @@ import React, { useCallback, useEffect, useState, useRef } from 'react' import { Container, Row, Col } from 'react-bootstrap' import { RelayPool } from 'nostr' + // Local libraries import ChatSidebar from './chat-sidebar' import ChatMain from './chat-main' @@ -28,12 +29,13 @@ function NostrChat (props) { try { // Update messages list setMessages(current => { - const exist = current.find(val => val.id === msg.id) // ignore existing messages + const exist = current.find(val => val.id === msg.id) if (exist) return current const newMsgs = [...current] newMsgs.push(msg) + // Sort messages by timestamp newMsgs.sort((a, b) => b.created_at - a.created_at) return newMsgs.reverse() @@ -45,9 +47,11 @@ function NostrChat (props) { if (existProfile) { return } - // Fech profile. + + // Fetch profile. let profile = await appData.nostrQueries.getProfile(pubKey) if (!profile) profile = { name: pubKey } + // Update profiles state setProfiles(currentProfiles => { const newProfiles = { ...currentProfiles } From d244f45897bf848f88a6f94c4d5349918b68b987 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 28 Aug 2025 08:32:44 -0700 Subject: [PATCH 2/3] More minor readability edits --- src/components/app-body/nostr-chat/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/app-body/nostr-chat/index.js b/src/components/app-body/nostr-chat/index.js index 55da003..fd24e69 100644 --- a/src/components/app-body/nostr-chat/index.js +++ b/src/components/app-body/nostr-chat/index.js @@ -27,6 +27,8 @@ function NostrChat (props) { // Handle read messages const onMsgRead = useCallback(async (msg) => { try { + // console.log('onMsgRead() msg: ', msg) + // Update messages list setMessages(current => { // ignore existing messages @@ -51,7 +53,7 @@ function NostrChat (props) { // Fetch profile. let profile = await appData.nostrQueries.getProfile(pubKey) if (!profile) profile = { name: pubKey } - + // Update profiles state setProfiles(currentProfiles => { const newProfiles = { ...currentProfiles } @@ -79,6 +81,7 @@ function NostrChat (props) { pool.on('open', relay => { relay.subscribe('REQ', { limit: 10, kinds: [42], '#e': [selectedChannel] }) }) + pool.on('eose', relay => { setLoadedMessages(true) }) @@ -87,6 +90,7 @@ function NostrChat (props) { console.log('post retrieved from ', relay.url, ev.content) onMsgRead(ev) }) + return () => { // Close pool on component unmount or selected channel changes console.log('Close existing pool') From f640ec0921d99383a4198e4ec492c73e0c230702 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 28 Aug 2025 08:33:45 -0700 Subject: [PATCH 3/3] Updating package.json --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 215f370..2f56e4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@fortawesome/free-regular-svg-icons": "6.7.2", "@fortawesome/free-solid-svg-icons": "6.7.2", "@fortawesome/react-fontawesome": "0.2.2", - "@noble/hashes": "^1.8.0", + "@noble/hashes": "1.8.0", "axios": "0.27.2", "bch-dex-lib": "2.2.0", "bch-message-lib": "2.2.1",