Browse Source

Improved updates handling

master
Igor Zhukov 10 years ago
parent
commit
3759ffef85
  1. 12
      app/js/controllers.js
  2. 27
      app/js/services.js

12
app/js/controllers.js

@ -783,7 +783,11 @@ angular.module('myApp.controllers', [])
$scope.history = []; $scope.history = [];
angular.forEach(historyResult.history, function (id) { angular.forEach(historyResult.history, function (id) {
$scope.history.push(AppMessagesManager.wrapForHistory(id)); var message = AppMessagesManager.wrapForHistory(id);
if ($scope.skippedHistory) {
delete message.unread;
}
$scope.history.push(message);
}); });
$scope.history.reverse(); $scope.history.reverse();
@ -1046,7 +1050,7 @@ angular.module('myApp.controllers', [])
$scope.$on('history_need_more', showMoreHistory); $scope.$on('history_need_more', showMoreHistory);
$rootScope.$watch('idle.isIDLE', function (newVal) { $rootScope.$watch('idle.isIDLE', function (newVal) {
if (!newVal && $scope.curDialog && $scope.curDialog.peerID) { if (!newVal && $scope.curDialog && $scope.curDialog.peerID && !$scope.mediaType && !$scope.skippedHistory) {
AppMessagesManager.readHistory($scope.curDialog.inputPeer); AppMessagesManager.readHistory($scope.curDialog.inputPeer);
} }
}); });
@ -1130,7 +1134,9 @@ angular.module('myApp.controllers', [])
// console.trace('ctrl text changed', newVal); // console.trace('ctrl text changed', newVal);
if (newVal && newVal.length) { if (newVal && newVal.length) {
AppMessagesManager.readHistory($scope.curDialog.inputPeer); if (!$scope.mediaType && !$scope.skippedHistory) {
AppMessagesManager.readHistory($scope.curDialog.inputPeer);
}
var backupDraftObj = {}; var backupDraftObj = {};
backupDraftObj['draft' + $scope.curDialog.peerID] = newVal; backupDraftObj['draft' + $scope.curDialog.peerID] = newVal;

27
app/js/services.js

@ -1182,7 +1182,11 @@ angular.module('myApp.services', [])
} }
function processAffectedHistory (inputPeer, affectedHistory, method) { function processAffectedHistory (inputPeer, affectedHistory, method) {
if (!ApiUpdatesManager.saveSeq(affectedHistory.seq)) { if (!ApiUpdatesManager.processUpdateMessage({
_: 'updates',
seq: affectedHistory.seq,
updates: []
})) {
return false; return false;
} }
if (!affectedHistory.offset) { if (!affectedHistory.offset) {
@ -2845,9 +2849,13 @@ angular.module('myApp.services', [])
pendingUpdates = {}; pendingUpdates = {};
function popPendingUpdate () { function popPendingUpdate () {
var updateMessage = pendingUpdates[curState.seq + 1]; var nextSeq = curState.seq + 1,
if (updateMessage && processUpdateMessage(updateMessage)) { updateMessage = pendingUpdates[nextSeq];
delete pendingUpdates[curState.seq + 1]; if (updateMessage) {
console.log(dT(), 'pop pending update', nextSeq, updateMessage);
if (processUpdateMessage(updateMessage)) {
delete pendingUpdates[nextSeq];
}
} }
} }
@ -2961,6 +2969,7 @@ angular.module('myApp.services', [])
popPendingUpdate(); popPendingUpdate();
if (getDifferencePending && curState.seq >= getDifferencePending.seqAwaiting) { if (getDifferencePending && curState.seq >= getDifferencePending.seqAwaiting) {
console.log(dT(), 'cancel pending getDiff', getDifferencePending.seqAwaiting);
clearTimeout(getDifferencePending.timeout); clearTimeout(getDifferencePending.timeout);
getDifferencePending = false; getDifferencePending = false;
} }
@ -2978,6 +2987,7 @@ angular.module('myApp.services', [])
MtpApiManager.invokeApi('updates.getDifference', {pts: curState.pts, date: curState.date, qts: 0}).then(function (differenceResult) { MtpApiManager.invokeApi('updates.getDifference', {pts: curState.pts, date: curState.date, qts: 0}).then(function (differenceResult) {
if (differenceResult._ == 'updates.differenceEmpty') { if (differenceResult._ == 'updates.differenceEmpty') {
console.log(dT(), 'apply empty diff', differenceResult.seq);
curState.date = differenceResult.date; curState.date = differenceResult.date;
curState.seq = differenceResult.seq; curState.seq = differenceResult.seq;
isSynchronizing = false; isSynchronizing = false;
@ -3006,6 +3016,8 @@ angular.module('myApp.services', [])
curState.pts = nextState.pts; curState.pts = nextState.pts;
curState.date = nextState.date; curState.date = nextState.date;
console.log(dT(), 'apply diff', curState.seq, curState.pts);
if (differenceResult._ == 'updates.differenceSlice') { if (differenceResult._ == 'updates.differenceSlice') {
getDifference(true); getDifference(true);
} else { } else {
@ -3025,7 +3037,6 @@ angular.module('myApp.services', [])
function saveSeq (seq, seqStart) { function saveSeq (seq, seqStart) {
// console.log('saving seq', curState.invalid, seq, seqStart, curState.seq);
seqStart = seqStart || seq; seqStart = seqStart || seq;
if (!seqStart) { if (!seqStart) {
@ -3033,12 +3044,13 @@ angular.module('myApp.services', [])
} }
if (isSynchronizing) { if (isSynchronizing) {
console.log(dT(), 'Seq decline', seqStart);
return false; return false;
} }
if (seqStart != curState.seq + 1) { if (seqStart != curState.seq + 1) {
if (seqStart > curState.seq) { if (seqStart > curState.seq) {
console.warn('Seq hole', seqStart, curState.seq); console.warn(dT(), 'Seq hole', seqStart, getDifferencePending && getDifferencePending.seqAwaiting);
if (!getDifferencePending) { if (!getDifferencePending) {
getDifferencePending = { getDifferencePending = {
seqAwaiting: seqStart, seqAwaiting: seqStart,
@ -3049,6 +3061,8 @@ angular.module('myApp.services', [])
} }
} }
return false; return false;
} else {
console.log(dT(), 'Seq apply', seqStart);
} }
curState.seq = seq; curState.seq = seq;
@ -3069,7 +3083,6 @@ angular.module('myApp.services', [])
return { return {
processUpdateMessage: processUpdateMessage, processUpdateMessage: processUpdateMessage,
saveSeq: saveSeq,
attach: attach attach: attach
} }
}) })

Loading…
Cancel
Save