view_email only get maximum 5 emails
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.
I'm having trouble reproducing this one.
Could you outline the steps needed to reproduce this error in more detail?
Sure.
- Search for an email with a thread of more than 5 emails
- Click on the suggestions that gmail give you when searching the email
- If you put a log in the observer or debug in the line you will see that only detects 5 emails.
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.
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:

As you can see there are 8 emails in this thread.

But in the log only prints 5

Thanks. I'll check this out after the holidays.
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.
Any feedback on this? Is the workaround sufficient?
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.
I tested the code but it doesn't work for me. First
obj.idis 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?
Old issue is old. Closing.