Sound notification

Additional code refactoring
This commit is contained in:
RainLoop Team 2015-01-27 01:06:00 +04:00
parent b42ce01e7e
commit aa84077ac4
87 changed files with 1573 additions and 574 deletions

View file

@ -17,6 +17,8 @@
Links = require('Common/Links'),
Translator = require('Common/Translator'),
SettingsUserStore = require('Stores/User/Settings'),
Settings = require('Storage/Settings'),
Cache = require('Storage/User/Cache'),
@ -24,18 +26,14 @@
MessageModel = require('Model/Message'),
Local = require('Storage/Local'),
AbstractData = require('Storage/AbstractData')
Local = require('Storage/Client')
;
/**
* @constructor
* @extends AbstractData
*/
function DataUserStorage()
{
AbstractData.call(this);
var
fRemoveSystemFolderType = function (observable) {
return function () {
@ -272,7 +270,7 @@
this.messageListPageCount = ko.computed(function () {
var iPage = window.Math.ceil(this.messageListCount() /
require('Stores/UserSettings').messagesPerPage());
SettingsUserStore.messagesPerPage());
return 0 >= iPage ? 1 : iPage;
}, this);
@ -328,13 +326,13 @@
this.messageFullScreenMode(false);
this.hideMessageBodies();
if (Enums.Layout.NoPreview === require('Stores/UserSettings').layout() &&
if (Enums.Layout.NoPreview === SettingsUserStore.layout() &&
-1 < window.location.hash.indexOf('message-preview'))
{
require('App/User').historyBack();
}
}
else if (Enums.Layout.NoPreview === require('Stores/UserSettings').layout())
else if (Enums.Layout.NoPreview === SettingsUserStore.layout())
{
this.message.focused(true);
}
@ -348,7 +346,7 @@
}
else if (Enums.KeyState.MessageView === Globals.keyScope())
{
if (Enums.Layout.NoPreview === require('Stores/UserSettings').layout() && this.message())
if (Enums.Layout.NoPreview === SettingsUserStore.layout() && this.message())
{
Globals.keyScope(Enums.KeyState.MessageView);
}
@ -451,8 +449,6 @@
this.purgeMessageBodyCacheThrottle = _.throttle(this.purgeMessageBodyCache, 1000 * 30);
}
_.extend(DataUserStorage.prototype, AbstractData.prototype);
DataUserStorage.prototype.purgeMessageBodyCache = function()
{
var
@ -487,8 +483,6 @@
DataUserStorage.prototype.populateDataOnStart = function()
{
AbstractData.prototype.populateDataOnStart.call(this);
this.accountEmail(Settings.settingsGet('Email'));
this.accountIncLogin(Settings.settingsGet('IncLogin'));
this.accountOutLogin(Settings.settingsGet('OutLogin'));
@ -519,52 +513,18 @@
var
iIndex = 0,
iLen = aNewMessages.length,
fNotificationHelper = function (sImageSrc, sTitle, sText)
{
var
NotificationSettingsStore = require('Stores/NotificationSettings'),
NotificationClass = NotificationSettingsStore.notificationClass(),
oNotification = null
;
if (NotificationClass && NotificationSettingsStore.enableDesktopNotification())
{
oNotification = new NotificationClass(sTitle, {
'body': sText,
'icon': sImageSrc
});
if (oNotification)
{
if (oNotification.show)
{
oNotification.show();
}
window.setTimeout((function (oLocalNotifications) {
return function () {
if (oLocalNotifications.cancel)
{
oLocalNotifications.cancel();
}
else if (oLocalNotifications.close)
{
oLocalNotifications.close();
}
};
}(oNotification)), 7000);
}
}
}
NotificationStore = require('Stores/User/Notification')
;
_.each(aNewMessages, function (oItem) {
Cache.addNewMessageCache(sFolder, oItem.Uid);
});
NotificationStore.playSoundNotification();
if (3 < iLen)
{
fNotificationHelper(
NotificationStore.displayDesktopNotification(
Links.notificationMailIcon(),
this.accountEmail(),
Translator.i18n('MESSAGE_LIST/NEW_MESSAGE_NOTIFICATION', {
@ -576,7 +536,7 @@
{
for (; iIndex < iLen; iIndex++)
{
fNotificationHelper(
NotificationStore.displayDesktopNotification(
Links.notificationMailIcon(),
MessageModel.emailsToLine(MessageModel.initEmailsFromJson(aNewMessages[iIndex].From), false),
aNewMessages[iIndex].Subject
@ -907,7 +867,7 @@
oMessage.showInternalImages(true);
}
if (oMessage.hasImages() && this.showImages())
if (oMessage.hasImages() && SettingsUserStore.showImages())
{
oMessage.showExternalImages(true);
}

View file

@ -10,6 +10,8 @@
Consts = require('Common/Consts'),
Base64 = require('Common/Base64'),
SettingsUserStore = require('Stores/User/Settings'),
Settings = require('Storage/Settings'),
Cache = require('Storage/User/Cache'),
Data = require('Storage/User/Data'),
@ -285,7 +287,7 @@
Data.projectHash(),
sFolderHash,
Cache.getFolderInboxName() === sFolderFullNameRaw ? Cache.getFolderUidNext(sFolderFullNameRaw) : '',
Data.threading() && Data.useThreads() ? '1' : '0',
Data.threading() && SettingsUserStore.useThreads() ? '1' : '0',
Data.threading() && sFolderFullNameRaw === Data.messageListThreadFolder() ? Data.messageListThreadUids().join(',') : ''
].join(String.fromCharCode(0))), bSilent ? [] : ['MessageList']);
}
@ -297,7 +299,7 @@
'Limit': iLimit,
'Search': sSearch,
'UidNext': Cache.getFolderInboxName() === sFolderFullNameRaw ? Cache.getFolderUidNext(sFolderFullNameRaw) : '',
'UseThreads': Data.threading() && Data.useThreads() ? '1' : '0',
'UseThreads': Data.threading() && SettingsUserStore.useThreads() ? '1' : '0',
'ExpandedThreadUid': Data.threading() && sFolderFullNameRaw === Data.messageListThreadFolder() ? Data.messageListThreadUids().join(',') : ''
}, '' === sSearch ? Consts.Defaults.DefaultAjaxTimeout : Consts.Defaults.SearchAjaxTimeout, '', bSilent ? [] : ['MessageList']);
}
@ -332,7 +334,7 @@
sFolderFullNameRaw,
iUid,
Data.projectHash(),
Data.threading() && Data.useThreads() ? '1' : '0'
Data.threading() && SettingsUserStore.useThreads() ? '1' : '0'
].join(String.fromCharCode(0))), ['Message']);
return true;
@ -411,7 +413,7 @@
'UidNext': Cache.getFolderInboxName() === sFolder ? Cache.getFolderUidNext(sFolder) : ''
});
}
else if (Data.useThreads())
else if (SettingsUserStore.useThreads())
{
require('App/User').reloadFlagsCurrentMessageListAndMessageFromCache();
}