(feat) now use md-on-demand for (hopefully) faster mailbox loading

This commit is contained in:
Ludovic Marcotte
2015-08-25 11:45:17 -04:00
parent eeb6be1f08
commit eab3ee111a
2 changed files with 32 additions and 4 deletions

View File

@@ -14,7 +14,8 @@
</header>
<md-virtual-repeat-container class="md-flex">
<md-list class="sg-section-list">
<div md-virtual-repeat="currentMessage in mailbox.selectedFolder.$messages">
<div md-virtual-repeat="currentMessage in
mailbox.selectedFolder" md-on-demand="md-on-demand">
<md-list-item
ng-class="{'sg-active': currentMessage.uid == mailbox.selectedFolder.selectedMessage, unread: !currentMessage.isread}"
ng-click="mailbox.selectMessage(currentMessage)"
@@ -33,8 +34,6 @@
ng-bind-html="currentMessage.relativedate"><!-- date --></span>
<div class="sg-md-subhead-multi">{{currentMessage.$shortAddress('from')}}</div>
<div class="sg-md-body-multi">{{currentMessage.subject}}</div>
<i class="icon-ion-refresh"
ng-hide="mailbox.selectedFolder.$loadMessage(currentMessage.uid)"><!-- loading --></i>
</div>
<div class="sg-tile-icons">
<md-icon ng-show="currentMessage.priority == 'highest' || currentMessage.priority == 'high'">warning</md-icon>

View File

@@ -167,6 +167,35 @@
}
};
/**
* @function getLength
* @memberof Mailbox.prototype
* @desc Used by md-virtual-repeat / md-on-demand
* @returns the number of items in the mailbox
*/
Mailbox.prototype.getLength = function() {
return this.$messages.length;
};
/**
* @function getItemAtIndex
* @memberof Mailbox.prototype
* @desc Used by md-virtual-repeat / md-on-demand
* @returns the message as the specified index
*/
Mailbox.prototype.getItemAtIndex = function(index) {
var message;
if (index >= 0 && index < this.$messages.length) {
message = this.$messages[index];
if (this.$loadMessage(message.uid))
return message;
}
return null;
};
/**
* @function $id
* @memberof Mailbox.prototype
@@ -588,7 +617,7 @@
if (_this.uids) {
Mailbox.$log.debug('unwrapping ' + data.uids.length + ' messages');
// First entry of 'headers' are keys
headers = _.invoke(_this.headers[0], 'toLowerCase');
_this.headers.splice(0, 1);