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

gmail.observer.on('view_email',function(obj){}) is firing multiple times #752

Open
MattIrineu opened this issue Mar 15, 2023 · 7 comments
Open

Comments

@MattIrineu
Copy link

`gmail.observe.on('view_email', function (obj) {
priotityTag();

console.log('Changed email in thread: ' + obj.id)

post(obj.id, "email")

});`
I have this code but whenever I run it, this function is triggered multiple times and I dont get why, from my understanding, it should be triggered only when I click in an email and stop, once I click and open an email, my console.log prints 4 times +

Any idea why this is happening?

Thank you very much

@josteink
Copy link
Collaborator

Depending on how you register the event, it could be registered many times (and thus fired many times).

Can you reproduce the issue using the boilerplate repo?

https://github.com/josteink/gmailjs-node-boilerplate

@knopa
Copy link

knopa commented Nov 17, 2023

With this repo i got firing 3 times

image

@knopa
Copy link

knopa commented Nov 17, 2023

I see, in boilerplate there is outdated packages, but even with latest one it fires now 2 times

@josteink
Copy link
Collaborator

I guess the answer is either to create idempotent event handlers (firing 1 or multiple times gives the same result), or someone fixing the event-triggering in gmailjs.

I'm not able to go fix the code anytime soon, so PRs are definitely welcome.

@knopa
Copy link

knopa commented Nov 17, 2023

Could it be related to that line with empty class?
// FIXME: the empty class ("") is for emails opened after thread is rendered (causes a storm of updates)
class: ["Bu", "nH", ""],

@josteink
Copy link
Collaborator

Might be. I didn't personally implement the latest revision of this particular code, so I'm not 100% sure.

Remove it and see if it still works? If so, that sounds like a simple PR, right? :)

@knopa
Copy link

knopa commented Nov 17, 2023

Unfortunatly it's not an issue), it's workaround to get view email event on open email in thread before last one

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

No branches or pull requests

3 participants