Added counters of unread messages for additional accounts (#377)

This commit is contained in:
RainLoop Team 2015-02-02 00:46:23 +04:00
parent abddb3d828
commit 79233ad83c
19 changed files with 333 additions and 93 deletions

View file

@ -494,15 +494,23 @@
AppUser.prototype.accountsCounts = function ()
{
AccountStore.accounts.loading(true);
Remote.accountsCounts(function (sResult, oData) {
AccountStore.accounts.loading(false);
if (Enums.StorageResultType.Success === sResult && oData.Result && oData.Result['Counts'])
{
var aAcounts = AccountStore.collection();
var
sEmail = Data.accountEmail(),
aAcounts = AccountStore.accounts()
;
_.each(oData.Result['Counts'], function (oItem) {
var oAccount = _.find(aAcounts, function (oAccount) {
return oAccount && oItem[0] === oAccount.email;
return oAccount && oItem[0] === oAccount.email && sEmail !== oAccount.email;
});
if (oAccount)
@ -518,12 +526,12 @@
{
var self = this;
AccountStore.loading(true);
AccountStore.accounts.loading(true);
IdentityStore.identities.loading(true);
Remote.accountsAndIdentities(function (sResult, oData) {
AccountStore.loading(false);
AccountStore.accounts.loading(false);
IdentityStore.identities.loading(false);
if (Enums.StorageResultType.Success === sResult && oData.Result)
@ -538,20 +546,26 @@
if (Utils.isArray(oData.Result['Accounts']))
{
_.each(AccountStore.collection(), function (oAccount) {
_.each(AccountStore.accounts(), function (oAccount) {
aCounts[oAccount.email] = oAccount.count();
});
Utils.delegateRunOnDestroy(AccountStore.collection());
Utils.delegateRunOnDestroy(AccountStore.accounts());
AccountStore.collection(_.map(oData.Result['Accounts'], function (sValue) {
AccountStore.accounts(_.map(oData.Result['Accounts'], function (sValue) {
return new AccountModel(sValue, sValue !== sParentEmail, aCounts[sValue] || 0);
}));
}
if (Utils.isUnd(bBoot) ? false : !!bBoot)
{
self.accountsCounts();
_.delay(function () {
self.accountsCounts();
}, 1000 * 5);
Events.sub('interval.10m-after5m', function () {
self.accountsCounts();
});
}
if (Utils.isArray(oData.Result['Identities']))

View file

@ -48,7 +48,10 @@
{
if (null === this.selectedItem())
{
this.selectedItem.valueHasMutated();
if (this.selectedItem.valueHasMutated)
{
this.selectedItem.valueHasMutated();
}
}
else
{

2
dev/External/ko.js vendored
View file

@ -828,7 +828,7 @@
oTarget('');
}
}
})
}).extend({'notify': 'always'})
;
oResult(oTarget());

View file

@ -127,7 +127,7 @@
}
},
'owner': this
});
}).extend({'notify': 'always'});
this.messageCountUnread = ko.computed({
'read': this.privateMessageCountUnread,
@ -142,7 +142,7 @@
}
},
'owner': this
});
}).extend({'notify': 'always'});
this.printableUnreadCount = ko.computed(function () {
var

View file

@ -12,6 +12,7 @@
Events = require('Common/Events'),
Translator = require('Common/Translator'),
AccountStore = require('Stores/User/Account'),
SettingsStore = require('Stores/User/Settings'),
Data = require('Storage/User/Data'),
@ -111,8 +112,18 @@
SettingsStore.layout.valueHasMutated();
}, 50);
Events.sub('mailbox.inbox-unread-count', function (nCount) {
Data.foldersInboxUnreadCount(nCount);
Events.sub('mailbox.inbox-unread-count', function (iCount) {
Data.foldersInboxUnreadCount(iCount);
var sEmail = Data.accountEmail();
_.each(AccountStore.accounts(), function (oItem) {
if (oItem && sEmail === oItem.email)
{
oItem.count(iCount);
}
});
});
Data.foldersInboxUnreadCount.subscribe(function () {

View file

@ -96,7 +96,7 @@
this.contactsType.valueHasMutated();
}
}
});
}).extend({'notify': 'always'});
this.contactsType.subscribe(function () {
this.testContactsSuccess(false);

View file

@ -22,10 +22,10 @@
*/
function AccountsUserSettings()
{
this.accounts = AccountStore.collection;
this.accounts = AccountStore.accounts;
this.processText = ko.computed(function () {
return AccountStore.loading() ? Translator.i18n('SETTINGS_ACCOUNTS/LOADING_PROCESS') : '';
return AccountStore.accounts.loading() ? Translator.i18n('SETTINGS_ACCOUNTS/LOADING_PROCESS') : '';
}, this);
this.visibility = ko.computed(function () {

View file

@ -238,8 +238,7 @@
*/
RemoteUserStorage.prototype.accountsCounts = function (fCallback)
{
return !!fCallback; // TODO
// this.defaultRequest(fCallback, 'AccountsCounts');
this.defaultRequest(fCallback, 'AccountsCounts');
};
/**

View file

@ -15,28 +15,43 @@
*/
function AccountUserStore()
{
this.loading = ko.observable(false).extend({'throttle': 100});
this.accounts = ko.observableArray([]);
this.accounts.loading = ko.observable(false).extend({'throttle': 100});
this.collection = ko.observableArray([]);
this.collectionEmailNames = ko.observableArray([]).extend({'throttle': 1000});
this.collectionEmailNames.skipFirst = true;
this.accountsEmailNames = ko.observableArray([]).extend({'throttle': 1000});
this.accountsEmailNames.skipFirst = true;
this.collection.subscribe(function (aList) {
this.collectionEmailNames(_.compact(_.map(aList, function (oItem) {
this.accounts.subscribe(function (aList) {
this.accountsEmailNames(_.compact(_.map(aList, function (oItem) {
return oItem ? oItem.email : null;
})));
}, this);
this.collectionEmailNames.subscribe(function (aList) {
if (this.collectionEmailNames.skipFirst)
this.accountsEmailNames.subscribe(function (aList) {
if (this.accountsEmailNames.skipFirst)
{
this.collectionEmailNames.skipFirst = false;
this.accountsEmailNames.skipFirst = false;
}
else if (aList && 1 < aList.length)
{
Remote.accountSortOrder(null, aList);
}
}, this);
this.accountsUnreadCount = ko.computed(function () {
var iResult = 0;
_.each(this.accounts(), function (oItem) {
if (oItem)
{
iResult += oItem.count();
}
});
return iResult;
}, this);
}
module.exports = new AccountUserStore();

View file

@ -59,7 +59,7 @@
return iResult;
}, this);
}, this).extend({'notify': 'always'});
this.enableDesktopNotification = ko.computed({
'owner': this,
@ -117,7 +117,7 @@
this.allowDesktopNotification(false);
}
}
});
}).extend({'notify': 'always'});
if (!this.enableDesktopNotification.valueHasMutated)
{
@ -150,7 +150,8 @@
this.soundNotificationIsSupported(true);
this.buzz = new buzz.sound(Links.sound('new-mail'), {
formats: ['ogg', 'mp3']
'preload': 'none',
'formats': ['mp3', 'ogg']
});
}
else

View file

@ -41,9 +41,6 @@
color: #fff;
text-shadow: 0 1px 0 #000;
position: absolute;
top: 11px;
right: 70px;
display: inline-block;
height: 28px;
max-width: 250px;
@ -55,6 +52,7 @@
text-overflow: ellipsis;
border-radius: 4px;
font-weight: bold;
margin-right: 5px;
white-space: nowrap;
}

View file

@ -29,18 +29,14 @@
{
AbstractView.call(this, 'Right', 'SystemDropDown');
this.accounts = AccountStore.collection;
this.accountEmail = Data.accountEmail;
this.accountsLoading = AccountStore.loading;
this.accounts = AccountStore.accounts;
this.accountsUnreadCount = AccountStore.accountsUnreadCount;
this.accountMenuDropdownTrigger = ko.observable(false);
this.capaAdditionalAccounts = ko.observable(Settings.capa(Enums.Capa.AdditionalAccounts));
this.loading = ko.computed(function () {
return this.accountsLoading();
}, this);
this.accountClick = _.bind(this.accountClick, this);
}
@ -50,10 +46,10 @@
{
if (oAccount && oEvent && !Utils.isUnd(oEvent.which) && 1 === oEvent.which)
{
var self = this;
this.accountsLoading(true);
AccountStore.accounts.loading(true);
_.delay(function () {
self.accountsLoading(false);
AccountStore.accounts.loading(false);
}, 1000);
}