Add SyncRequest class
Similar in function to an xhr request, a textsecure.SyncRequest object is initialized from a message sender and receiver pair and initiates a request for sync from the master device. It later fires a success event when both contacts and groups are done syncing, or a timeout event after one minute. // FREEBIE
This commit is contained in:
parent
d8381cfc47
commit
925c1bdb33
5 changed files with 246 additions and 11 deletions
|
@ -103,21 +103,20 @@
|
|||
messageReceiver.addEventListener('sent', onSentMessage);
|
||||
messageReceiver.addEventListener('error', onError);
|
||||
|
||||
messageReceiver.addEventListener('contactsync', onContactSyncComplete);
|
||||
|
||||
window.textsecure.messaging = new textsecure.MessageSender(SERVER_URL, USERNAME, PASSWORD, ATTACHMENT_SERVER_URL);
|
||||
if (firstRun === true && textsecure.storage.user.getDeviceId() != '1') {
|
||||
textsecure.messaging.sendRequestContactSyncMessage().then(function() {
|
||||
textsecure.messaging.sendRequestGroupSyncMessage();
|
||||
var syncRequest = new textsecure.SyncRequest(textsecure.messaging, messageReceiver);
|
||||
syncRequest.addEventListener('success', function() {
|
||||
console.log('sync successful');
|
||||
window.dispatchEvent(new Event('textsecure:contactsync'));
|
||||
});
|
||||
syncRequest.addEventListener('timeout', function() {
|
||||
console.log('sync timed out');
|
||||
window.dispatchEvent(new Event('textsecure:contactsync'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onContactSyncComplete() {
|
||||
console.log('Contact sync complete');
|
||||
window.dispatchEvent(new Event('textsecure:contactsync'));
|
||||
}
|
||||
|
||||
function onContactReceived(ev) {
|
||||
var contactDetails = ev.contactDetails;
|
||||
ConversationController.create({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue