snappymail/dev/Stores/User/Account.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
import _ from '_';
2019-07-05 03:19:24 +08:00
import { Magics } from 'Common/Enums';
import * as Settings from 'Storage/Settings';
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
class AccountUserStore {
constructor() {
this.email = ko.observable('');
this.parentEmail = ko.observable('');
2015-01-28 06:16:00 +08:00
this.signature = ko.observable('');
2015-02-19 03:52:52 +08:00
this.accounts = ko.observableArray([]);
2019-07-05 03:19:24 +08:00
this.accounts.loading = ko.observable(false).extend({ throttle: Magics.Time100ms });
this.computers();
}
computers() {
this.accountsEmails = ko.computed(() => _.compact(this.accounts().map(item => (item ? item.email : null))));
this.accountsUnreadCount = ko.computed(() => 0);
// this.accountsUnreadCount = ko.computed(() => {
// let result = 0;
// this.accounts().forEach(item => {
// if (item)
// {
// result += item.count();
// }
// });
// return result;
// });
}
populate() {
this.email(Settings.settingsGet('Email'));
this.parentEmail(Settings.settingsGet('ParentEmail'));
}
/**
* @returns {boolean}
*/
isRootAccount() {
return '' === this.parentEmail();
}
}
2015-01-28 06:16:00 +08:00
export default new AccountUserStore();