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';
|
2021-01-25 05:58:06 +08:00
|
|
|
import { Layout, EditorDefaultType } from 'Common/EnumsUser';
|
2019-07-05 03:19:24 +08:00
|
|
|
import { pInt } from 'Common/Utils';
|
2021-03-10 18:44:48 +08:00
|
|
|
import { $htmlCL, SettingsGet } from 'Common/Globals';
|
2021-02-17 03:12:23 +08:00
|
|
|
import { ThemeStore } from 'Stores/Theme';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
export const SettingsUserStore = new class {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
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,
|
2021-02-24 07:17:53 +08:00
|
|
|
removeColors: false,
|
2020-10-27 18:09:24 +08:00
|
|
|
useCheckboxesInList: true,
|
|
|
|
allowDraftAutosave: true,
|
|
|
|
useThreads: false,
|
|
|
|
replySameFolder: false,
|
|
|
|
|
|
|
|
autoLogout: 30
|
|
|
|
});
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-02-17 03:12:23 +08:00
|
|
|
this.usePreviewPane = ko.computed(() => Layout.NoPreview !== this.layout() && !ThemeStore.isMobile());
|
2020-09-24 21:08:57 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
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);
|
|
|
|
dispatchEvent(new CustomEvent('rl-layout', {detail:value}));
|
|
|
|
});
|
2021-03-03 00:39:02 +08:00
|
|
|
|
|
|
|
let iAutoLogoutTimer;
|
|
|
|
this.delayLogout = (() => {
|
|
|
|
clearTimeout(iAutoLogoutTimer);
|
2021-03-10 18:44:48 +08:00
|
|
|
if (0 < this.autoLogout() && !SettingsGet('AccountSignMe')) {
|
2021-03-03 00:39:02 +08:00
|
|
|
iAutoLogoutTimer = setTimeout(
|
|
|
|
rl.app.logout,
|
|
|
|
this.autoLogout() * 60000
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}).throttle(5000);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
populate() {
|
2021-03-10 18:44:48 +08:00
|
|
|
this.layout(pInt(SettingsGet('Layout')));
|
|
|
|
this.editorDefaultType(SettingsGet('EditorDefaultType'));
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-03-10 18:44:48 +08:00
|
|
|
this.autoLogout(pInt(SettingsGet('AutoLogout')));
|
|
|
|
this.messagesPerPage(SettingsGet('MPP'));
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-03-10 18:44:48 +08:00
|
|
|
this.showImages(!!SettingsGet('ShowImages'));
|
|
|
|
this.removeColors(!!SettingsGet('RemoveColors'));
|
|
|
|
this.useCheckboxesInList(!!(ThemeStore.isMobile() || SettingsGet('UseCheckboxesInList')));
|
|
|
|
this.allowDraftAutosave(!!SettingsGet('AllowDraftAutosave'));
|
|
|
|
this.useThreads(!!SettingsGet('UseThreads'));
|
|
|
|
this.replySameFolder(!!SettingsGet('ReplySameFolder'));
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-03-03 00:39:02 +08:00
|
|
|
this.delayLogout();
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2021-03-11 05:41:35 +08:00
|
|
|
};
|