|
|
@ -1170,12 +1170,13 @@ angular.module('myApp.services', []) |
|
|
|
return MtpApiManager.invokeApi('messages.deleteMessages', { |
|
|
|
return MtpApiManager.invokeApi('messages.deleteMessages', { |
|
|
|
id: messageIDs |
|
|
|
id: messageIDs |
|
|
|
}).then(function (deletedMessageIDs) { |
|
|
|
}).then(function (deletedMessageIDs) { |
|
|
|
|
|
|
|
ApiUpdatesManager.processUpdateMessage({ |
|
|
|
ApiUpdatesManager.saveUpdate({ |
|
|
|
_: 'updateShort', |
|
|
|
_: 'updateDeleteMessages', |
|
|
|
update: { |
|
|
|
messages: deletedMessageIDs |
|
|
|
_: 'updateDeleteMessages', |
|
|
|
|
|
|
|
messages: deletedMessageIDs |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return deletedMessageIDs; |
|
|
|
return deletedMessageIDs; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -1361,22 +1362,25 @@ angular.module('myApp.services', []) |
|
|
|
peer: inputPeer, |
|
|
|
peer: inputPeer, |
|
|
|
message: text, |
|
|
|
message: text, |
|
|
|
random_id: randomID |
|
|
|
random_id: randomID |
|
|
|
}, sentRequestOptions).then(function (result) { |
|
|
|
}, sentRequestOptions).then(function (sentMessage) { |
|
|
|
if (ApiUpdatesManager.saveSeq(result.seq)) { |
|
|
|
message.date = sentMessage.date; |
|
|
|
ApiUpdatesManager.saveUpdate({ |
|
|
|
message.id = sentMessage.id; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApiUpdatesManager.processUpdateMessage({ |
|
|
|
|
|
|
|
_: 'updates', |
|
|
|
|
|
|
|
users: [], |
|
|
|
|
|
|
|
chats: [], |
|
|
|
|
|
|
|
seq: sentMessage.seq, |
|
|
|
|
|
|
|
updates: [{ |
|
|
|
_: 'updateMessageID', |
|
|
|
_: 'updateMessageID', |
|
|
|
random_id: randomIDS, |
|
|
|
random_id: randomIDS, |
|
|
|
id: result.id |
|
|
|
id: sentMessage.id |
|
|
|
}); |
|
|
|
}, { |
|
|
|
|
|
|
|
|
|
|
|
message.date = result.date; |
|
|
|
|
|
|
|
message.id = result.id; |
|
|
|
|
|
|
|
ApiUpdatesManager.saveUpdate({ |
|
|
|
|
|
|
|
_: 'updateNewMessage', |
|
|
|
_: 'updateNewMessage', |
|
|
|
message: message, |
|
|
|
message: message, |
|
|
|
pts: result.pts |
|
|
|
pts: sentMessage.pts |
|
|
|
}); |
|
|
|
}] |
|
|
|
} |
|
|
|
}); |
|
|
|
}, function (error) { |
|
|
|
}, function (error) { |
|
|
|
toggleError(true); |
|
|
|
toggleError(true); |
|
|
|
})['finally'](function () { |
|
|
|
})['finally'](function () { |
|
|
@ -1503,25 +1507,26 @@ angular.module('myApp.services', []) |
|
|
|
peer: inputPeer, |
|
|
|
peer: inputPeer, |
|
|
|
media: inputMedia, |
|
|
|
media: inputMedia, |
|
|
|
random_id: randomID |
|
|
|
random_id: randomID |
|
|
|
}).then(function (result) { |
|
|
|
}).then(function (statedMessage) { |
|
|
|
if (ApiUpdatesManager.saveSeq(result.seq)) { |
|
|
|
message.date = statedMessage.message.date; |
|
|
|
ApiUpdatesManager.saveUpdate({ |
|
|
|
message.id = statedMessage.message.id; |
|
|
|
|
|
|
|
message.media = statedMessage.message.media; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApiUpdatesManager.processUpdateMessage({ |
|
|
|
|
|
|
|
_: 'updates', |
|
|
|
|
|
|
|
users: statedMessage.users, |
|
|
|
|
|
|
|
chats: statedMessage.chats, |
|
|
|
|
|
|
|
seq: statedMessage.seq, |
|
|
|
|
|
|
|
updates: [{ |
|
|
|
_: 'updateMessageID', |
|
|
|
_: 'updateMessageID', |
|
|
|
random_id: randomIDS, |
|
|
|
random_id: randomIDS, |
|
|
|
id: result.message.id |
|
|
|
id: statedMessage.message.id |
|
|
|
}); |
|
|
|
}, { |
|
|
|
|
|
|
|
|
|
|
|
message.date = result.message.date; |
|
|
|
|
|
|
|
message.id = result.message.id; |
|
|
|
|
|
|
|
message.media = result.message.media; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApiUpdatesManager.saveUpdate({ |
|
|
|
|
|
|
|
_: 'updateNewMessage', |
|
|
|
_: 'updateNewMessage', |
|
|
|
message: message, |
|
|
|
message: message, |
|
|
|
pts: result.pts |
|
|
|
pts: statedMessage.pts |
|
|
|
}); |
|
|
|
}] |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}, function (error) { |
|
|
|
}, function (error) { |
|
|
|
toggleError(true); |
|
|
|
toggleError(true); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -1617,24 +1622,26 @@ angular.module('myApp.services', []) |
|
|
|
peer: inputPeer, |
|
|
|
peer: inputPeer, |
|
|
|
media: inputMedia, |
|
|
|
media: inputMedia, |
|
|
|
random_id: randomID |
|
|
|
random_id: randomID |
|
|
|
}).then(function (result) { |
|
|
|
}).then(function (statedMessage) { |
|
|
|
if (ApiUpdatesManager.saveSeq(result.seq)) { |
|
|
|
message.date = statedMessage.message.date; |
|
|
|
ApiUpdatesManager.saveUpdate({ |
|
|
|
message.id = statedMessage.message.id; |
|
|
|
|
|
|
|
message.media = statedMessage.message.media; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApiUpdatesManager.processUpdateMessage({ |
|
|
|
|
|
|
|
_: 'updates', |
|
|
|
|
|
|
|
users: statedMessage.users, |
|
|
|
|
|
|
|
chats: statedMessage.chats, |
|
|
|
|
|
|
|
seq: statedMessage.seq, |
|
|
|
|
|
|
|
updates: [{ |
|
|
|
_: 'updateMessageID', |
|
|
|
_: 'updateMessageID', |
|
|
|
random_id: randomIDS, |
|
|
|
random_id: randomIDS, |
|
|
|
id: result.message.id |
|
|
|
id: statedMessage.message.id |
|
|
|
}); |
|
|
|
}, { |
|
|
|
|
|
|
|
|
|
|
|
message.date = result.message.date; |
|
|
|
|
|
|
|
message.id = result.message.id; |
|
|
|
|
|
|
|
message.media = result.message.media; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApiUpdatesManager.saveUpdate({ |
|
|
|
|
|
|
|
_: 'updateNewMessage', |
|
|
|
_: 'updateNewMessage', |
|
|
|
message: message, |
|
|
|
message: message, |
|
|
|
pts: result.pts |
|
|
|
pts: statedMessage.pts |
|
|
|
}); |
|
|
|
}] |
|
|
|
} |
|
|
|
}); |
|
|
|
}, function (error) { |
|
|
|
}, function (error) { |
|
|
|
toggleError(true); |
|
|
|
toggleError(true); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -1656,22 +1663,23 @@ angular.module('myApp.services', []) |
|
|
|
return MtpApiManager.invokeApi('messages.forwardMessages', { |
|
|
|
return MtpApiManager.invokeApi('messages.forwardMessages', { |
|
|
|
peer: AppPeersManager.getInputPeerByID(peerID), |
|
|
|
peer: AppPeersManager.getInputPeerByID(peerID), |
|
|
|
id: msgIDs |
|
|
|
id: msgIDs |
|
|
|
}).then(function (forwardResult) { |
|
|
|
}).then(function (statedMessages) { |
|
|
|
AppUsersManager.saveApiUsers(forwardResult.users); |
|
|
|
var updates = []; |
|
|
|
AppChatsManager.saveApiChats(forwardResult.chats); |
|
|
|
angular.forEach(statedMessages.messages, function(apiMessage) { |
|
|
|
|
|
|
|
updates.push({ |
|
|
|
if (ApiUpdatesManager.saveSeq(forwardResult.seq)) { |
|
|
|
_: 'updateNewMessage', |
|
|
|
angular.forEach(forwardResult.messages, function(apiMessage) { |
|
|
|
message: apiMessage, |
|
|
|
|
|
|
|
pts: statedMessages.pts |
|
|
|
ApiUpdatesManager.saveUpdate({ |
|
|
|
|
|
|
|
_: 'updateNewMessage', |
|
|
|
|
|
|
|
message: apiMessage, |
|
|
|
|
|
|
|
pts: forwardResult.pts |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApiUpdatesManager.processUpdateMessage({ |
|
|
|
|
|
|
|
_: 'updates', |
|
|
|
|
|
|
|
users: statedMessages.users, |
|
|
|
|
|
|
|
chats: statedMessages.chats, |
|
|
|
|
|
|
|
seq: statedMessages.seq, |
|
|
|
|
|
|
|
updates: updates |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -1686,9 +1694,12 @@ angular.module('myApp.services', []) |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
i; |
|
|
|
i; |
|
|
|
|
|
|
|
|
|
|
|
ApiUpdatesManager.saveUpdate({ |
|
|
|
ApiUpdatesManager.processUpdateMessage({ |
|
|
|
_: 'updateDeleteMessages', |
|
|
|
_: 'updateShort', |
|
|
|
messages: [tempID] |
|
|
|
update: { |
|
|
|
|
|
|
|
_: 'updateDeleteMessages', |
|
|
|
|
|
|
|
messages: [tempID] |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < historyStorage.pending.length; i++) { |
|
|
|
for (i = 0; i < historyStorage.pending.length; i++) { |
|
|
@ -2828,15 +2839,28 @@ angular.module('myApp.services', []) |
|
|
|
|
|
|
|
|
|
|
|
.service('ApiUpdatesManager', function ($rootScope, MtpNetworkerFactory, AppUsersManager, AppChatsManager, AppPeersManager, MtpApiManager) { |
|
|
|
.service('ApiUpdatesManager', function ($rootScope, MtpNetworkerFactory, AppUsersManager, AppChatsManager, AppPeersManager, MtpApiManager) { |
|
|
|
|
|
|
|
|
|
|
|
var curState = {invalid: true}; |
|
|
|
var isSynchronizing = true, |
|
|
|
|
|
|
|
getDifferencePending = false, |
|
|
|
|
|
|
|
curState = {}, |
|
|
|
|
|
|
|
pendingUpdates = {}; |
|
|
|
|
|
|
|
|
|
|
|
function processUpdateMessage (updateMessage) { |
|
|
|
function popPendingUpdate () { |
|
|
|
if (curState.invalid) { |
|
|
|
var updateMessage = pendingUpdates[curState.seq + 1]; |
|
|
|
return false; |
|
|
|
if (updateMessage && processUpdateMessage(updateMessage)) { |
|
|
|
|
|
|
|
delete pendingUpdates[curState.seq + 1]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function forceGetDifference () { |
|
|
|
|
|
|
|
if (!isSynchronizing) { |
|
|
|
|
|
|
|
getDifference(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function processUpdateMessage (updateMessage) { |
|
|
|
if (updateMessage.seq) { |
|
|
|
if (updateMessage.seq) { |
|
|
|
if (!saveSeq(updateMessage.seq, updateMessage.seq_start)) { |
|
|
|
if (!saveSeq(updateMessage.seq, updateMessage.seq_start)) { |
|
|
|
|
|
|
|
pendingUpdates[updateMessage.seq_start || updateMessage.seq] = updateMessage; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (updateMessage.date) { |
|
|
|
if (updateMessage.date) { |
|
|
@ -2847,47 +2871,18 @@ angular.module('myApp.services', []) |
|
|
|
|
|
|
|
|
|
|
|
switch (updateMessage._) { |
|
|
|
switch (updateMessage._) { |
|
|
|
case 'updatesTooLong': |
|
|
|
case 'updatesTooLong': |
|
|
|
getDifference(); |
|
|
|
forceGetDifference(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'updateShort': |
|
|
|
case 'updateShort': |
|
|
|
saveUpdate(updateMessage.update); |
|
|
|
saveUpdate(updateMessage.update); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'updatesCombined': |
|
|
|
|
|
|
|
case 'updates': |
|
|
|
|
|
|
|
AppUsersManager.saveApiUsers(updateMessage.users); |
|
|
|
|
|
|
|
AppChatsManager.saveApiChats(updateMessage.chats); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var i, update, message; |
|
|
|
|
|
|
|
for (var i = 0; i < updateMessage.updates.length; i++) { |
|
|
|
|
|
|
|
update = updateMessage.updates[i]; |
|
|
|
|
|
|
|
switch (update._) { |
|
|
|
|
|
|
|
case 'updateNewMessage': |
|
|
|
|
|
|
|
message = update.message; |
|
|
|
|
|
|
|
if (message.from_id && !AppUsersManager.hasUser(message.from_id)) { |
|
|
|
|
|
|
|
console.log('User not found', message.from_id, 'getDiff'); |
|
|
|
|
|
|
|
getDifference(); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (message.to_id.chat_id && !AppChatsManager.hasChat(message.to_id.chat_id)) { |
|
|
|
|
|
|
|
console.log('Chat not found', message.to_id.chat_id, 'getDiff'); |
|
|
|
|
|
|
|
getDifference(); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
angular.forEach(updateMessage.updates, function (update) { |
|
|
|
|
|
|
|
saveUpdate(update); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'updateShortMessage': |
|
|
|
case 'updateShortMessage': |
|
|
|
if (!AppUsersManager.hasUser(updateMessage.from_id)) { |
|
|
|
if (!AppUsersManager.hasUser(updateMessage.from_id)) { |
|
|
|
console.log('User not found', updateMessage.from_id, 'getDiff'); |
|
|
|
console.log('User not found', updateMessage.from_id, 'getDiff'); |
|
|
|
getDifference(); |
|
|
|
forceGetDifference(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
saveUpdate({ |
|
|
|
saveUpdate({ |
|
|
@ -2911,7 +2906,7 @@ angular.module('myApp.services', []) |
|
|
|
if (!AppUsersManager.hasUser(updateMessage.from_id) || |
|
|
|
if (!AppUsersManager.hasUser(updateMessage.from_id) || |
|
|
|
!AppChatsManager.hasChat(updateMessage.chat_id)) { |
|
|
|
!AppChatsManager.hasChat(updateMessage.chat_id)) { |
|
|
|
console.log('User or chat not found', updateMessage.from_id, updateMessage.chat_id, 'getDiff'); |
|
|
|
console.log('User or chat not found', updateMessage.from_id, updateMessage.chat_id, 'getDiff'); |
|
|
|
getDifference(); |
|
|
|
forceGetDifference(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
saveUpdate({ |
|
|
|
saveUpdate({ |
|
|
@ -2930,22 +2925,63 @@ angular.module('myApp.services', []) |
|
|
|
pts: updateMessage.pts |
|
|
|
pts: updateMessage.pts |
|
|
|
}); |
|
|
|
}); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'updatesCombined': |
|
|
|
|
|
|
|
case 'updates': |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
AppUsersManager.saveApiUsers(updateMessage.users); |
|
|
|
|
|
|
|
AppChatsManager.saveApiChats(updateMessage.chats); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var i, update, message; |
|
|
|
|
|
|
|
for (var i = 0; i < updateMessage.updates.length; i++) { |
|
|
|
|
|
|
|
update = updateMessage.updates[i]; |
|
|
|
|
|
|
|
switch (update._) { |
|
|
|
|
|
|
|
case 'updateNewMessage': |
|
|
|
|
|
|
|
message = update.message; |
|
|
|
|
|
|
|
if (message.from_id && !AppUsersManager.hasUser(message.from_id)) { |
|
|
|
|
|
|
|
console.log('User not found', message.from_id, 'getDiff'); |
|
|
|
|
|
|
|
forceGetDifference(); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (message.to_id.chat_id && !AppChatsManager.hasChat(message.to_id.chat_id)) { |
|
|
|
|
|
|
|
console.log('Chat not found', message.to_id.chat_id, 'getDiff'); |
|
|
|
|
|
|
|
forceGetDifference(); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
angular.forEach(updateMessage.updates, function (update) { |
|
|
|
|
|
|
|
saveUpdate(update); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
popPendingUpdate(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (getDifferencePending && curState.seq >= getDifferencePending.seqAwaiting) { |
|
|
|
|
|
|
|
clearTimeout(getDifferencePending.timeout); |
|
|
|
|
|
|
|
getDifferencePending = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getDifference (force) { |
|
|
|
function getDifference () { |
|
|
|
if (curState.invalid && !force) { |
|
|
|
isSynchronizing = true; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
if (getDifferencePending) { |
|
|
|
|
|
|
|
clearTimeout(getDifferencePending.timeout); |
|
|
|
|
|
|
|
getDifferencePending = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
curState.invalid = true; |
|
|
|
|
|
|
|
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') { |
|
|
|
curState.date = differenceResult.date; |
|
|
|
curState.date = differenceResult.date; |
|
|
|
curState.seq = differenceResult.seq; |
|
|
|
curState.seq = differenceResult.seq; |
|
|
|
delete curState.invalid; |
|
|
|
isSynchronizing = false; |
|
|
|
|
|
|
|
popPendingUpdate(); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2954,7 +2990,7 @@ angular.module('myApp.services', []) |
|
|
|
|
|
|
|
|
|
|
|
// Should be first because of updateMessageID
|
|
|
|
// Should be first because of updateMessageID
|
|
|
|
angular.forEach(differenceResult.other_updates, function(update){ |
|
|
|
angular.forEach(differenceResult.other_updates, function(update){ |
|
|
|
saveUpdate(update, true); |
|
|
|
saveUpdate(update); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
angular.forEach(differenceResult.new_messages, function (apiMessage) { |
|
|
|
angular.forEach(differenceResult.new_messages, function (apiMessage) { |
|
|
@ -2962,7 +2998,7 @@ angular.module('myApp.services', []) |
|
|
|
_: 'updateNewMessage', |
|
|
|
_: 'updateNewMessage', |
|
|
|
message: apiMessage, |
|
|
|
message: apiMessage, |
|
|
|
pts: curState.pts |
|
|
|
pts: curState.pts |
|
|
|
}, true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var nextState = differenceResult.intermediate_state || differenceResult.state; |
|
|
|
var nextState = differenceResult.intermediate_state || differenceResult.state; |
|
|
@ -2973,15 +3009,12 @@ angular.module('myApp.services', []) |
|
|
|
if (differenceResult._ == 'updates.differenceSlice') { |
|
|
|
if (differenceResult._ == 'updates.differenceSlice') { |
|
|
|
getDifference(true); |
|
|
|
getDifference(true); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
delete curState.invalid; |
|
|
|
isSynchronizing = false; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function saveUpdate (update, force) { |
|
|
|
function saveUpdate (update) { |
|
|
|
if (curState.invalid && !force) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (update.pts) { |
|
|
|
if (update.pts) { |
|
|
|
curState.pts = update.pts; |
|
|
|
curState.pts = update.pts; |
|
|
|
} |
|
|
|
} |
|
|
@ -2989,23 +3022,31 @@ angular.module('myApp.services', []) |
|
|
|
$rootScope.$broadcast('apiUpdate', update); |
|
|
|
$rootScope.$broadcast('apiUpdate', update); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function saveSeq (seq, seqStart) { |
|
|
|
|
|
|
|
// console.log('saving seq', curState.invalid, seq, seqStart, curState.seq);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (curState.invalid) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function saveSeq (seq, seqStart) { |
|
|
|
|
|
|
|
// console.log('saving seq', curState.invalid, seq, seqStart, curState.seq);
|
|
|
|
seqStart = seqStart || seq; |
|
|
|
seqStart = seqStart || seq; |
|
|
|
|
|
|
|
|
|
|
|
if (!seqStart) { |
|
|
|
if (!seqStart) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isSynchronizing) { |
|
|
|
|
|
|
|
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('Seq hole', seqStart, curState.seq); |
|
|
|
getDifference(); |
|
|
|
if (!getDifferencePending) { |
|
|
|
|
|
|
|
getDifferencePending = { |
|
|
|
|
|
|
|
seqAwaiting: seqStart, |
|
|
|
|
|
|
|
timeout: setTimeout(function () { |
|
|
|
|
|
|
|
getDifference(); |
|
|
|
|
|
|
|
}, 5000) |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -3021,13 +3062,13 @@ angular.module('myApp.services', []) |
|
|
|
curState.seq = stateResult.seq; |
|
|
|
curState.seq = stateResult.seq; |
|
|
|
curState.pts = stateResult.pts; |
|
|
|
curState.pts = stateResult.pts; |
|
|
|
curState.date = stateResult.date; |
|
|
|
curState.date = stateResult.date; |
|
|
|
delete curState.invalid; |
|
|
|
isSynchronizing = false; |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
saveUpdate: saveUpdate, |
|
|
|
processUpdateMessage: processUpdateMessage, |
|
|
|
saveSeq: saveSeq, |
|
|
|
saveSeq: saveSeq, |
|
|
|
attach: attach |
|
|
|
attach: attach |
|
|
|
} |
|
|
|
} |
|
|
|