|
|
@ -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 |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|