InboxSDK presending event if condition gets stuck

189 views Asked by At

I am using the presending event of InboxSDK to check for a condition before sending the email. For the case selectedProject!==0, email is not getting sent. Does anyone have any comments.

composeView.on('presending', (event) => {
  if(selectedProject!==0){
    //console.log(selectedProject);
    composeView.send();

  }else{
    console.log(selectedProject);
    event.cancel();
    console.log('please select a project for the email');
    alert('please select a project for the email');
    initDropdown();//show the dropdown to select projects
  }
1

There are 1 answers

0
piedra On

From the presending handler if you want to send, you need to end the function by returning, if you call composeView.send(); it gets on a cycle calling the presending handler again.

composeView.on('presending', (event) => {
  if(selectedProject !== 0){
    return;
  } else {
    ...
    event.cancel();
    ...
  }

If you want to send later, you need to set a flag that is checked on the presending event to avoid running it again.

composeView.on('presending', (event) => {
  if(myForceSendFlag || selectedProject !== 0){
    return;
  } else {
    ...
    event.cancel();
    ...
  }

I know it's a bit late, but I hope this helps.