Merge pull request #57 from Permissionless-Software-Foundation/ct-unstable

Minor code readability edits
This commit is contained in:
Chris Troutner
2025-08-28 08:34:53 -07:00
committed by GitHub
3 changed files with 12 additions and 4 deletions
+1 -1
View File
@@ -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",
+1 -1
View File
@@ -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",
+10 -2
View File
@@ -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'
@@ -26,14 +27,17 @@ function NostrChat (props) {
// Handle read messages
const onMsgRead = useCallback(async (msg) => {
try {
// console.log('onMsgRead() msg: ', msg)
// 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 +49,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 }
@@ -75,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)
})
@@ -83,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')