This commit is contained in:
ansuz 2020-05-25 12:48:18 -04:00
parent 27dd9c0063
commit cf426c24e5
2 changed files with 29 additions and 21 deletions

View file

@ -257,15 +257,18 @@ define([
if (!$ticket.length) { if (!$ticket.length) {
$ticket = APP.support.makeTicket($div, content, function () { $ticket = APP.support.makeTicket($div, content, function () {
var error = false; var error = false;
hashesById[id].forEach(function (d) { nThen(function (w) {
common.mailbox.dismiss(d, function (err) { hashesById[id].forEach(function (d) {
if (err) { common.mailbox.dismiss(d, w(function (err) {
error = true; if (err) {
console.error(err); error = true;
} console.error(err);
}
}));
}); });
}).nThen(function () {
if (!error) { $ticket.remove(); }
}); });
if (!error) { $ticket.remove(); }
}); });
} }
$ticket.append(APP.support.makeMessage(content, hash)); $ticket.append(APP.support.makeMessage(content, hash));

View file

@ -134,13 +134,8 @@ proxy.mailboxes = {
// If the hash in in our history, get the index from the history: // If the hash in in our history, get the index from the history:
// - if the index is 0, we can change our lastKnownHash // - if the index is 0, we can change our lastKnownHash
// - otherwise, just push to view // - otherwise, just push to view
var idx; var idx = box.history.indexOf(hash);
if (box.history.some(function (el, i) { if (idx !== -1) {
if (hash === el) {
idx = i;
return true;
}
})) {
if (idx === 0) { if (idx === 0) {
m.lastKnownHash = hash; m.lastKnownHash = hash;
box.history.shift(); box.history.shift();
@ -153,15 +148,25 @@ proxy.mailboxes = {
// Check the "viewed" array to see if we're able to bump lastKnownhash more // Check the "viewed" array to see if we're able to bump lastKnownhash more
var sliceIdx; var sliceIdx;
var lastKnownHash; var lastKnownHash;
var toForget = [];
box.history.some(function (hash, i) { box.history.some(function (hash, i) {
// naming here is confusing... isViewed implies it's a boolean
// when in fact it's an index
var isViewed = m.viewed.indexOf(hash); var isViewed = m.viewed.indexOf(hash);
if (isViewed !== -1) {
sliceIdx = i + 1; // iterate over your history until you hit an element you haven't viewed
m.viewed.splice(isViewed, 1); if (isViewed === -1) { return true; }
lastKnownHash = hash; // update the index that you'll use to slice off viewed parts of history
return false; sliceIdx = i + 1;
} // keep track of which hashes you should remove from your 'viewed' array
return true; toForget.push(hash);
// prevent fetching dismissed messages on (re)connect
lastKnownHash = hash;
});
// remove all elements in 'toForget' from the 'viewed' array in one step
m.viewed = m.viewed.filter(function (hash) {
return toForget.indexOf(hash) === -1;
}); });
if (sliceIdx) { if (sliceIdx) {