Skip to content

Commit 8e22dc7

Browse files
author
g8g3
committed
api.get.displayed_email_data() excludes deleted emails, or non-deleted emails when reading from trash.
1 parent f182ed7 commit 8e22dc7

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/gmail.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -916,30 +916,48 @@ var Gmail = function() {
916916

917917
if (api.check.is_conversation_view()) {
918918
displayed_email_data = email_data;
919+
920+
var threads = displayed_email_data.threads;
921+
var total_threads = displayed_email_data.total_threads;
922+
923+
var hash = window.location.hash.split('#')[1] || '';
924+
var is_in_trash = (hash.indexOf('trash') === 0);
925+
926+
for (id in threads) {
927+
var email = threads[id];
928+
var keep_email = (is_in_trash) ? email.is_deleted : !email.is_deleted;
929+
930+
if (!keep_email) {
931+
delete threads[id];
932+
total_threads.splice(total_threads.indexOf(id), 1);
933+
displayed_email_data.total_emails--;
934+
// TODO: remove people involved only in this email.
935+
}
936+
}
919937
}
920938
else { // Supposing only one displayed email.
921939
for (id in email_data.threads) {
922940
var displayed_email_element = $('.ii.gt[class*="' + id + '"]');
923941

924942
if (displayed_email_element.length > 0) {
925-
var thread = email_data.threads[id];
943+
var email = email_data.threads[id];
926944

927945
displayed_email_data.first_email = id;
928946
displayed_email_data.last_email = id;
929947
displayed_email_data.subject = email_data.subject;
930948

931949
displayed_email_data.threads = {};
932-
displayed_email_data.threads[id] = thread;
950+
displayed_email_data.threads[id] = email;
933951
displayed_email_data.total_emails = 1;
934952
displayed_email_data.total_threads = [id];
935953

936954
displayed_email_data.people_involved = [];
937955

938956
displayed_email_data.people_involved.push(
939-
[thread.from, thread.from_email]
957+
[email.from, email.from_email]
940958
);
941959

942-
thread.to.forEach(function(recipient) {
960+
email.to.forEach(function(recipient) {
943961
var address = api.tools.extract_email_address(recipient);
944962
var name = api.tools.extract_name(recipient.replace(address, '')) || '';
945963

@@ -964,7 +982,7 @@ var Gmail = function() {
964982
var flag = undefined;
965983
var array_with_flag = api.tracker.globals[17][5][1];
966984

967-
for (var i=0; i < array_with_flag.length; i++) {
985+
for (var i = 0; i < array_with_flag.length; i++) {
968986
var current = array_with_flag[i];
969987

970988
if (current[0] === flag_name) {

0 commit comments

Comments
 (0)