Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subsequent email_data() calls in observers return empty objects #18

Closed
gilgen opened this issue Dec 12, 2013 · 9 comments
Closed

Subsequent email_data() calls in observers return empty objects #18

gilgen opened this issue Dec 12, 2013 · 9 comments
Assignees
Labels

Comments

@gilgen
Copy link

gilgen commented Dec 12, 2013

If I use a gmail.get.email_data() inside an open_email observer it works the first time but in subsequent email opens, the email_data() returns an empty object. Some sort of race condition perhaps?

@ghost ghost assigned KartikTalwar Dec 12, 2013
@KartikTalwar
Copy link
Owner

@jamiebikies thanks for noticing this. So the first thing email_data() does is retrieves the email_id from the url. With the open_email observer, the data function is getting triggered the instant you click on an email from the inbox view where the url is still the inbox's. The quickest way to fix this is add a delay in the email_data function so a valid id is present. I'll try to fix it by tomorrow and see if this can be done without a delay

@gilgen
Copy link
Author

gilgen commented Dec 12, 2013

Hey @KartikTalwar, the delay is exactly what I've done for now. I'll take a look and submit a PR if you haven't got to it and I come up with a good way, like you said, to do it without a delay.

@KartikTalwar
Copy link
Owner

That PR for now would be great. From what I did to debug, L861 bloc always works (it knows that its inside the email) but api.get.email_id() in L862 still has the inbox view url.

KartikTalwar added a commit that referenced this issue Dec 15, 2013
KartikTalwar added a commit that referenced this issue Dec 15, 2013
@KartikTalwar
Copy link
Owner

@jamiebikies so the problem is that the observe callback gets executed right after its triggered. So when your callback requests the email_data, the data function runs between your click on the email and the email opening. If you add a 10 second delay to the email_data function, its going to wait 10s before opening the email. I just added a fix for this where the data function has been parameterized. This code will work

gmail.observe.on('open_email', function(id) {
  var data = gmail.get.email_data(id);
  console.log(data);
});

Feel free to reopen this issue if you find any inconsistencies

@sweetaai
Copy link

@KartikTalwar @jamiebikies i added above code in my script but still empty object got..but first time i got data but if i open email 2nd onwards then empty object got.Now i m using https://xmailchrome.appspot.com/gmail.js link gmail.js in my script. Can you tell me where i did wrong?

@KartikTalwar
Copy link
Owner

@sweetaai that js file is very outdated. It most likely does not have the fix from this issue. Please host gmail.js yourself so you can keep better track of code changes.

@sweetaai
Copy link

@KartikTalwar when i added below code in load.js then working fine.

var fb = document.createElement('script');
fb.src = "https://xmailchrome.appspot.com/gmail.js";
document.getElementsByTagName('body')[0].appendChild(fb);

but when added
var fb = document.createElement('script');
fb.src = "https://2.helloworld1test.appspot.com/js/gmail.js";
document.getElementsByTagName('body')[0].appendChild(fb);
then gmail is not defined exception got on console.There is no any difference. Only difference in gmail.js. So plz can you tell me where i did wrong?

@KartikTalwar
Copy link
Owner

@sweetaai the url is not a valid https url. I would recommend you host it on amazon s3

.

@sweetaai
Copy link

@KartikTalwar
Below is valid url
......................
but still not working.
I don't have amazon s3 space..If you have any updated gmail.js url can you send me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants