Skip to content
Snippets Groups Projects
Unverified Commit eea1e669 authored by Christoph Wurst's avatar Christoph Wurst Committed by GitHub
Browse files

Merge pull request #1316 from nextcloud/refactor/vue-dead-sync-service

Remove dead sync service
parents 4e47ea24 f4fd39cd
No related branches found
No related tags found
No related merge requests found
/**
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
*
* Mail
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
define(function(require) {
'use strict';
var Radio = require('radio');
var _timer = null;
var _accounts = null;
Radio.sync.on('start', startBackgroundSync);
var SYNC_INTERVAL = 30 * 1000; // twice a minute
function startBackgroundSync(accounts) {
_accounts = accounts;
clearTimeout(_timer);
triggerNextSync();
}
function triggerNextSync() {
_timer = setTimeout(function() {
var account;
if (require('state').accounts.length === 0) {
// Nothing to do right now, just re-trigger the sync event
triggerNextSync();
} else if (require('state').accounts.length === 1) {
account = _accounts.first();
} else {
account = _accounts.get(-1);
}
sync(account);
}, SYNC_INTERVAL);
}
/**
* @param {Account} account
* @returns {Promise}
*/
function sync(account) {
return Radio.sync.request('sync:folder', account.folders.first())
.then(function(newMessages) {
Radio.ui.trigger('notification:mail:show', newMessages);
})
.catch(function(e) {
console.error(e);
})
.then(triggerNextSync);
}
return {
sync: sync
};
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment