mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex-taker-v2.git
synced 2026-09-22 09:12:00 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
efdfb7971b | ||
|
|
8c59bdf6d8 |
@@ -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)
|
||||
|
||||
@@ -138,7 +138,7 @@ function InfoButton (props) {
|
||||
|
||||
</Container>
|
||||
</Modal.Body>
|
||||
<Modal.Footer style={{ justifyContent: 'center'}}>
|
||||
<Modal.Footer style={{ justifyContent: 'center' }}>
|
||||
{!loading && <Button style={{ width: '135px' }} onClick={updateOffer}>Update</Button>}
|
||||
{loading && <Spinner />}
|
||||
</Modal.Footer>
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
+7
-1
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user