2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2020-09-30 20:07:03 +08:00
|
|
|
import { MESSAGES_PER_PAGE_VALUES } from 'Common/Consts';
|
2020-08-14 04:58:41 +08:00
|
|
|
import { Layout, EditorDefaultType } from 'Common/Enums';
|
2019-07-05 03:19:24 +08:00
|
|
|
import { pInt } from 'Common/Utils';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
class SettingsUserStore {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
|
|
|
this.iAutoLogoutTimer = 0;
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
this.layout = ko
|
|
|
|
.observable(Layout.SidePreview)
|
|
|
|
.extend({ limitedList: [Layout.SidePreview, Layout.BottomPreview, Layout.NoPreview] });
|
|
|
|
|
|
|
|
this.editorDefaultType = ko.observable(EditorDefaultType.Html).extend({
|
|
|
|
limitedList: [
|
|
|
|
EditorDefaultType.Html,
|
|
|
|
EditorDefaultType.Plain,
|
|
|
|
EditorDefaultType.HtmlForced,
|
|
|
|
EditorDefaultType.PlainForced
|
|
|
|
]
|
|
|
|
});
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2020-09-30 20:07:03 +08:00
|
|
|
this.messagesPerPage = ko.observable(20).extend({ limitedList: MESSAGES_PER_PAGE_VALUES });
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2020-10-27 18:09:24 +08:00
|
|
|
ko.addObservablesTo(this, {
|
|
|
|
showImages: false,
|
|
|
|
useCheckboxesInList: true,
|
|
|
|
allowDraftAutosave: true,
|
|
|
|
useThreads: false,
|
|
|
|
replySameFolder: false,
|
|
|
|
|
|
|
|
autoLogout: 30
|
|
|
|
});
|
2016-08-17 06:01:20 +08:00
|
|
|
|
|
|
|
this.usePreviewPane = ko.computed(() => Layout.NoPreview !== this.layout());
|
2020-09-24 21:08:57 +08:00
|
|
|
|
|
|
|
this.subscribers();
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
subscribers() {
|
2020-08-27 21:45:47 +08:00
|
|
|
const htmlCL = document.documentElement.classList;
|
|
|
|
this.layout.subscribe(value => {
|
|
|
|
htmlCL.toggle('rl-no-preview-pane', Layout.NoPreview === value);
|
|
|
|
htmlCL.toggle('rl-side-preview-pane', Layout.SidePreview === value);
|
|
|
|
htmlCL.toggle('rl-bottom-preview-pane', Layout.BottomPreview === value);
|
2020-08-15 02:35:39 +08:00
|
|
|
dispatchEvent(new CustomEvent('rl-layout', {detail:value}));
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
populate() {
|
2020-09-04 18:05:17 +08:00
|
|
|
const settingsGet = rl.settings.get;
|
|
|
|
this.layout(pInt(settingsGet('Layout')));
|
|
|
|
this.editorDefaultType(settingsGet('EditorDefaultType'));
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2020-09-04 18:05:17 +08:00
|
|
|
this.autoLogout(pInt(settingsGet('AutoLogout')));
|
|
|
|
this.messagesPerPage(settingsGet('MPP'));
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2020-09-04 18:05:17 +08:00
|
|
|
this.showImages(!!settingsGet('ShowImages'));
|
|
|
|
this.useCheckboxesInList(!!settingsGet('UseCheckboxesInList'));
|
|
|
|
this.allowDraftAutosave(!!settingsGet('AllowDraftAutosave'));
|
|
|
|
this.useThreads(!!settingsGet('UseThreads'));
|
|
|
|
this.replySameFolder(!!settingsGet('ReplySameFolder'));
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2020-08-15 02:35:39 +08:00
|
|
|
const refresh = () => {
|
2020-08-12 06:25:36 +08:00
|
|
|
clearTimeout(this.iAutoLogoutTimer);
|
2020-09-04 18:05:17 +08:00
|
|
|
if (0 < this.autoLogout() && !settingsGet('AccountSignMe')) {
|
2020-08-15 02:35:39 +08:00
|
|
|
this.iAutoLogoutTimer = setTimeout(() =>
|
|
|
|
dispatchEvent(new CustomEvent('rl.auto-logout'))
|
|
|
|
, this.autoLogout() * 60000);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2020-08-15 02:35:39 +08:00
|
|
|
};
|
|
|
|
addEventListener('rl.auto-logout-refresh', refresh);
|
|
|
|
refresh();
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-09-13 04:50:21 +08:00
|
|
|
export default new SettingsUserStore();
|