2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
|
|
|
import _ from '_';
|
2019-07-05 03:19:24 +08:00
|
|
|
import { Magics } from 'Common/Enums';
|
2016-08-17 06:01:20 +08:00
|
|
|
import * as Settings from 'Storage/Settings';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
class AccountUserStore {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
|
|
|
this.email = ko.observable('');
|
|
|
|
this.parentEmail = ko.observable('');
|
2015-01-28 06:16:00 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.signature = ko.observable('');
|
2015-02-19 03:52:52 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.accounts = ko.observableArray([]);
|
2019-07-05 03:19:24 +08:00
|
|
|
this.accounts.loading = ko.observable(false).extend({ throttle: Magics.Time100ms });
|
2015-02-02 04:46:23 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.computers();
|
|
|
|
}
|
2015-02-02 04:46:23 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
computers() {
|
2020-07-23 02:09:31 +08:00
|
|
|
this.accountsEmails = ko.computed(() => _.compact(this.accounts().map(item => (item ? item.email : null))));
|
2015-02-02 04:46:23 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.accountsUnreadCount = ko.computed(() => 0);
|
2017-06-25 03:26:27 +08:00
|
|
|
// this.accountsUnreadCount = ko.computed(() => {
|
|
|
|
// let result = 0;
|
2020-07-22 20:49:18 +08:00
|
|
|
// this.accounts().forEach(item => {
|
2017-06-25 03:26:27 +08:00
|
|
|
// if (item)
|
|
|
|
// {
|
|
|
|
// result += item.count();
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// return result;
|
|
|
|
// });
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-09-13 04:50:21 +08:00
|
|
|
export default new AccountUserStore();
|