Skip to content

Commit

Permalink
Bugfix: on login loading the user settings failed
Browse files Browse the repository at this point in the history
  • Loading branch information
djmaze committed Nov 19, 2021
1 parent 3895b72 commit e614524
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 41 deletions.
2 changes: 2 additions & 0 deletions dev/App/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,8 @@ class AppUser extends AbstractApp {

AccountUserStore.email(SettingsGet('Email'));

SettingsUserStore.init();

this.foldersReload(value => {
try {
if (value) {
Expand Down
63 changes: 43 additions & 20 deletions dev/Stores/User/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import { ThemeStore } from 'Stores/Theme';

export const SettingsUserStore = new class {
constructor() {
this.layout = ko
.observable(pInt(SettingsGet('Layout')))
const self = this;

self.layout = ko
.observable(1)
.extend({ limitedList: Object.values(Layout) });

this.editorDefaultType = ko.observable(SettingsGet('EditorDefaultType')).extend({
self.editorDefaultType = ko.observable('Html').extend({
limitedList: [
EditorDefaultType.Html,
EditorDefaultType.Plain,
Expand All @@ -20,43 +22,64 @@ export const SettingsUserStore = new class {
]
});

this.messagesPerPage = ko.observable(pInt(SettingsGet('MPP'))).extend({ debounce: 999 });
self.messagesPerPage = ko.observable(25).extend({ debounce: 999 });

this.messageReadDelay = ko.observable(pInt(SettingsGet('MessageReadDelay'))).extend({ debounce: 999 });
self.messageReadDelay = ko.observable(5).extend({ debounce: 999 });

addObservablesTo(this, {
showImages: !!SettingsGet('ShowImages'),
removeColors: !!SettingsGet('RemoveColors'),
useCheckboxesInList: !!(ThemeStore.isMobile() || SettingsGet('UseCheckboxesInList')),
allowDraftAutosave: !!SettingsGet('AllowDraftAutosave'),
useThreads: !!SettingsGet('UseThreads'),
replySameFolder: !!SettingsGet('ReplySameFolder'),
hideUnsubscribed: Settings.app('useImapSubscribe') && SettingsGet('HideUnsubscribed'),
autoLogout: pInt(SettingsGet('AutoLogout'))
addObservablesTo(self, {
showImages: 0,
removeColors: 0,
useCheckboxesInList: 1,
allowDraftAutosave: 1,
useThreads: 0,
replySameFolder: 0,
hideUnsubscribed: 1,
autoLogout: 0
});

this.usePreviewPane = ko.computed(() => Layout.NoPreview !== this.layout() && !ThemeStore.isMobile());
self.init();

self.usePreviewPane = ko.computed(() => Layout.NoPreview !== self.layout() && !ThemeStore.isMobile());

const toggleLayout = () => {
const value = ThemeStore.isMobile() ? Layout.NoPreview : this.layout();
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);
dispatchEvent(new CustomEvent('rl-layout', {detail:value}));
};
this.layout.subscribe(toggleLayout);
self.layout.subscribe(toggleLayout);
ThemeStore.isMobile.subscribe(toggleLayout);
toggleLayout();

let iAutoLogoutTimer;
this.delayLogout = (() => {
self.delayLogout = (() => {
clearTimeout(iAutoLogoutTimer);
if (0 < this.autoLogout() && !SettingsGet('AccountSignMe')) {
if (0 < self.autoLogout() && !SettingsGet('AccountSignMe')) {
iAutoLogoutTimer = setTimeout(
rl.app.logout,
this.autoLogout() * 60000
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')));

self.showImages(!!SettingsGet('ShowImages'));
self.removeColors(!!SettingsGet('RemoveColors'));
self.useCheckboxesInList(!!SettingsGet('UseCheckboxesInList'));
self.allowDraftAutosave(!!SettingsGet('AllowDraftAutosave'));
self.useThreads(!!SettingsGet('UseThreads'));
self.replySameFolder(!!SettingsGet('ReplySameFolder'));

self.hideUnsubscribed(Settings.app('useImapSubscribe') && SettingsGet('HideUnsubscribed'));
}
};
14 changes: 8 additions & 6 deletions dev/Styles/User/Contacts.less
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@
font-size: 24px;
line-height: 30px;
}

&.hideContactListCheckbox {
.checkboxItem {
visibility: hidden;
}
}
}

.e-contact-item {
Expand Down Expand Up @@ -263,3 +257,11 @@
}
}
}

html:not(rl-mobile) {
.hideContactListCheckbox {
.checkboxItem {
visibility: hidden;
}
}
}
16 changes: 10 additions & 6 deletions dev/Styles/User/MessageList.less
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ html.rl-no-preview-pane {
}
}

.hideMessageListCheckbox {
.checkboxCheckAll {
visibility: hidden;
}
html:not(rl-mobile) {
.hideMessageListCheckbox {
.checkboxCheckAll {
visibility: hidden;
}

.checkboxMessage {
display: none;
.checkboxMessage {
display: none;
}
}
}

Expand Down Expand Up @@ -416,7 +418,9 @@ html.rl-ctrl-key-pressed .messageListItem {
order: 3;
}
}
}

.rl-side-preview-pane {
.messageList:not(.hideMessageListCheckbox) .subjectParent {
margin-left: 30px;
}
Expand Down
4 changes: 2 additions & 2 deletions snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ public function AppData(bool $bAdmin): array
// user
'ShowImages' => (bool) $oConfig->Get('defaults', 'show_images', false),
'RemoveColors' => (bool) $oConfig->Get('defaults', 'remove_colors', false),
'MPP' => (int) $oConfig->Get('webmail', 'messages_per_page', 25),
'MessagesPerPage' => (int) $oConfig->Get('webmail', 'messages_per_page', 25),
'MessageReadDelay' => (int) $oConfig->Get('webmail', 'message_read_delay', 5),
'SoundNotification' => true,
'NotificationSound' => 'new-mail',
Expand Down Expand Up @@ -975,7 +975,7 @@ public function AppData(bool $bAdmin): array
$aResult['ShowImages'] = (bool)$oSettings->GetConf('ShowImages', $aResult['ShowImages']);
$aResult['RemoveColors'] = (bool)$oSettings->GetConf('RemoveColors', $aResult['RemoveColors']);
$aResult['ContactsAutosave'] = (bool)$oSettings->GetConf('ContactsAutosave', $aResult['ContactsAutosave']);
$aResult['MPP'] = (int)$oSettings->GetConf('MPP', $aResult['MPP']);
$aResult['MessagesPerPage'] = (int)$oSettings->GetConf('MPP', $aResult['MessagesPerPage']);
$aResult['MessageReadDelay'] = (int)$oSettings->GetConf('MessageReadDelay', $aResult['MessageReadDelay']);
$aResult['SoundNotification'] = (bool)$oSettings->GetConf('SoundNotification', $aResult['SoundNotification']);
$aResult['NotificationSound'] = (string)$oSettings->GetConf('NotificationSound', $aResult['NotificationSound']);
Expand Down
15 changes: 8 additions & 7 deletions snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public function DoSettingsUpdate() : array
}

$this->setSettingsFromParams($oSettings, 'MPP', 'int', function ($iValue) {
return (int) (\in_array($iValue, array(10, 20, 30, 50, 100, 150, 200, 300)) ? $iValue : 20);
return \min(50, \max(10, $iValue));
});

$this->setSettingsFromParams($oSettings, 'Layout', 'int', function ($iValue) {
Expand Down Expand Up @@ -548,7 +548,7 @@ private function getMimeFileByHash(\RainLoop\Model\Account $oAccount, string $sH
return $aValues;
}

private function setSettingsFromParams(\RainLoop\Settings $oSettings, string $sConfigName, string $sType = 'string', ?callable $mStringCallback = null) : void
private function setSettingsFromParams(\RainLoop\Settings $oSettings, string $sConfigName, string $sType = 'string', ?callable $cCallback = null) : void
{
if ($this->HasActionParam($sConfigName))
{
Expand All @@ -558,21 +558,22 @@ private function setSettingsFromParams(\RainLoop\Settings $oSettings, string $sC
default:
case 'string':
$sValue = (string) $sValue;
if ($mStringCallback && is_callable($mStringCallback))
{
$sValue = $mStringCallback($sValue);
if ($cCallback) {
$sValue = $cCallback($sValue);
}

$oSettings->SetConf($sConfigName, (string) $sValue);
break;

case 'int':
$iValue = (int) $sValue;
if ($cCallback) {
$sValue = $cCallback($iValue);
}
$oSettings->SetConf($sConfigName, $iValue);
break;

case 'bool':
$oSettings->SetConf($sConfigName, '1' === (string) $sValue);
$oSettings->SetConf($sConfigName, !empty($sValue));
break;
}
}
Expand Down

0 comments on commit e614524

Please sign in to comment.