perf(mail(js)): improvements for md-virtual-repeat
parent
976579356d
commit
d285411ef3
|
@ -166,6 +166,7 @@
|
||||||
this.$isLoading = true;
|
this.$isLoading = true;
|
||||||
this.$messages = [];
|
this.$messages = [];
|
||||||
this.uidsMap = {};
|
this.uidsMap = {};
|
||||||
|
this.$visibleMessages = this.$messages;
|
||||||
}
|
}
|
||||||
angular.extend(this, data);
|
angular.extend(this, data);
|
||||||
if (this.path) {
|
if (this.path) {
|
||||||
|
@ -234,16 +235,7 @@
|
||||||
* @returns the number of messages in the mailbox
|
* @returns the number of messages in the mailbox
|
||||||
*/
|
*/
|
||||||
Mailbox.prototype.getLength = function() {
|
Mailbox.prototype.getLength = function() {
|
||||||
var _this = this, collapsedThread = false;
|
return this.$visibleMessages.length;
|
||||||
var visibleMessages = _.filter(this.$messages, function(msg, i) {
|
|
||||||
if (msg.first) {
|
|
||||||
collapsedThread = msg.collapsed;
|
|
||||||
} else if (msg.level < 0) {
|
|
||||||
collapsedThread = false;
|
|
||||||
}
|
|
||||||
return msg.first || collapsedThread === false;
|
|
||||||
});
|
|
||||||
return visibleMessages.length;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -253,18 +245,10 @@
|
||||||
* @returns the message at the specified index
|
* @returns the message at the specified index
|
||||||
*/
|
*/
|
||||||
Mailbox.prototype.getItemAtIndex = function(index) {
|
Mailbox.prototype.getItemAtIndex = function(index) {
|
||||||
var _this = this, collapsedThread = false, message;
|
var message;
|
||||||
var visibleMessages = _.filter(this.$messages, function(msg, i) {
|
|
||||||
if (msg.first) {
|
|
||||||
collapsedThread = msg.collapsed;
|
|
||||||
} else if (msg.level < 0) {
|
|
||||||
collapsedThread = false; // leaving the thread
|
|
||||||
}
|
|
||||||
return msg.first || collapsedThread === false;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (index >= 0 && index < visibleMessages.length) {
|
if (index >= 0 && index < this.$visibleMessages.length) {
|
||||||
message = visibleMessages[index];
|
message = this.$visibleMessages[index];
|
||||||
this.$lastVisibleIndex = Math.max(0, index - 3); // Magic number is NUM_EXTRA from virtual-repeater.js
|
this.$lastVisibleIndex = Math.max(0, index - 3); // Magic number is NUM_EXTRA from virtual-repeater.js
|
||||||
this.$loadMessage(message.uid);
|
this.$loadMessage(message.uid);
|
||||||
return message; // skeleton is displayed while headers are being fetched
|
return message; // skeleton is displayed while headers are being fetched
|
||||||
|
@ -473,6 +457,7 @@
|
||||||
else {
|
else {
|
||||||
// Message at this index will be loaded
|
// Message at this index will be loaded
|
||||||
uids.push(this.$messages[startIndex].uid);
|
uids.push(this.$messages[startIndex].uid);
|
||||||
|
//console.debug('loading ' + this.$messages[startIndex].uid);
|
||||||
this.$messages[startIndex].loading = true;
|
this.$messages[startIndex].loading = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -956,6 +941,26 @@
|
||||||
return mailbox;
|
return mailbox;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @function updateVisibleMessages
|
||||||
|
* @memberof Mailbox.prototype
|
||||||
|
* @desc Update list of visible messages when in threaded mode.
|
||||||
|
*/
|
||||||
|
Mailbox.prototype.updateVisibleMessages = function() {
|
||||||
|
var collapsedThread = false;
|
||||||
|
|
||||||
|
if (this.threaded) {
|
||||||
|
this.$visibleMessages = _.filter(this.$messages, function(msg, i) {
|
||||||
|
if (msg.first) {
|
||||||
|
collapsedThread = msg.collapsed;
|
||||||
|
} else if (msg.level < 0) {
|
||||||
|
collapsedThread = false; // leaving the thread
|
||||||
|
}
|
||||||
|
return msg.first || collapsedThread === false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function $unwrap
|
* @function $unwrap
|
||||||
* @memberof Mailbox.prototype
|
* @memberof Mailbox.prototype
|
||||||
|
@ -997,14 +1002,13 @@
|
||||||
if (angular.isUndefined(_this.uidsMap[uid.toString()])) {
|
if (angular.isUndefined(_this.uidsMap[uid.toString()])) {
|
||||||
// New messsage; update map of UID <=> index
|
// New messsage; update map of UID <=> index
|
||||||
_this.uidsMap[uid] = i;
|
_this.uidsMap[uid] = i;
|
||||||
msgObject = new Mailbox.$Message(_this.$account.id, _this, {uid: uid}, true);
|
_this.$messages.splice(i, 0, {uid: uid});
|
||||||
_this.$messages.splice(i, 0, msgObject);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
// New messages received, update uidsMap
|
// New messages received, update uidsMap for existing messages
|
||||||
for (j = i; j < _this.$messages.length; j++) {
|
for (j = i; j < _this.$messages.length; j++) {
|
||||||
msgObject = _this.$messages[j];
|
msgObject = _this.$messages[j];
|
||||||
_this.uidsMap[msgObject.uid] += i;
|
_this.uidsMap[msgObject.uid] += i;
|
||||||
|
@ -1043,7 +1047,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
data = {uid: msg.toString()};
|
data = {uid: msg};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build map of UID <=> index
|
// Build map of UID <=> index
|
||||||
|
@ -1075,6 +1079,10 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_this.threaded) {
|
||||||
|
_this.updateVisibleMessages();
|
||||||
|
}
|
||||||
|
|
||||||
Mailbox.$log.debug('mailbox ' + _this.id + ' ready');
|
Mailbox.$log.debug('mailbox ' + _this.id + ' ready');
|
||||||
_this.$isLoading = false;
|
_this.$isLoading = false;
|
||||||
deferred.resolve(_this.$messages);
|
deferred.resolve(_this.$messages);
|
||||||
|
@ -1116,6 +1124,9 @@
|
||||||
_this.$messages[j].init(messageHeaders);
|
_this.$messages[j].init(messageHeaders);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (_this.threaded) {
|
||||||
|
_this.updateVisibleMessages();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -594,8 +594,12 @@
|
||||||
action = 'markMessageUncollapse';
|
action = 'markMessageUncollapse';
|
||||||
|
|
||||||
this.collapsed = !this.collapsed;
|
this.collapsed = !this.collapsed;
|
||||||
|
_this.$mailbox.updateVisibleMessages();
|
||||||
|
|
||||||
return Message.$$resource.post(this.$absolutePath(), action);
|
return Message.$$resource.post(this.$absolutePath(), action).catch(function() {
|
||||||
|
this.collapsed = !this.collapsed;
|
||||||
|
_this.$mailbox.updateVisibleMessages();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
|
|
||||||
this.$onInit = function () {
|
this.$onInit = function () {
|
||||||
var watchedAttrs = ['uid', 'isread', 'isflagged', 'flags', 'subject', 'loading'];
|
var watchedAttrs = ['uid', 'isread', 'isflagged', 'flags', 'loading'];
|
||||||
|
|
||||||
// this.service = Message;
|
// this.service = Message;
|
||||||
this.MailboxService = Mailbox;
|
this.MailboxService = Mailbox;
|
||||||
|
|
Loading…
Reference in New Issue