snappymail/dev/Stores/User/Settings.js

63 lines
2.2 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2016-06-30 08:02:45 +08:00
2021-01-25 05:58:06 +08:00
import { Layout, EditorDefaultType } from 'Common/EnumsUser';
import { pInt, addObservablesTo } from 'Common/Utils';
2021-03-10 18:44:48 +08:00
import { $htmlCL, SettingsGet } from 'Common/Globals';
import { ThemeStore } from 'Stores/Theme';
2016-06-30 08:02:45 +08:00
export const SettingsUserStore = new class {
constructor() {
2019-07-05 03:19:24 +08:00
this.layout = ko
2021-03-18 23:12:24 +08:00
.observable(pInt(SettingsGet('Layout')))
.extend({ limitedList: Object.values(Layout) });
2019-07-05 03:19:24 +08:00
2021-03-18 23:12:24 +08:00
this.editorDefaultType = ko.observable(SettingsGet('EditorDefaultType')).extend({
2019-07-05 03:19:24 +08:00
limitedList: [
EditorDefaultType.Html,
EditorDefaultType.Plain,
EditorDefaultType.HtmlForced,
EditorDefaultType.PlainForced
]
});
2021-09-10 15:30:06 +08:00
this.messagesPerPage = ko.observable(pInt(SettingsGet('MPP'))).extend({ debounce: 999 });
2021-09-10 15:30:06 +08:00
this.messageReadDelay = ko.observable(pInt(SettingsGet('MessageReadDelay'))).extend({ debounce: 999 });
2021-09-02 20:21:50 +08:00
addObservablesTo(this, {
2021-03-18 23:12:24 +08:00
showImages: !!SettingsGet('ShowImages'),
removeColors: !!SettingsGet('RemoveColors'),
useCheckboxesInList: !!(ThemeStore.isMobile() || SettingsGet('UseCheckboxesInList')),
allowDraftAutosave: !!SettingsGet('AllowDraftAutosave'),
useThreads: !!SettingsGet('UseThreads'),
replySameFolder: !!SettingsGet('ReplySameFolder'),
2021-03-29 18:08:52 +08:00
hideUnsubscribed: !!SettingsGet('HideUnsubscribed'),
2021-03-18 23:12:24 +08:00
autoLogout: pInt(SettingsGet('AutoLogout'))
2020-10-27 18:09:24 +08:00
});
this.usePreviewPane = ko.computed(() => Layout.NoPreview !== this.layout() && !ThemeStore.isMobile());
const toggleLayout = () => {
const value = ThemeStore.isMobile() ? Layout.NoPreview : this.layout();
$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}));
};
this.layout.subscribe(toggleLayout);
ThemeStore.isMobile.subscribe(toggleLayout);
toggleLayout();
let iAutoLogoutTimer;
this.delayLogout = (() => {
clearTimeout(iAutoLogoutTimer);
2021-03-10 18:44:48 +08:00
if (0 < this.autoLogout() && !SettingsGet('AccountSignMe')) {
iAutoLogoutTimer = setTimeout(
rl.app.logout,
this.autoLogout() * 60000
);
}
}).throttle(5000);
}
};