1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-30 04:42:15 -05:00

[WO-87][WO-89] automated sync and notification on incoming email

This commit is contained in:
Felix Hammerl 2013-11-05 14:00:50 +01:00
parent 0cefc08fa3
commit c0203bb1f6
4 changed files with 54 additions and 2 deletions

View File

@ -28,7 +28,8 @@ define([], function() {
host: 'smtp.gmail.com' host: 'smtp.gmail.com'
} }
}, },
checkOutboxInterval: 30000 checkOutboxInterval: 30000,
iconPath: '/img/icon.png'
}; };
/** /**

View File

@ -5,6 +5,8 @@ define(function(require) {
angular = require('angular'), angular = require('angular'),
appController = require('js/app-controller'), appController = require('js/app-controller'),
IScroll = require('iscroll'), IScroll = require('iscroll'),
str = require('js/app-config').string,
cfg = require('js/app-config').config,
emailDao; emailDao;
var MailListCtrl = function($scope) { var MailListCtrl = function($scope) {
@ -14,6 +16,35 @@ define(function(require) {
emailDao = appController._emailDao; emailDao = appController._emailDao;
emailDao.onIncomingMessage = function(email) {
if (email.subject.indexOf(str.subjectPrefix) === -1) {
return;
}
// sync
$scope.synchronize(function() {
// show notification
notificationForEmail(email);
});
};
function notificationClicked(uidString) {
var email, uid = parseInt(uidString, 10);
if (isNaN(uid)) {
return;
}
email = _.findWhere($scope.emails, {
uid: uid
});
if (email) {
$scope.select(email);
}
}
chrome.notifications.onClicked.addListener(notificationClicked);
// //
// scope functions // scope functions
// //
@ -34,7 +65,7 @@ define(function(require) {
markAsRead(email); markAsRead(email);
}; };
$scope.$parent.synchronize = $scope.synchronize = function() { $scope.$parent.synchronize = $scope.synchronize = function(callback) {
updateStatus('Syncing ...'); updateStatus('Syncing ...');
// sync from imap to local db // sync from imap to local db
syncImapFolder({ syncImapFolder({
@ -49,6 +80,9 @@ define(function(require) {
num: num num: num
}, function() { }, function() {
updateStatus('Last update: ', new Date()); updateStatus('Last update: ', new Date());
if (callback) {
callback();
}
}); });
}); });
}; };
@ -75,6 +109,15 @@ define(function(require) {
// helper functions // helper functions
// //
function notificationForEmail(email) {
chrome.notifications.create('' + email.uid, {
type: 'basic',
title: email.from[0].address,
message: email.subject.split(str.subjectPrefix)[1],
iconUrl: chrome.runtime.getURL(cfg.iconPath)
}, function() {});
}
function initList() { function initList() {
updateStatus('Read cache ...'); updateStatus('Read cache ...');

View File

@ -17,6 +17,13 @@ define(function(require) {
self._smtpClient = smtpClient; self._smtpClient = smtpClient;
self._crypto = crypto; self._crypto = crypto;
self._devicestorage = devicestorage; self._devicestorage = devicestorage;
// delegation-esque pattern to mitigate between node-style events and plain js
self._imapClient.onIncomingMessage = function(message) {
if (typeof self.onIncomingMessage === 'function') {
self.onIncomingMessage(message);
}
};
}; };
/** /**

View File

@ -10,6 +10,7 @@
"permissions": [{ "permissions": [{
"fileSystem": ["write"] "fileSystem": ["write"]
}, },
"notifications",
"https://keys.whiteout.io/", "https://keys.whiteout.io/",
"identity", { "identity", {
"socket": [ "socket": [