Skip to content

Commit

Permalink
show confirmation dialog before setting large signature, closes #2573
Browse files Browse the repository at this point in the history
  • Loading branch information
vaf-hub authored and johnbotris committed Apr 30, 2021
1 parent 43069e2 commit c90e02d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
33 changes: 28 additions & 5 deletions src/settings/EditSignatureDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import m from "mithril"
import {assertMainOrNode} from "../api/common/Env"
import {Dialog, DialogType} from "../gui/base/Dialog"
import {lang} from "../misc/LanguageViewModel"
import {update} from "../api/main/Entity"
import {DropDownSelector} from "../gui/base/DropDownSelector"
import {EmailSignatureType, FeatureType} from "../api/common/TutanotaConstants"
import {logins} from "../api/main/LoginController"
Expand All @@ -14,9 +13,13 @@ import {insertInlineImageB64ClickHandler} from "../mail/view/MailViewerUtils"
import {PayloadTooLargeError} from "../api/common/error/RestError"
import {showProgressDialog} from "../gui/ProgressDialog"
import {neverNull} from "../api/common/utils/Utils"
import {locator} from "../api/main/MainLocator"

assertMainOrNode()

// signatures can become large, for example if they include a base64 embedded image. we ask for confirmation in such cases
const RECOMMENDED_SIGNATURE_SIZE_LIMIT = 15 * 1024

export function show(props: TutanotaProperties) {
import("../mail/signature/Signature").then(({getDefaultSignature}) => {
const defaultSignature = getDefaultSignature()
Expand Down Expand Up @@ -59,22 +62,42 @@ export function show(props: TutanotaProperties) {
const oldType = props.emailSignatureType
const oldCustomValue = props.customEmailSignature

if (newType === oldType && (newType !== EmailSignatureType.EMAIL_SIGNATURE_TYPE_CUSTOM || newCustomValue === oldCustomValue)) {
return dialog.close()
} else {
const updateSignature = () => {
props.emailSignatureType = newType
if (newType === EmailSignatureType.EMAIL_SIGNATURE_TYPE_CUSTOM) {
props.customEmailSignature = newCustomValue
}
const updatePromise = update(props)
const updatePromise = locator.entityClient.update(props)
return showProgressDialog("pleaseWait_msg", updatePromise)
.then(() => dialog.close())
.catch(PayloadTooLargeError, () => {
props.emailSignatureType = oldType
props.customEmailSignature = oldCustomValue
return Dialog.error("requestTooLarge_msg")
})
}

if (newType === oldType && (newType !== EmailSignatureType.EMAIL_SIGNATURE_TYPE_CUSTOM || newCustomValue === oldCustomValue)) {
return dialog.close()
} else {
if (newType === EmailSignatureType.EMAIL_SIGNATURE_TYPE_CUSTOM
&& newCustomValue.length > RECOMMENDED_SIGNATURE_SIZE_LIMIT) {
const signatureSizeKb = Math.floor(newCustomValue.length / 1024)
const confirmLargeSignatureAttrs = {
title: lang.get("userEmailSignature_label"),
child: {
view: () => m("p", lang.get("largeSignature_msg", {"{1}": signatureSizeKb}))
},
okAction: (dialog) => {
dialog.close()
updateSignature()
},
allowOkWithReturn: true,
}
Dialog.showActionDialog(confirmLargeSignatureAttrs)
} else {
updateSignature()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/translations/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,6 @@ export default {
"yourCalendars_label": "Your calendars",
"yourFolders_action": "YOUR FOLDERS",
"yourMessage_label": "Your message",
"you_label": "You"
"you_label": "You",
}
}

0 comments on commit c90e02d

Please sign in to comment.