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/protocols/matrix/shims | |
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/protocols/matrix/shims')
-rw-r--r-- | comm/chat/protocols/matrix/shims/empty.js | 16 | ||||
-rw-r--r-- | comm/chat/protocols/matrix/shims/loglevel.js | 73 | ||||
-rw-r--r-- | comm/chat/protocols/matrix/shims/moz.build | 14 | ||||
-rw-r--r-- | comm/chat/protocols/matrix/shims/safe-buffer.js | 48 | ||||
-rw-r--r-- | comm/chat/protocols/matrix/shims/uuid.js | 13 |
5 files changed, 164 insertions, 0 deletions
diff --git a/comm/chat/protocols/matrix/shims/empty.js b/comm/chat/protocols/matrix/shims/empty.js new file mode 100644 index 0000000000..ef18a9a5ac --- /dev/null +++ b/comm/chat/protocols/matrix/shims/empty.js @@ -0,0 +1,16 @@ +/* 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/. */ + +"use strict"; + +/* globals exports */ + +/* + * This module serves as a shim empty module for any empty ts type definition + * module one of the libraries might try to require. + */ + +Object.defineProperty(exports, "__esModule", { + value: true, +}); diff --git a/comm/chat/protocols/matrix/shims/loglevel.js b/comm/chat/protocols/matrix/shims/loglevel.js new file mode 100644 index 0000000000..9998435d40 --- /dev/null +++ b/comm/chat/protocols/matrix/shims/loglevel.js @@ -0,0 +1,73 @@ +/* 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/. */ + +"use strict"; + +/* globals scriptError, imIDebugMessage, module */ + +let _loggers = {}; + +/* + * Implement a custom logger to to hook the Matrix logging up to the chat + * logging framework. + * + * This unfortunately does not enable account specific logging. + */ +function getLogger(loggerName) { + let moduleName = "prpl-matrix." + loggerName; + + let logger = _loggers[moduleName]; + + // If the logger was previously created, return it. + if (logger) { + return logger; + } + + // Otherwise, build a new logger. + logger = {}; + logger.trace = scriptError.bind( + logger, + moduleName, + imIDebugMessage.LEVEL_DEBUG + ); + logger.debug = scriptError.bind( + logger, + moduleName, + imIDebugMessage.LEVEL_DEBUG + ); + logger.log = scriptError.bind( + logger, + moduleName, + imIDebugMessage.LEVEL_DEBUG + ); + logger.info = scriptError.bind(logger, moduleName, imIDebugMessage.LEVEL_LOG); + logger.warn = scriptError.bind( + logger, + moduleName, + imIDebugMessage.LEVEL_WARNING + ); + logger.error = scriptError.bind( + logger, + moduleName, + imIDebugMessage.LEVEL_ERROR + ); + + // This is a no-op since log levels are configured via preferences. + logger.setLevel = function (level) {}; + + _loggers[moduleName] = logger; + + return logger; +} + +module.exports = { + getLogger, + levels: { + TRACE: imIDebugMessage.LEVEL_DEBUG, + DEBUG: imIDebugMessage.LEVEL_DEBUG, + INFO: imIDebugMessage.LEVEL_LOG, + WARN: imIDebugMessage.LEVEL_WARNING, + ERROR: imIDebugMessage.LEVEL_ERROR, + }, +}; diff --git a/comm/chat/protocols/matrix/shims/moz.build b/comm/chat/protocols/matrix/shims/moz.build new file mode 100644 index 0000000000..522fade712 --- /dev/null +++ b/comm/chat/protocols/matrix/shims/moz.build @@ -0,0 +1,14 @@ +# vim: set filetype=python: +# 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/. + +# Shimmed dependencies of the matrix-js-sdk that we can provide through direct +# implementation instead of through npm packages. + +EXTRA_JS_MODULES.matrix += [ + "empty.js", + "loglevel.js", + "safe-buffer.js", + "uuid.js", +] diff --git a/comm/chat/protocols/matrix/shims/safe-buffer.js b/comm/chat/protocols/matrix/shims/safe-buffer.js new file mode 100644 index 0000000000..1bc806d24e --- /dev/null +++ b/comm/chat/protocols/matrix/shims/safe-buffer.js @@ -0,0 +1,48 @@ +/* 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/. */ + +"use strict"; + +/* globals module */ + +/* + * Per the Node.js documentation, a Buffer is an instance of Uint8Array, but + * additional class methods are missing for it. + * + * https://nodejs.org/docs/latest/api/buffer.html#buffer_buffers_and_typedarray + */ +class Buffer extends Uint8Array { + static isBuffer(obj) { + return obj instanceof Uint8Array; + } + + // Note that this doesn't fully implement allocate, only enough is implemented + // for the base-x package to function properly. + static alloc(size, fill, encoding) { + return new Buffer(size); + } + + static allocUnsafe(size) { + return new Buffer(size); + } + + // Add base 64 conversion support, used to safely transmit encrypted data. + static from(...args) { + if (args[1] === "base64") { + return super.from(atob(args[0]), character => character.charCodeAt(0)); + } + return super.from(...args); + } + + toString(target) { + if (target === "base64") { + return btoa(String.fromCharCode(...this.values())); + } + return super.toString(); + } +} + +module.exports = { + Buffer, +}; diff --git a/comm/chat/protocols/matrix/shims/uuid.js b/comm/chat/protocols/matrix/shims/uuid.js new file mode 100644 index 0000000000..ecdb036591 --- /dev/null +++ b/comm/chat/protocols/matrix/shims/uuid.js @@ -0,0 +1,13 @@ +/* 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/. */ + +"use strict"; + +/* globals module */ + +const v4 = () => crypto.randomUUID(); + +module.exports = { + v4, +}; |