diff --git a/src/App.js b/src/App.js index 65d87a8..b046457 100644 --- a/src/App.js +++ b/src/App.js @@ -155,9 +155,6 @@ 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/nostr-chat/index.js b/src/components/app-body/nostr-chat/index.js index 83892cc..25ca952 100644 --- a/src/components/app-body/nostr-chat/index.js +++ b/src/components/app-body/nostr-chat/index.js @@ -30,7 +30,7 @@ function NostrChat (props) { const [selectedChannel, setSelectedChannel] = useState(null) const [selectedChannelIsDm, setSelectedChannelIsDm] = useState(false) - const [deletedChats] = useState(appData.deletedChats) + const [deletedChats] = useState(appData.nostrQueries.deletedChats) const profilesRef = useRef({}) const dmChannelsRef = useRef([]) diff --git a/src/hooks/state.js b/src/hooks/state.js index 5e97897..18a2fd2 100644 --- a/src/hooks/state.js +++ b/src/hooks/state.js @@ -47,9 +47,6 @@ function useAppState () { 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 @@ -241,9 +238,7 @@ function useAppState () { startChannelChat, setStartChannelChat, asyncBackGroundInitState, - updateBackGroundInitState, - deletedChats, - setDeletedChats + updateBackGroundInitState } } diff --git a/src/services/async-load.js b/src/services/async-load.js index 7661ec2..f35fc7a 100644 --- a/src/services/async-load.js +++ b/src/services/async-load.js @@ -14,9 +14,6 @@ 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 () { @@ -336,22 +333,6 @@ 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) { diff --git a/src/services/nostr-queries.js b/src/services/nostr-queries.js index d619a07..c2e031d 100644 --- a/src/services/nostr-queries.js +++ b/src/services/nostr-queries.js @@ -7,6 +7,9 @@ import * as nip19 from 'nostr-tools/nip19' import { nip04 } from 'nostr-tools' import { hexToBytes } from '@noble/hashes/utils' // already an installed dependency import axios from 'axios' +import config from '../config' + +const SERVER = `${config.dexServer}/` export default class NostrQueries { constructor ({ relays }) { @@ -16,11 +19,16 @@ export default class NostrQueries { this.loadedChannelsInfo = {} this.blackList = [] this.blackListFetched = false + + this.deletedChats = [] + this.deletedPosts = [] } async start () { try { await this.getBlackList() + await this.fetchDeletedChats() + await this.fetchDeletedPosts() } catch (error) { console.error('NostrQueries.start() error : ', error.message) throw error @@ -182,7 +190,9 @@ export default class NostrQueries { pool.on('event', (relay, subId, ev) => { console.log('post retrieved from ', relay.url, ev.sig) - list = [...list, ev] + const isDeleted = this.deletedPosts.find((val) => { return val.eventId === ev.id }) + + if (!isDeleted) list = [...list, ev] }) pool.on('error', (relay) => { relay.close() @@ -506,4 +516,39 @@ export default class NostrQueries { 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 + this.deletedChats = deletedChats + } catch (error) { + console.error('Error fetchDeletedChats: ', error) + throw error + } + } + + // Get all deleted posts + async fetchDeletedPosts () { + try { + const options = { + method: 'GET', + url: `${SERVER}nostr/deletedPost` + } + const result = await axios.request(options) + console.log('result', result) + const { deletedPosts } = result.data + console.log('deletedPosts', deletedPosts) + + this.deletedPosts = deletedPosts + } catch (error) { + console.error('Error fetchDeletedPosts: ', error) + throw error + } + } }