Compare commits

...
2 Commits
Author SHA1 Message Date
Chris Troutner efdfb7971b Merge pull request #73 from Permissionless-Software-Foundation/dh-filter-chats
feat(chat): Filter out chat messages from deletedChat database
2025-11-04 08:48:22 -08:00
Daniel Gonzalez 8c59bdf6d8 feat(chat): Filter out chat messages from deletedChat database 2025-11-03 15:12:46 -04:00
5 changed files with 40 additions and 4 deletions
+3
View File
@@ -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>
+10 -2
View File
@@ -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
View File
@@ -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
}
}
+19
View File
@@ -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) {