snappymail/dev/Stores/User/Settings.js

105 lines
3.2 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
import { koComputable, addObservablesTo } from 'External/ko';
2016-06-30 08:02:45 +08:00
2022-09-26 17:55:26 +08:00
import { Layout } from 'Common/EnumsUser';
2022-02-17 16:36:29 +08:00
import { pInt } from 'Common/Utils';
2022-10-28 05:52:33 +08:00
import { $htmlCL, SettingsGet, fireEvent } from 'Common/Globals';
import { ThemeStore } from 'Stores/Theme';
2016-06-30 08:02:45 +08:00
export const SettingsUserStore = new class {
constructor() {
const self = this;
self.messagesPerPage = ko.observable(25).extend({ debounce: 999 });
self.messageReadDelay = ko.observable(5).extend({ debounce: 999 });
2021-09-02 20:21:50 +08:00
addObservablesTo(self, {
viewHTML: 1,
showImages: 0,
removeColors: 0,
listInlineAttachments: 0,
simpleAttachmentsList: 0,
useCheckboxesInList: 1,
2022-12-25 06:21:43 +08:00
listPerDay: 0,
allowDraftAutosave: 1,
useThreads: 0,
replySameFolder: 0,
hideUnsubscribed: 0,
hideDeleted: 1,
2022-09-27 15:46:49 +08:00
unhideKolabFolders: 0,
autoLogout: 0,
showUnreadCount: 0,
requestReadReceipt: 0,
requestDsn: 0,
pgpSign: 0,
2022-09-26 17:55:26 +08:00
pgpEncrypt: 0,
2022-11-15 19:12:01 +08:00
allowSpellcheck: 0,
2022-09-26 17:55:26 +08:00
layout: 1,
editorDefaultType: 'Html',
msgDefaultAction: 1
2020-10-27 18:09:24 +08:00
});
self.init();
self.usePreviewPane = koComputable(() => Layout.NoPreview !== self.layout() && !ThemeStore.isMobile());
const toggleLayout = () => {
const value = ThemeStore.isMobile() ? Layout.NoPreview : self.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);
fireEvent('rl-layout', value);
};
self.layout.subscribe(toggleLayout);
ThemeStore.isMobile.subscribe(toggleLayout);
toggleLayout();
let iAutoLogoutTimer;
self.delayLogout = (() => {
clearTimeout(iAutoLogoutTimer);
2022-10-27 22:05:28 +08:00
if (0 < self.autoLogout() && !SettingsGet('AccountSignMe')) {
iAutoLogoutTimer = setTimeout(
rl.app.logout,
self.autoLogout() * 60000
);
}
}).throttle(5000);
}
init() {
const self = this;
self.editorDefaultType(SettingsGet('EditorDefaultType'));
self.layout(pInt(SettingsGet('Layout')));
self.messagesPerPage(pInt(SettingsGet('MessagesPerPage')));
self.messageReadDelay(pInt(SettingsGet('MessageReadDelay')));
self.autoLogout(pInt(SettingsGet('AutoLogout')));
2022-08-31 23:31:08 +08:00
self.msgDefaultAction(SettingsGet('MsgDefaultAction'));
self.viewHTML(SettingsGet('ViewHTML'));
self.showImages(SettingsGet('ShowImages'));
self.removeColors(SettingsGet('RemoveColors'));
self.listInlineAttachments(SettingsGet('ListInlineAttachments'));
self.simpleAttachmentsList(SettingsGet('simpleAttachmentsList'));
self.useCheckboxesInList(SettingsGet('UseCheckboxesInList'));
2022-12-23 15:42:36 +08:00
self.listPerDay(SettingsGet('listPerDay'));
self.allowDraftAutosave(SettingsGet('AllowDraftAutosave'));
self.useThreads(SettingsGet('UseThreads'));
self.replySameFolder(SettingsGet('ReplySameFolder'));
self.hideUnsubscribed(SettingsGet('HideUnsubscribed'));
self.hideDeleted(SettingsGet('HideDeleted'));
self.showUnreadCount(SettingsGet('ShowUnreadCount'));
2022-09-27 15:46:49 +08:00
self.unhideKolabFolders(SettingsGet('UnhideKolabFolders'));
self.requestReadReceipt(SettingsGet('requestReadReceipt'));
self.requestDsn(SettingsGet('requestDsn'));
self.pgpSign(SettingsGet('pgpSign'));
self.pgpEncrypt(SettingsGet('pgpEncrypt'));
2022-11-15 19:12:01 +08:00
self.allowSpellcheck(SettingsGet('allowSpellcheck'));
}
};