diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/chat/content/otr-add-fingerprint.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/chat/content/otr-add-fingerprint.js')
-rw-r--r-- | comm/chat/content/otr-add-fingerprint.js | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/comm/chat/content/otr-add-fingerprint.js b/comm/chat/content/otr-add-fingerprint.js new file mode 100644 index 0000000000..fb6d6c037d --- /dev/null +++ b/comm/chat/content/otr-add-fingerprint.js @@ -0,0 +1,84 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +var { l10nHelper } = ChromeUtils.importESModule( + "resource:///modules/imXPCOMUtils.sys.mjs" +); +var { OTR } = ChromeUtils.importESModule("resource:///modules/OTR.sys.mjs"); + +window.addEventListener("DOMContentLoaded", () => { + otrAddFinger.onload(); +}); + +var otrAddFinger = { + onload() { + let args = window.arguments[0].wrappedJSObject; + + this.fingerWarning = document.getElementById("fingerWarning"); + this.fingerError = document.getElementById("fingerError"); + this.keyCount = document.getElementById("keyCount"); + + document.l10n.setAttributes( + document.getElementById("otrDescription"), + "otr-add-finger-description", + { + name: args.screenname, + } + ); + + document.addEventListener("dialogaccept", event => { + let hex = document.getElementById("fingerprint").value; + let context = OTR.getContextFromRecipient( + args.account, + args.protocol, + args.screenname + ); + let finger = OTR.addFingerprint(context, hex); + if (finger.isNull()) { + event.preventDefault(); + return; + } + try { + // Ignore the return, this is just a test. + OTR.getUIConvFromContext(context); + } catch (error) { + // We expect that a conversation may not have been started. + context = null; + } + OTR.setTrust(finger, true, context); + }); + }, + + addBlankSpace(value) { + return value + .replace(/\s/g, "") + .trim() + .replace(/(.{8})/g, "$1 ") + .trim(); + }, + + oninput(input) { + let hex = input.value.replace(/\s/g, ""); + + if (/[^0-9A-F]/gi.test(hex)) { + this.keyCount.hidden = true; + this.fingerWarning.hidden = false; + this.fingerError.hidden = false; + } else { + this.keyCount.hidden = false; + this.fingerWarning.hidden = true; + this.fingerError.hidden = true; + } + + document.querySelector("dialog").getButton("accept").disabled = + input.value && !input.validity.valid; + + this.keyCount.value = `${hex.length}/40`; + input.value = this.addBlankSpace(input.value); + }, + + onblur(input) { + input.value = this.addBlankSpace(input.value); + }, +}; |