diff --git a/app/js/controllers.js b/app/js/controllers.js index e88d8065..0514a388 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -1165,8 +1165,10 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.state.mayBeHasMore = true; + console.log(dT(), 'start load history', $scope.curDialog); getMessagesPromise.then(function (historyResult) { if (curJump != jump) return; + console.log(dT(), 'history loaded', historyResult); var fetchedLength = historyResult.history.length; diff --git a/app/js/services.js b/app/js/services.js index 05088715..1cfaab52 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -1833,7 +1833,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) var peerID = pendingData[0], tempID = pendingData[1], historyStorage = historiesStorage[peerID], - i; + pos = historyStorage.pending.indexOf(tempID); ApiUpdatesManager.processUpdateMessage({ _: 'updateShort', @@ -1843,17 +1843,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } }); - for (i = 0; i < historyStorage.pending.length; i++) { - if (historyStorage.pending[i] == tempID) { - historyStorage.pending.splice(i, 1); - break; - } + if (pos != -1) { + historyStorage.pending.splice(pos, 1); } delete messagesForHistory[tempID]; delete messagesStorage[tempID]; - return true; } @@ -1868,17 +1864,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) var peerID = pendingData[0], tempID = pendingData[1], historyStorage = historiesStorage[peerID], - index = false, - message = false, - historyMessage = false, - i; + message, + historyMessage; // console.log('pending', randomID, historyStorage.pending); - for (i = 0; i < historyStorage.pending.length; i++) { - if (historyStorage.pending[i] == tempID) { - historyStorage.pending.splice(i, 1); - break; - } + var pos = historyStorage.pending.indexOf(tempID); + if (pos != -1) { + historyStorage.pending.splice(pos, 1); } if (message = messagesStorage[tempID]) { @@ -2315,17 +2307,15 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) historyStorage = historiesStorage[peerID]; if (historyStorage !== undefined) { - var topMsgID = historiesStorage[peerID].history[0]; if (historiesStorage[peerID].history.indexOf(message.id) != -1) { return false; } - else { - historyStorage.history.unshift(message.id); - if (message.id > 0 && message.id < topMsgID || true) { - historyStorage.history.sort(function (a, b) { - return b - a; - }); - } + var topMsgID = historiesStorage[peerID].history[0]; + historyStorage.history.unshift(message.id); + if (message.id > 0 && message.id < topMsgID) { + historyStorage.history.sort(function (a, b) { + return b - a; + }); } } else { historyStorage = historiesStorage[peerID] = {count: null, history: [message.id], pending: []};