mirror of
https://github.com/moparisthebest/mail
synced 2024-12-21 23:08:50 -05:00
app now still works if no internet connection is there
This commit is contained in:
parent
a20df131d1
commit
7b2751ed9b
@ -15,8 +15,7 @@ app.dao.EmailDAO = function(_, crypto, devicestorage, cloudstorage) {
|
||||
// sync user's cloud key with local storage
|
||||
cloudstorage.getUserSecretKey(account.get('emailAddress'), function(err) {
|
||||
if (err) {
|
||||
alert(err.status);
|
||||
return;
|
||||
console.log('Could not sync user key from server: ' + JSON.stringify(err));
|
||||
}
|
||||
// init crypto
|
||||
initCrypto();
|
||||
@ -88,18 +87,13 @@ app.dao.EmailDAO = function(_, crypto, devicestorage, cloudstorage) {
|
||||
var folder, self = this;
|
||||
|
||||
cloudstorage.listEncryptedItems('email', this.account.get('emailAddress'), folderName, function(res) {
|
||||
if (res.status) {
|
||||
// return if an error occured or if fetched list from cloud storage is empty
|
||||
if (!res || res.status || res.length === 0) {
|
||||
callback(res); // error
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: remove old folder items from devicestorage
|
||||
|
||||
// return if fetched list from cloud storage is empty
|
||||
if (res.length === 0) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
// persist encrypted list in device storage
|
||||
devicestorage.storeEcryptedList(res, 'email_' + folderName, function() {
|
||||
|
@ -29,8 +29,15 @@ app.view.MessageListView = Backbone.View.extend({
|
||||
|
||||
$.mobile.loading('show', { text: 'Syncing...', textVisible: true });
|
||||
// sync from cloud
|
||||
this.dao.syncFromCloud(this.folder, function() {
|
||||
this.dao.syncFromCloud(this.folder, function(res) {
|
||||
$.mobile.loading('hide');
|
||||
|
||||
// check for error
|
||||
if (res && res.status) {
|
||||
alert('Syncing failed: ' + JSON.stringify(res));
|
||||
return;
|
||||
}
|
||||
|
||||
// read local storage and add to list view
|
||||
self.loadItems();
|
||||
});
|
||||
|
@ -4,7 +4,8 @@ var TestData = function() {
|
||||
|
||||
this.getEmailCollection = function(size) {
|
||||
// create test data
|
||||
var i, mail, envelope, collection = new app.model.EmailCollection();
|
||||
var i, mail, envelope, collection = new app.model.EmailCollection(),
|
||||
bigAssString = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet,';
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
mail = new app.model.Email({
|
||||
@ -13,7 +14,7 @@ var TestData = function() {
|
||||
to:['jack@to.com'],
|
||||
subject: 'Important stuff ' + i,
|
||||
sentDate: '15:00',
|
||||
body: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet,'
|
||||
body: bigAssString
|
||||
});
|
||||
|
||||
collection.add(mail);
|
||||
|
@ -56,6 +56,7 @@ asyncTest("List Email models", 1, function() {
|
||||
emaildao_test.emailDao.listItems('inbox', 0, emaildao_test.list.length, function(collection) {
|
||||
var gotten = collection.toJSON(),
|
||||
reference = emaildao_test.list.toJSON();
|
||||
|
||||
deepEqual(gotten, reference, 'Collection length');
|
||||
|
||||
start();
|
||||
|
Loading…
Reference in New Issue
Block a user