From 8c59bdf6d8ad4fc615205c8d10ea312ea809ad5e Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Mon, 3 Nov 2025 15:12:46 -0400 Subject: [PATCH] feat(chat): Filter out chat messages from deletedChat database --- src/App.js | 3 +++ .../app-body/nfts-for-sale/info-button.js | 2 +- src/components/app-body/nostr-chat/index.js | 12 ++++++++++-- src/hooks/state.js | 8 +++++++- src/services/async-load.js | 19 +++++++++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index b046457..65d87a8 100644 --- a/src/App.js +++ b/src/App.js @@ -155,6 +155,9 @@ function App (props) { const nostrLib = asyncLoad.getNostrLib({ bchWallet: walletTemp }) appData.setNostr(nostrLib) + const deletedChats = await asyncLoad.fetchDeletedChats() + appData.setDeletedChats(deletedChats) + // Update state appData.setShowStartModal(false) appData.setDenyClose(false) diff --git a/src/components/app-body/nfts-for-sale/info-button.js b/src/components/app-body/nfts-for-sale/info-button.js index dd95961..731feac 100644 --- a/src/components/app-body/nfts-for-sale/info-button.js +++ b/src/components/app-body/nfts-for-sale/info-button.js @@ -138,7 +138,7 @@ function InfoButton (props) { - + {!loading && } {loading && } diff --git a/src/components/app-body/nostr-chat/index.js b/src/components/app-body/nostr-chat/index.js index d745fe4..83892cc 100644 --- a/src/components/app-body/nostr-chat/index.js +++ b/src/components/app-body/nostr-chat/index.js @@ -12,6 +12,8 @@ import ChatSidebar from './chat-sidebar' import ChatMain from './chat-main' import config from '../../../config' +// Global variables and constants + function NostrChat (props) { const { appData } = props const { nostrQueries, bchWalletState, startChannelChat } = appData @@ -28,6 +30,8 @@ function NostrChat (props) { const [selectedChannel, setSelectedChannel] = useState(null) const [selectedChannelIsDm, setSelectedChannelIsDm] = useState(false) + const [deletedChats] = useState(appData.deletedChats) + const profilesRef = useRef({}) const dmChannelsRef = useRef([]) @@ -182,6 +186,9 @@ function NostrChat (props) { // fetch messages when channel selected and channel metadata are loaded if (!selectedChannel || !channelsLoaded || selectedChannelIsDm) return + // wait for deleted chats + if (!deletedChats || !Array.isArray(deletedChats)) return + // Load messages for group channel const relays = nostrQueries.relays if (relays.length === 0) { @@ -204,7 +211,8 @@ function NostrChat (props) { pool.on('event', (relay, subId, ev) => { console.log('Group post retrieved from ', relay.url, ev.content) const onBlackList = nostrQueries.blackList.find((val) => { return val === ev.pubkey }) - if (!onBlackList)onMsgRead(ev) + const isDeleted = deletedChats.find((val) => { return val.eventId === ev.id }) + if (!onBlackList && !isDeleted)onMsgRead(ev) }) return () => { @@ -212,7 +220,7 @@ function NostrChat (props) { console.log('Close existing pool for group channel') pool.close() } - }, [onMsgRead, selectedChannel, selectedChannelIsDm, nostrQueries, channelsLoaded]) + }, [onMsgRead, selectedChannel, selectedChannelIsDm, nostrQueries, channelsLoaded, deletedChats]) // Handle nostr pool for dm channels useEffect(() => { diff --git a/src/hooks/state.js b/src/hooks/state.js index b54c844..5e97897 100644 --- a/src/hooks/state.js +++ b/src/hooks/state.js @@ -46,6 +46,10 @@ function useAppState () { const [hideSpinner, setHideSpinner] = useState(false) const [denyClose, setDenyClose] = useState(false) const [isSingleView, setIsSingleView] = useState(false) + + // Deleted nostr chats. + const [deletedChats, setDeletedChats] = useState([]) + // Background process state const [asyncBackGroundInitState, setAsyncBackGroundInitState] = useState({ bchInitLoaded: false, slpInitLoaded: false, asyncBackgroundFinished: false @@ -237,7 +241,9 @@ function useAppState () { startChannelChat, setStartChannelChat, asyncBackGroundInitState, - updateBackGroundInitState + updateBackGroundInitState, + deletedChats, + setDeletedChats } } diff --git a/src/services/async-load.js b/src/services/async-load.js index f35fc7a..7661ec2 100644 --- a/src/services/async-load.js +++ b/src/services/async-load.js @@ -14,6 +14,9 @@ import { base58_to_binary as base58ToBinary } from 'base58-js' import { bytesToHex } from '@noble/hashes/utils' // already an installed dependency import { getPublicKey } from 'nostr-tools/pure' import * as nip19 from 'nostr-tools/nip19' +import config from '../config' + +const SERVER = `${config.dexServer}/` class AsyncLoad { constructor () { @@ -333,6 +336,22 @@ class AsyncLoad { throw error } } + + // Get all deleted chats + async fetchDeletedChats () { + try { + const options = { + method: 'GET', + url: `${SERVER}nostr/deletedChat` + } + const result = await axios.request(options) + const { deletedChats } = result.data + return deletedChats + } catch (error) { + console.error('Error deletedChats: ', error) + throw error + } + } } function sleep (ms) {