Centralize current Folder checks to prevent bugs (which there were)

This commit is contained in:
the-djmaze 2022-09-07 23:39:46 +02:00
parent 0c90875b61
commit f451af2188
5 changed files with 46 additions and 80 deletions

View file

@ -6,6 +6,7 @@ import { MessageSetAction } from 'Common/EnumsUser';
import { $htmlCL } from 'Common/Globals'; import { $htmlCL } from 'Common/Globals';
import { arrayLength, pInt, pString } from 'Common/Utils'; import { arrayLength, pInt, pString } from 'Common/Utils';
import { addObservablesTo, addComputablesTo } from 'External/ko'; import { addObservablesTo, addComputablesTo } from 'External/ko';
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { import {
getFolderInboxName, getFolderInboxName,
@ -45,6 +46,7 @@ addObservablesTo(MessagelistUserStore, {
page: 1, page: 1,
pageBeforeThread: 1, pageBeforeThread: 1,
error: '', error: '',
// Folder: '',
endHash: '', endHash: '',
endThreadUid: 0, endThreadUid: 0,
@ -68,6 +70,28 @@ addComputablesTo(MessagelistUserStore, {
return value; return value;
}, },
isArchiveFolder: () => FolderUserStore.archiveFolder() === MessagelistUserStore().Folder,
isDraftFolder: () => FolderUserStore.draftsFolder() === MessagelistUserStore().Folder,
isSentFolder: () => FolderUserStore.sentFolder() === MessagelistUserStore().Folder,
isSpamFolder: () => FolderUserStore.spamFolder() === MessagelistUserStore().Folder,
isTrashFolder: () => FolderUserStore.trashFolder() === MessagelistUserStore().Folder,
archiveAllowed: () => ![UNUSED_OPTION_VALUE, MessagelistUserStore().Folder].includes(FolderUserStore.archiveFolder())
&& !MessagelistUserStore.isDraftFolder(),
spamAllowed: () => !(UNUSED_OPTION_VALUE === FolderUserStore.spamFolder()
// | MessagelistUserStore.isArchiveFolder()
| MessagelistUserStore.isSentFolder()
| MessagelistUserStore.isDraftFolder()),
isSpamAllowed: () => MessagelistUserStore.spamAllowed() && !MessagelistUserStore.isSpamFolder(),
isUnSpamAllowed: () => MessagelistUserStore.spamAllowed() && MessagelistUserStore.isSpamFolder(),
pageCount: () => Math.max(1, Math.ceil(MessagelistUserStore.count() / SettingsUserStore.messagesPerPage())), pageCount: () => Math.max(1, Math.ceil(MessagelistUserStore.count() / SettingsUserStore.messagesPerPage())),
mainSearch: { mainSearch: {

View file

@ -4,8 +4,6 @@ import { Scope } from 'Common/Enums';
import { ComposeType, FolderType, MessageSetAction } from 'Common/EnumsUser'; import { ComposeType, FolderType, MessageSetAction } from 'Common/EnumsUser';
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { doc, leftPanelDisabled, moveAction, import { doc, leftPanelDisabled, moveAction,
Settings, SettingsCapa, SettingsGet, Settings, SettingsCapa, SettingsGet,
addEventsListeners, addEventsListeners,
@ -70,6 +68,9 @@ export class MailMessageList extends AbstractViewRight {
this.allowDangerousActions = SettingsCapa('DangerousActions'); this.allowDangerousActions = SettingsCapa('DangerousActions');
this.messageList = MessagelistUserStore; this.messageList = MessagelistUserStore;
this.archiveAllowed = MessagelistUserStore.archiveAllowed;
this.isSpamAllowed = MessagelistUserStore.isSpamAllowed;
this.isUnSpamAllowed = MessagelistUserStore.isUnSpamAllowed;
this.composeInEdit = AppUserStore.composeInEdit; this.composeInEdit = AppUserStore.composeInEdit;
@ -135,25 +136,6 @@ export class MailMessageList extends AbstractViewRight {
return c && MessagelistUserStore().length > c; return c && MessagelistUserStore().length > c;
}, },
isSpamFolder: () => (FolderUserStore.spamFolder() || 0) === MessagelistUserStore().Folder,
isTrashFolder: () => (FolderUserStore.trashFolder() || 0) === MessagelistUserStore().Folder,
isDraftFolder: () => (FolderUserStore.draftsFolder() || 0) === MessagelistUserStore().Folder,
archiveAllowed: () =>
(FolderUserStore.archiveFolder() || 0) !== MessagelistUserStore().Folder
&& UNUSED_OPTION_VALUE !== FolderUserStore.archiveFolder()
&& !this.isDraftFolder(),
spamAllowed: () => UNUSED_OPTION_VALUE !== FolderUserStore.spamFolder()
&& (FolderUserStore.sentFolder() || 0) !== MessagelistUserStore().Folder
&& !this.isDraftFolder(),
isSpamVisible: () => !this.isSpamFolder() && this.spamAllowed(),
isUnSpamVisible: () => this.isSpamFolder() && this.spamAllowed(),
mobileCheckedStateShow: () => ThemeStore.isMobile() ? MessagelistUserStore.listChecked().length : 1, mobileCheckedStateShow: () => ThemeStore.isMobile() ? MessagelistUserStore.listChecked().length : 1,
mobileCheckedStateHide: () => ThemeStore.isMobile() ? !MessagelistUserStore.listChecked().length : 1, mobileCheckedStateHide: () => ThemeStore.isMobile() ? !MessagelistUserStore.listChecked().length : 1,
@ -596,7 +578,7 @@ export class MailMessageList extends AbstractViewRight {
!MessagelistUserStore.error() && !MessagelistUserStore.error() &&
!MessagelistUserStore.endThreadUid() && !MessagelistUserStore.endThreadUid() &&
MessagelistUserStore().length && MessagelistUserStore().length &&
(this.isSpamFolder() || this.isTrashFolder()) (MessagelistUserStore.isSpamFolder() || MessagelistUserStore.isTrashFolder())
); );
} }

View file

@ -1,7 +1,4 @@
import ko from 'ko'; import ko from 'ko';
import { koComputable } from 'External/ko';
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { Scope } from 'Common/Enums'; import { Scope } from 'Common/Enums';
@ -74,10 +71,10 @@ export class MailMessageView extends AbstractViewRight {
*/ */
createCommand = (fExecute, fCanExecute) => { createCommand = (fExecute, fCanExecute) => {
let fResult = () => { let fResult = () => {
fResult.canExecute() && fExecute.call(null); fCanExecute() && fExecute.call(null);
return false; return false;
}; };
fResult.canExecute = koComputable(() => fCanExecute()); fResult.canExecute = fCanExecute;
return fResult; return fResult;
}, },
@ -114,8 +111,13 @@ export class MailMessageView extends AbstractViewRight {
const attachmentsActions = Settings.app('attachmentsActions'); const attachmentsActions = Settings.app('attachmentsActions');
this.attachmentsActions = ko.observableArray(arrayLength(attachmentsActions) ? attachmentsActions : []); this.attachmentsActions = ko.observableArray(arrayLength(attachmentsActions) ? attachmentsActions : []);
this.message = MessageUserStore.message;
this.hasCheckedMessages = MessagelistUserStore.hasCheckedMessages; this.hasCheckedMessages = MessagelistUserStore.hasCheckedMessages;
this.isDraftFolder = MessagelistUserStore.isDraftFolder;
this.archiveAllowed = MessagelistUserStore.archiveAllowed;
this.isSpamAllowed = MessagelistUserStore.isSpamAllowed;
this.isUnSpamAllowed = MessagelistUserStore.isUnSpamAllowed;
this.message = MessageUserStore.message;
this.messageLoadingThrottle = MessageUserStore.loading; this.messageLoadingThrottle = MessageUserStore.loading;
this.messagesBodiesDom = MessageUserStore.bodiesDom; this.messagesBodiesDom = MessageUserStore.bodiesDom;
this.messageError = MessageUserStore.error; this.messageError = MessageUserStore.error;
@ -142,7 +144,7 @@ export class MailMessageView extends AbstractViewRight {
messageVisibility: () => !MessageUserStore.loading() && !!currentMessage(), messageVisibility: () => !MessageUserStore.loading() && !!currentMessage(),
canBeRepliedOrForwarded: () => !this.isDraftFolder() && this.messageVisibility(), canBeRepliedOrForwarded: () => !MessagelistUserStore.isDraftFolder() && this.messageVisibility(),
viewFromDkimVisibility: () => 'none' !== this.viewFromDkimData()[0], viewFromDkimVisibility: () => 'none' !== this.viewFromDkimData()[0],
@ -441,53 +443,11 @@ export class MailMessageView extends AbstractViewRight {
}); });
} }
/**
* @returns {boolean}
*/
isDraftFolder() {
return currentMessage() && FolderUserStore.draftsFolder() === currentMessage().folder;
}
/**
* @returns {boolean}
*/
isSentFolder() {
return currentMessage() && FolderUserStore.sentFolder() === currentMessage().folder;
}
/**
* @returns {boolean}
*/
isSpamFolder() {
return currentMessage() && FolderUserStore.spamFolder() === currentMessage().folder;
}
/**
* @returns {boolean}
*/
isSpamDisabled() {
return currentMessage() && FolderUserStore.spamFolder() === UNUSED_OPTION_VALUE;
}
/**
* @returns {boolean}
*/
isArchiveFolder() {
return currentMessage() && FolderUserStore.archiveFolder() === currentMessage().folder;
}
/**
* @returns {boolean}
*/
isArchiveDisabled() {
return currentMessage() && FolderUserStore.archiveFolder() === UNUSED_OPTION_VALUE;
}
/** /**
* @returns {boolean} * @returns {boolean}
*/ */
isDraftOrSentFolder() { isDraftOrSentFolder() {
return this.isDraftFolder() || this.isSentFolder(); return MessagelistUserStore.isDraftFolder() || MessagelistUserStore.isSentFolder();
} }
composeClick() { composeClick() {

View file

@ -31,8 +31,8 @@
<!-- /ko --> <!-- /ko -->
<div class="btn-group" data-bind="visible: mobileCheckedStateShow()"> <div class="btn-group" data-bind="visible: mobileCheckedStateShow()">
<a class="btn fontastic" data-bind="visible: archiveAllowed, command: archiveCommand" data-i18n="[title]GLOBAL/TO_ARCHIVE">🗄</a> <a class="btn fontastic" data-bind="visible: archiveAllowed, command: archiveCommand" data-i18n="[title]GLOBAL/TO_ARCHIVE">🗄</a>
<a class="btn fontastic" data-bind="visible: isSpamVisible, command: spamCommand" data-i18n="[title]GLOBAL/SPAM"></a> <a class="btn fontastic" data-bind="visible: isSpamAllowed, command: spamCommand" data-i18n="[title]GLOBAL/SPAM"></a>
<a class="btn" data-bind="visible: isUnSpamVisible, command: notSpamCommand" data-i18n="[title]GLOBAL/NOT_SPAM"> <a class="btn" data-bind="visible: isUnSpamAllowed, command: notSpamCommand" data-i18n="[title]GLOBAL/NOT_SPAM">
<i class="icon-check-mark-circle-two"></i> <i class="icon-check-mark-circle-two"></i>
</a> </a>
<a class="btn fontastic" data-bind="command: deleteCommand" data-i18n="[title]GLOBAL/DELETE">🗑</a> <a class="btn fontastic" data-bind="command: deleteCommand" data-i18n="[title]GLOBAL/DELETE">🗑</a>

View file

@ -8,9 +8,9 @@
<a class="btn btn-success buttonEdit fontastic" data-bind="command: messageEditCommand">🖉</a> <a class="btn btn-success buttonEdit fontastic" data-bind="command: messageEditCommand">🖉</a>
</div> </div>
<div class="btn-group"> <div class="btn-group">
<a class="btn fontastic" data-bind="visible: !isDraftFolder() && !isArchiveFolder() && !isArchiveDisabled(), command: archiveCommand" data-i18n="[title]GLOBAL/TO_ARCHIVE">🗄</a> <a class="btn fontastic" data-bind="visible: archiveAllowed, command: archiveCommand" data-i18n="[title]GLOBAL/TO_ARCHIVE">🗄</a>
<a class="btn fontastic" data-bind="visible: !isDraftFolder() && !isSentFolder() && !isSpamFolder() && !isSpamDisabled(), command: spamCommand" data-i18n="[title]GLOBAL/SPAM"></a> <a class="btn fontastic" data-bind="visible: isSpamAllowed , command: spamCommand" data-i18n="[title]GLOBAL/SPAM"></a>
<a class="btn" data-bind="visible: !isDraftFolder() && !isSentFolder() && isSpamFolder() && !isSpamDisabled(), command: notSpamCommand" data-i18n="[title]GLOBAL/NOT_SPAM"> <a class="btn" data-bind="visible: isUnSpamAllowed, command: notSpamCommand" data-i18n="[title]GLOBAL/NOT_SPAM">
<i class="icon-check-mark-circle-two"></i> <i class="icon-check-mark-circle-two"></i>
</a> </a>
<a class="btn fontastic" data-bind="command: deleteCommand" data-i18n="[title]GLOBAL/DELETE">🗑</a> <a class="btn fontastic" data-bind="command: deleteCommand" data-i18n="[title]GLOBAL/DELETE">🗑</a>
@ -65,13 +65,13 @@
</li> </li>
</div> </div>
<div class="dividerbar"> <div class="dividerbar">
<li role="presentation" data-bind="visible: !isDraftFolder() && !isArchiveFolder() && !isArchiveDisabled()"> <li role="presentation" data-bind="visible: archiveAllowed">
<a href="#" tabindex="-1" data-bind="command: archiveCommand" data-icon="🗄" data-i18n="GLOBAL/TO_ARCHIVE"></a> <a href="#" tabindex="-1" data-bind="command: archiveCommand" data-icon="🗄" data-i18n="GLOBAL/TO_ARCHIVE"></a>
</li> </li>
<li role="presentation" data-bind="visible: !isDraftFolder() && !isSentFolder() && !isSpamFolder() && !isSpamDisabled()"> <li role="presentation" data-bind="visible: isSpamAllowed">
<a href="#" tabindex="-1" data-bind="command: spamCommand" data-icon="⚠" data-i18n="GLOBAL/SPAM"></a> <a href="#" tabindex="-1" data-bind="command: spamCommand" data-icon="⚠" data-i18n="GLOBAL/SPAM"></a>
</li> </li>
<li role="presentation" data-bind="visible: !isDraftFolder() && !isSentFolder() && isSpamFolder() && !isSpamDisabled()"> <li role="presentation" data-bind="visible: isUnSpamAllowed">
<a href="#" tabindex="-1" data-bind="command: notSpamCommand"> <a href="#" tabindex="-1" data-bind="command: notSpamCommand">
<i class="icon-check-mark-circle-two"></i> <i class="icon-check-mark-circle-two"></i>
<span data-i18n="GLOBAL/NOT_SPAM"></span> <span data-i18n="GLOBAL/NOT_SPAM"></span>