Simple prefetch functionality (ifvisible.js)

config:
[labs]
allow_prefetch
This commit is contained in:
RainLoop Team 2014-01-26 18:23:37 +04:00
parent b7e135a553
commit 38672e1672
18 changed files with 988 additions and 28 deletions

View file

@ -17,8 +17,6 @@ function MessageModel()
this.toEmailsString = ko.observable('');
this.senderEmailsString = ko.observable('');
this.prefetched = false;
this.emails = [];
this.from = [];
@ -228,8 +226,6 @@ MessageModel.prototype.clear = function ()
this.toEmailsString('');
this.senderEmailsString('');
this.prefetched = false;
this.emails = [];
this.from = [];
@ -299,8 +295,6 @@ MessageModel.prototype.initByJson = function (oJsonMessage)
this.uid = oJsonMessage.Uid;
this.requestHash = oJsonMessage.RequestHash;
this.prefetched = false;
this.size(Utils.pInt(oJsonMessage.Size));
this.from = MessageModel.initEmailsFromJson(oJsonMessage.From);

View file

@ -41,7 +41,7 @@ function AdminLoginViewModel()
RL.remote().adminLogin(_.bind(function (sResult, oData) {
if (Enums.StorageResultType.Success === sResult && oData&& 'AdminLogin' === oData.Action)
if (Enums.StorageResultType.Success === sResult && oData && 'AdminLogin' === oData.Action)
{
if (oData.Result)
{

View file

@ -9,6 +9,7 @@ function MailBoxMessageListViewModel()
KnoinAbstractViewModel.call(this, 'Right', 'MailMessageList');
this.sLastUid = null;
this.bPrefetch = false;
this.emptySubjectValue = '';
var oData = RL.data();
@ -796,6 +797,51 @@ MailBoxMessageListViewModel.prototype.onBuild = function (oDom)
}, this).extend({'notify': 'always'});
this.initUploaderForAppend();
if (!Globals.bMobileDevice && !!RL.settingsGet('AllowPrefetch') && ifvisible)
{
ifvisible.setIdleDuration(10);
ifvisible.idle(function () {
self.prefetchNextTick();
});
}
};
MailBoxMessageListViewModel.prototype.prefetchNextTick = function ()
{
if (!this.bPrefetch && !ifvisible.now() && this.viewModelVisibility())
{
var
self = this,
oCache = RL.cache(),
oMessage = _.find(this.messageList(), function (oMessage) {
return oMessage &&
!oCache.hasRequestedMessage(oMessage.folderFullNameRaw, oMessage.uid);
})
;
if (oMessage)
{
this.bPrefetch = true;
RL.cache().addRequestedMessage(oMessage.folderFullNameRaw, oMessage.uid);
RL.remote().message(function (sResult, oData) {
var bNext = !!(Enums.StorageResultType.Success === sResult && oData && oData.Result);
_.delay(function () {
self.bPrefetch = false;
if (bNext)
{
self.prefetchNextTick();
}
}, 1000);
}, oMessage.folderFullNameRaw, oMessage.uid);
}
}
};
MailBoxMessageListViewModel.prototype.composeClick = function ()