Skip to content

Commit

Permalink
disabled check if requester is already in the db in order to not proc…
Browse files Browse the repository at this point in the history
…ess a message
  • Loading branch information
silkroadnomad committed Mar 8, 2024
1 parent d9bf04b commit 1f5f1dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/lib/components/OnBoarding.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
dbMyAddressBook,
myAddressBook,
progressText,
progressState,
connectedPeers
} from "../../stores.js";
import { requestAddress } from "../../lib/network/p2p-operations.js"
Expand Down
37 changes: 23 additions & 14 deletions src/lib/network/p2p-operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,9 @@ async function handleMessage (dContactMessage) {
requesterDB = await _orbitdb.open(data.sharedAddress, {
type: 'documents',sync: true})

const isRes = await isRecipientInSenderDB(requesterDB, messageObj)

if (isRes == true)
break;
// const isRes = await isRecipientInSenderDB(requesterDB, messageObj) //TODO this seems contradicting we need to think twice again
// if (isRes === true)
// break;

result = await confirm({
data:messageObj,
Expand Down Expand Up @@ -204,21 +203,31 @@ async function handleMessage (dContactMessage) {
}
}

/**
* Opens the db of the requesterDB (if Alice requests from Bob, Bob opens Alice db)
* And if the requester is already in the db we return false (and do not process the message)
*
* //TODO this seems contradicting at some point - needs solution
*
* @param requesterDB db of Alice
* @param messageObj the message of Alice
* @returns {Promise<boolean>}
*/
async function isRecipientInSenderDB (requesterDB, messageObj){

const records = await requesterDB.all()

if(records.length!=0){
const isRecipient = records.filter(element => {
return element.value.owner === messageObj.recipient
});
if(records.length !== 0){

if(isRecipient.length != 0 ){
return true
}else{
return false
}
}
const isRecipient = records.filter(element => {
return element.value.owner === messageObj.recipient
});

if(isRecipient.length !== 0 )
return true
else
return false
}
}

/**
Expand Down

0 comments on commit 1f5f1dc

Please sign in to comment.