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) {
$ticket = APP.support.makeTicket($div, content, function () {
var error = false;
hashesById[id].forEach(function (d) {
common.mailbox.dismiss(d, function (err) {
if (err) {
error = true;
console.error(err);
}
nThen(function (w) {
hashesById[id].forEach(function (d) {
common.mailbox.dismiss(d, w(function (err) {
if (err) {
error = true;
console.error(err);
}
}));
});
}).nThen(function () {
if (!error) { $ticket.remove(); }
});
if (!error) { $ticket.remove(); }
});
}
$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 index is 0, we can change our lastKnownHash
// - otherwise, just push to view
var idx;
if (box.history.some(function (el, i) {
if (hash === el) {
idx = i;
return true;
}
})) {
var idx = box.history.indexOf(hash);
if (idx !== -1) {
if (idx === 0) {
m.lastKnownHash = hash;
box.history.shift();
@ -153,15 +148,25 @@ proxy.mailboxes = {
// Check the "viewed" array to see if we're able to bump lastKnownhash more
var sliceIdx;
var lastKnownHash;
var toForget = [];
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);
if (isViewed !== -1) {
sliceIdx = i + 1;
m.viewed.splice(isViewed, 1);
lastKnownHash = hash;
return false;
}
return true;
// iterate over your history until you hit an element you haven't viewed
if (isViewed === -1) { return true; }
// update the index that you'll use to slice off viewed parts of history
sliceIdx = i + 1;
// keep track of which hashes you should remove from your 'viewed' array
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) {