gmail.js icon indicating copy to clipboard operation
gmail.js copied to clipboard

view_email only get maximum 5 emails

Open danieltigse opened this issue 9 years ago • 9 comments

You can replicate this If you find for an email with a thread of more than 5 emails. If you find it and open it all the mails are displayed. The problem is that the lib only detect me 5 emails.

danieltigse avatar Nov 30 '16 21:11 danieltigse

I'm having trouble reproducing this one.

Could you outline the steps needed to reproduce this error in more detail?

josteink avatar Dec 01 '16 15:12 josteink

Sure.

  1. Search for an email with a thread of more than 5 emails
  2. Click on the suggestions that gmail give you when searching the email
  3. If you put a log in the observer or debug in the line you will see that only detects 5 emails.

danieltigse avatar Dec 01 '16 15:12 danieltigse

I guess I need to be more specific myself :)

Can you show me the code and functions you use which fail to detect more than 5 items? This is the part which is non-obvious to me.

josteink avatar Dec 01 '16 20:12 josteink

Ok.

This is my code, it only prints the number of emails detected in the thread right?: gmail.observe.on('view_email', function(obj) { console.log(obj.id_element.length); }

So my test is that I search an email that has more than 5 mails in the thread like this: screen shot 2016-12-28 at 12 06 21 pm

As you can see there are 8 emails in this thread. screen shot 2016-12-28 at 12 06 41 pm

But in the log only prints 5 screen shot 2016-12-28 at 12 07 01 pm

danieltigse avatar Dec 28 '16 17:12 danieltigse

Thanks. I'll check this out after the holidays.

josteink avatar Dec 29 '16 15:12 josteink

view_email should trigger once for every email shown in a thread. From your error-description, it sounds like what you're really after is information not about the email, but about the thread itself. Is that correct?

The id_elements property may be useful to get to the other emails in the thread, but the email object is first and foremost about providing integration with a single email. Anything beyond that is convenience and not core. If id_elementsdoesn't return all elements (and I can reproduce that it doesn't), I'm not sure I think it's such a critical bug.

If you just need the IDs of the other emails in the same thread, you can use gmail.get.email_data (or more preferably the async-version) to get these. I've tested that and it works.

gmail.observe.on('view_email', function(obj) {
    console.log(obj.id_element.length);
    gmail.get.email_data_async(obj.id, function(res) {
        console.log("Result: ", res.threads);
    });
});

Please note it might cause server-requests, and is not entirely DOM-based.

Let me know if that's a good enough workaround for now. If you can provide a patch which makes view_email act more accurately, that's ofcourse always welcome.

josteink avatar Jan 01 '17 20:01 josteink

Any feedback on this? Is the workaround sufficient?

josteink avatar Feb 10 '17 08:02 josteink

I tested the code but it doesn't work for me. First obj.id is undefined. When I try gmail.get.email_data_async(obj.id_element[0].id, function(res) or gmail.get.email_data_async(obj.id, function(res) I got undefined in the response.

danieltigse avatar Feb 10 '17 14:02 danieltigse

I tested the code but it doesn't work for me. First obj.id is undefined

That's extremely strange, and something I'm not able to reproduce. Strictly speaking it sounds like something which "shouldn't" be possible.

Can you, via debugger check if the codepath you're being taken to is this one?

https://github.com/KartikTalwar/gmail.js/blob/master/src/gmail.js#L2606-L2615

If so, at least we have a slight clue...

As for theories... Could it be performance-related? I've seen gmail.js DOM-events where we need to "wait it out" because we've intercepted the XHR and triggered the event before Gmail has actually updated the UI itself.

Maybe we need to wait some of our events out before we trigger them?

Could you inspect the state of element at this location in the code? Does innerHTML look what you would expect it to?

josteink avatar Feb 10 '17 19:02 josteink

Old issue is old. Closing.

josteink avatar Oct 11 '23 08:10 josteink