1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-25 18:32:20 -05:00

app now still works if no internet connection is there

This commit is contained in:
Tankred Hase 2013-03-20 18:20:08 +01:00
parent a20df131d1
commit 7b2751ed9b
4 changed files with 15 additions and 12 deletions

View File

@ -15,8 +15,7 @@ app.dao.EmailDAO = function(_, crypto, devicestorage, cloudstorage) {
// sync user's cloud key with local storage // sync user's cloud key with local storage
cloudstorage.getUserSecretKey(account.get('emailAddress'), function(err) { cloudstorage.getUserSecretKey(account.get('emailAddress'), function(err) {
if (err) { if (err) {
alert(err.status); console.log('Could not sync user key from server: ' + JSON.stringify(err));
return;
} }
// init crypto // init crypto
initCrypto(); initCrypto();
@ -88,19 +87,14 @@ app.dao.EmailDAO = function(_, crypto, devicestorage, cloudstorage) {
var folder, self = this; var folder, self = this;
cloudstorage.listEncryptedItems('email', this.account.get('emailAddress'), folderName, function(res) { 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 callback(res); // error
return; return;
} }
// TODO: remove old folder items from devicestorage // 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 // persist encrypted list in device storage
devicestorage.storeEcryptedList(res, 'email_' + folderName, function() { devicestorage.storeEcryptedList(res, 'email_' + folderName, function() {
// remove cached folder in account model // remove cached folder in account model

View File

@ -29,8 +29,15 @@ app.view.MessageListView = Backbone.View.extend({
$.mobile.loading('show', { text: 'Syncing...', textVisible: true }); $.mobile.loading('show', { text: 'Syncing...', textVisible: true });
// sync from cloud // sync from cloud
this.dao.syncFromCloud(this.folder, function() { this.dao.syncFromCloud(this.folder, function(res) {
$.mobile.loading('hide'); $.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 // read local storage and add to list view
self.loadItems(); self.loadItems();
}); });

View File

@ -4,7 +4,8 @@ var TestData = function() {
this.getEmailCollection = function(size) { this.getEmailCollection = function(size) {
// create test data // 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++) { for (i = 0; i < size; i++) {
mail = new app.model.Email({ mail = new app.model.Email({
@ -13,7 +14,7 @@ var TestData = function() {
to:['jack@to.com'], to:['jack@to.com'],
subject: 'Important stuff ' + i, subject: 'Important stuff ' + i,
sentDate: '15:00', 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); collection.add(mail);

View File

@ -56,6 +56,7 @@ asyncTest("List Email models", 1, function() {
emaildao_test.emailDao.listItems('inbox', 0, emaildao_test.list.length, function(collection) { emaildao_test.emailDao.listItems('inbox', 0, emaildao_test.list.length, function(collection) {
var gotten = collection.toJSON(), var gotten = collection.toJSON(),
reference = emaildao_test.list.toJSON(); reference = emaildao_test.list.toJSON();
deepEqual(gotten, reference, 'Collection length'); deepEqual(gotten, reference, 'Collection length');
start(); start();