2019-07-05 03:19:24 +08:00
|
|
|
import { AbstractModel } from 'Knoin/AbstractModel';
|
2022-10-31 05:19:52 +08:00
|
|
|
import { addObservablesTo } from 'External/ko';
|
2022-12-08 00:36:04 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2022-12-22 17:01:25 +08:00
|
|
|
import { SettingsUserStore } from 'Stores/User/Settings';
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2021-01-22 23:32:08 +08:00
|
|
|
export class AccountModel extends AbstractModel {
|
2016-07-07 05:03:30 +08:00
|
|
|
/**
|
|
|
|
* @param {string} email
|
|
|
|
* @param {boolean=} canBeDelete = true
|
|
|
|
* @param {number=} count = 0
|
|
|
|
*/
|
2022-12-08 00:36:04 +08:00
|
|
|
constructor(email, name, isAdditional = true) {
|
2020-10-19 01:19:45 +08:00
|
|
|
super();
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2022-11-09 00:40:12 +08:00
|
|
|
this.name = name;
|
2016-07-07 05:03:30 +08:00
|
|
|
this.email = email;
|
|
|
|
|
2022-11-09 00:40:12 +08:00
|
|
|
this.displayName = name ? name + ' <' + email + '>' : email;
|
|
|
|
|
2022-10-31 05:19:52 +08:00
|
|
|
addObservablesTo(this, {
|
2022-12-08 00:36:04 +08:00
|
|
|
unreadEmails: null,
|
2022-01-28 06:07:34 +08:00
|
|
|
askDelete: false,
|
2021-11-15 17:56:52 +08:00
|
|
|
isAdditional: isAdditional
|
2020-10-25 18:46:58 +08:00
|
|
|
});
|
2022-12-08 00:36:04 +08:00
|
|
|
|
|
|
|
// Load at random between 3 and 30 seconds
|
2022-12-22 17:01:25 +08:00
|
|
|
SettingsUserStore.showUnreadCount() && isAdditional
|
|
|
|
&& setTimeout(()=>this.fetchUnread(), (Math.ceil(Math.random() * 10)) * 3000);
|
2022-12-08 00:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get INBOX unread messages
|
|
|
|
*/
|
|
|
|
fetchUnread() {
|
|
|
|
Remote.request('AccountUnread', (iError, oData) => {
|
|
|
|
iError || this.unreadEmails(oData?.Result?.unreadEmails || null);
|
|
|
|
}, {
|
|
|
|
email: this.email
|
|
|
|
});
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
2022-12-07 19:24:31 +08:00
|
|
|
/**
|
|
|
|
* Imports all mail to main account
|
|
|
|
*//*
|
|
|
|
importAll(account) {
|
2022-12-08 00:36:04 +08:00
|
|
|
Remote.streamPerLine(line => {
|
2022-12-07 19:24:31 +08:00
|
|
|
try {
|
|
|
|
line = JSON.parse(line);
|
|
|
|
console.dir(line);
|
|
|
|
} catch (e) {
|
|
|
|
// OOPS
|
|
|
|
}
|
|
|
|
}, 'AccountImport', {
|
|
|
|
Action: 'AccountImport',
|
|
|
|
email: account.email
|
|
|
|
});
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|