From 89cc78948726971463b5dfa16aeb88bac2daa502 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Tue, 24 Mar 2015 17:54:15 +0300 Subject: [PATCH] Fixed NaN problem --- app/js/services.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/app/js/services.js b/app/js/services.js index 1cfaab52..b7436a56 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -1006,17 +1006,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) offset = 0, offsetNotFound = false, unreadOffset = false, - unreadSkip = false, - resultPending = []; + unreadSkip = false; prerendered = prerendered ? Math.min(50, prerendered) : 0; if (historyStorage === undefined) { historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []}; } - else if (!maxID && historyStorage.pending.length) { - resultPending = historyStorage.pending.slice(); - } if (!limit && !maxID) { var foundDialog = getDialogByPeerID(peerID); @@ -1056,9 +1052,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } else { limit = limit || (offset ? 20 : (prerendered || 5)); } + var history = historyStorage.history.slice(offset, offset + limit); + if (!maxID && historyStorage.pending.length) { + history = historyStorage.pending.slice().concat(history); + } return $q.when({ count: historyStorage.count, - history: resultPending.concat(historyStorage.history.slice(offset, offset + limit)), + history: history, unreadOffset: unreadOffset, unreadSkip: unreadSkip }); @@ -1082,10 +1082,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) angular.forEach(historyResult.messages, function (message) { history.push(message.id); }); + if (!maxID && historyStorage.pending.length) { + history = historyStorage.pending.slice().concat(history); + } return { count: historyStorage.count, - history: resultPending.concat(history), + history: history, unreadOffset: unreadOffset, unreadSkip: unreadSkip }; @@ -1102,9 +1105,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } } + var history = historyStorage.history.slice(offset, offset + limit); + if (!maxID && historyStorage.pending.length) { + history = historyStorage.pending.slice().concat(history); + } + return { count: historyStorage.count, - history: resultPending.concat(historyStorage.history.slice(offset, offset + limit)), + history: history, unreadOffset: unreadOffset, unreadSkip: unreadSkip };