Add button for re-importing contacts from phone
Add a section under settings for performing a contact sync from your mobile device. This just re-runs the same import operation that occurs at install/link time. // FREEBIE
This commit is contained in:
parent
c01722c31b
commit
8e1d884a10
6 changed files with 152 additions and 0 deletions
|
@ -83,6 +83,10 @@
|
|||
}
|
||||
});
|
||||
|
||||
window.getSyncRequest = function() {
|
||||
return new textsecure.SyncRequest(textsecure.messaging, messageReceiver);
|
||||
};
|
||||
|
||||
function init(firstRun) {
|
||||
window.removeEventListener('online', init);
|
||||
if (!textsecure.registration.isDone()) { return; }
|
||||
|
@ -112,6 +116,7 @@
|
|||
var syncRequest = new textsecure.SyncRequest(textsecure.messaging, messageReceiver);
|
||||
syncRequest.addEventListener('success', function() {
|
||||
console.log('sync successful');
|
||||
storage.put('synced_at', Date.now());
|
||||
window.dispatchEvent(new Event('textsecure:contactsync'));
|
||||
});
|
||||
syncRequest.addEventListener('timeout', function() {
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
setting = 'message';
|
||||
}
|
||||
this.$('#notification-setting-' + setting).attr('checked','checked');
|
||||
if (textsecure.storage.user.getDeviceId() != '1') {
|
||||
var syncView = new SyncView().render();
|
||||
this.$('.content').append(syncView.el);
|
||||
}
|
||||
},
|
||||
render_attributes: function() {
|
||||
return {
|
||||
|
@ -36,4 +40,59 @@
|
|||
};
|
||||
}
|
||||
});
|
||||
|
||||
var SyncView = Whisper.View.extend({
|
||||
templateName: 'syncSettings',
|
||||
className: 'syncSettings',
|
||||
events: {
|
||||
'click .sync': 'sync'
|
||||
},
|
||||
enable: function() {
|
||||
this.$('.sync').text(i18n('syncNow'));
|
||||
this.$('.sync').removeAttr('disabled');
|
||||
},
|
||||
disable: function() {
|
||||
this.$('.sync').attr('disabled', 'disabled');
|
||||
this.$('.sync').text(i18n('syncing'));
|
||||
},
|
||||
onsuccess: function() {
|
||||
storage.put('synced_at', Date.now());
|
||||
console.log('sync successful');
|
||||
this.enable();
|
||||
this.render();
|
||||
},
|
||||
ontimeout: function() {
|
||||
console.log('sync timed out');
|
||||
this.$('.synced_at').hide();
|
||||
this.$('.sync_failed').show();
|
||||
this.enable();
|
||||
},
|
||||
sync: function() {
|
||||
this.$('.sync_failed').hide();
|
||||
if (textsecure.storage.user.getDeviceId() != '1') {
|
||||
this.disable();
|
||||
var syncRequest = window.getSyncRequest();
|
||||
syncRequest.addEventListener('success', this.onsuccess.bind(this));
|
||||
syncRequest.addEventListener('timeout', this.ontimeout.bind(this));
|
||||
} else {
|
||||
console.log("Tried to sync from device 1");
|
||||
}
|
||||
},
|
||||
render_attributes: function() {
|
||||
var attrs = {
|
||||
sync: i18n('sync'),
|
||||
syncNow: i18n('syncNow'),
|
||||
syncExplanation: i18n('syncExplanation'),
|
||||
syncFailed: i18n('syncFailed')
|
||||
};
|
||||
var date = storage.get('synced_at');
|
||||
if (date) {
|
||||
date = new Date(date);
|
||||
attrs.lastSynced = i18n('lastSynced');
|
||||
attrs.syncDate = date.toLocaleDateString();
|
||||
attrs.syncTime = date.toLocaleTimeString();
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue