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

Temporarily restoring email to thread doesn't appear in displayed_email_data_async()

Open revmischa opened this issue 7 years ago • 2 comments

If you have a thread with a deleted message, call gmail.get.displayed_email_data_async(). You get N messages, which don't include the deleted message. Now click to restore the message (temporarily), and call gmail.get.displayed_email_data_async() again. You still get N messages. You should get N+1 in the thread because the message has been re-added.

This makes it very hard to handle forward/reply for messages in a thread when they are deleted.

Related Q: In the case where there are deleted messages in the thread, I am trying to find the correct email ID by using jQuery's index() method to locate the offset of the message element in the thread container, skipping over elements with .height()==0 aka deleted. If I hook the reply/forward buttons, is there a better way to account for deleted messages in threads?

revmischa avatar Feb 15 '18 10:02 revmischa

This makes it very hard to handle forward/reply for messages in a thread when they are deleted.

What do you mean? For reply/forward cases, I've been happy with the compose bits of the API and injecting what I need here.

Anyhow, looking at the issue-list, we clearly have several issues with deleted messages, and in its current state gmail.js can't guarantee for correct behaviour when you need to process deleted emails.

If someone wants to look into how we can get that fixed, I will be more than happy review the PR.

josteink avatar Feb 15 '18 11:02 josteink

This is what I'm doing:

    getEmailIdForActionEvent(openItem, element, event) {
      // FIXME: is there a better way to get this besides walking the DOM? maybe hooking gmail.js compose event?
      // given event on element (e.g. reply or forward menu click), locate the email id
      // corresponding to the container of that element
      // get position/index of open item relative to siblings (aka what thread item index to look up)
      // siblings no height = deleted thread items (not present in total_threads)
      const siblings = openItem
        .parent()
        .children('[role="listitem"]')
        .filter((_, e) => $(e).height())
      let emailPosition = siblings.index(openItem) // search email container, get offset of message in un-deleted thread items
      // get thread item from (undeleted) thread list
      const emailId = this.openedEmailDetails.total_threads[emailPosition]
      return emailId
    }

Basically given a DOM element in the thread, find it's index() relative to its siblings. This gets the index into all thread items, including deleted ones. Filtering out ones with no height (aka deleted and invisible) gives you the index into the thread list from displayed_email_data. This still has issues with visible but unrestored thread items.

revmischa avatar Feb 15 '18 11:02 revmischa

Old issue is old. Closing.

josteink avatar Oct 11 '23 08:10 josteink