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', []) @@ -783,7 +783,11 @@ angular.module('myApp.controllers', [])
$scope.history = [];
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();
@ -1046,7 +1050,7 @@ angular.module('myApp.controllers', []) @@ -1046,7 +1050,7 @@ angular.module('myApp.controllers', [])
$scope.$on('history_need_more', showMoreHistory);
$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);
}
});
@ -1130,7 +1134,9 @@ angular.module('myApp.controllers', []) @@ -1130,7 +1134,9 @@ angular.module('myApp.controllers', [])
// console.trace('ctrl text changed', newVal);
if (newVal && newVal.length) {
AppMessagesManager.readHistory($scope.curDialog.inputPeer);
if (!$scope.mediaType && !$scope.skippedHistory) {
AppMessagesManager.readHistory($scope.curDialog.inputPeer);
}
var backupDraftObj = {};
backupDraftObj['draft' + $scope.curDialog.peerID] = newVal;

27
app/js/services.js

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

Loading…
Cancel
Save