KartikTalwar / gmail.js

Gmail JavaScript API
MIT License
3.74k stars 455 forks source link

Fix classes used for detecting threads #735

Closed cancan101 closed 1 year ago

josteink commented 1 year ago

Testing that almost kinda works, but not completely.

If you do like this, this kinda works:

gmail.observe.on("view_thread", (domThread) => {
    console.log("Looking at thread:", domThread);
}

But if you try to chain it into gmail.new.get.thread_data() it seems to fail:

gmail.observe.on("view_thread", (domThread) => {
    console.log("Looking at thread:", domThread);
    const threadData = gmail.new.get.thread_data(domThread);
    console.log("Thread data:", threadData); // reports null!
}

Not sure if fixing that is within the scope of this PR or not though.

josteink commented 1 year ago

I guess either way, it's an improvement, so why not merge it :smile:

cancan101 commented 1 year ago

FWIW, I am not sure this has worked recently:

gmail.observe.on("view_thread", (domThread) => {
    console.log("Looking at thread:", domThread);
    const threadData = gmail.new.get.thread_data(domThread);
    console.log("Thread data:", threadData); // reports null!
}

I have:

gmail.observe.on('view_thread', function (obj) {
  console.log('view_thread', obj);
  const threadJQElem = obj.dom();
  const threadElem = threadJQElem[0].querySelector<HTMLElement>(
    '[data-thread-perm-id]'
  );
  if (threadElem) {
    const threadId: string | undefined = threadElem.dataset['threadPermId'];
    if (threadId) {
      const threadData = gmail.new.get.thread_data(threadId);

      console.log('view_thread. obj:', obj, threadId, threadData);

     // ....
    }
  }
});
josteink commented 1 year ago

Oh well. It works with email, so IMO it should work with threads too for API consistency.

But that's another issue.