diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
commit | 9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/chat/protocols/jsTest | |
parent | Initial commit. (diff) | |
download | thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.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/jsTest')
-rw-r--r-- | comm/chat/protocols/jsTest/components.conf | 15 | ||||
-rw-r--r-- | comm/chat/protocols/jsTest/jsTestProtocol.sys.mjs | 145 | ||||
-rw-r--r-- | comm/chat/protocols/jsTest/moz.build | 13 |
3 files changed, 173 insertions, 0 deletions
diff --git a/comm/chat/protocols/jsTest/components.conf b/comm/chat/protocols/jsTest/components.conf new file mode 100644 index 0000000000..ae73392491 --- /dev/null +++ b/comm/chat/protocols/jsTest/components.conf @@ -0,0 +1,15 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# 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/. + +Classes = [ + { + 'cid': '{a0774c5a-4aea-458b-9fbc-8d3cbf1a4630}', + 'contract_ids': ['@mozilla.org/chat/jstest;1'], + 'esModule': 'resource:///modules/jsTestProtocol.sys.mjs', + 'constructor': 'JSTestProtocol', + 'categories': {'im-protocol-plugin': 'prpl-jstest'}, + }, +] diff --git a/comm/chat/protocols/jsTest/jsTestProtocol.sys.mjs b/comm/chat/protocols/jsTest/jsTestProtocol.sys.mjs new file mode 100644 index 0000000000..52f749ca92 --- /dev/null +++ b/comm/chat/protocols/jsTest/jsTestProtocol.sys.mjs @@ -0,0 +1,145 @@ +/* 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/. */ + +import { setTimeout } from "resource://gre/modules/Timer.sys.mjs"; +import { + GenericAccountPrototype, + GenericConvIMPrototype, + GenericProtocolPrototype, +} from "resource:///modules/jsProtoHelper.sys.mjs"; + +function Conversation(aAccount) { + this._init(aAccount); +} +Conversation.prototype = { + __proto__: GenericConvIMPrototype, + _disconnected: false, + _setDisconnected() { + this._disconnected = true; + }, + close() { + if (!this._disconnected) { + this.account.disconnect(true); + } + }, + dispatchMessage(aMsg) { + if (this._disconnected) { + this.writeMessage( + "jstest", + "This message could not be sent because the conversation is no longer active: " + + aMsg, + { system: true, error: true } + ); + return; + } + + this.writeMessage("You", aMsg, { outgoing: true }); + this.writeMessage("/dev/null", "Thanks! I appreciate your attention.", { + incoming: true, + autoResponse: true, + }); + }, + + get name() { + return "/dev/null"; + }, +}; + +function Account(aProtoInstance, aImAccount) { + this._init(aProtoInstance, aImAccount); +} +Account.prototype = { + __proto__: GenericAccountPrototype, + connect() { + this.reportConnecting(); + // do something here + this.reportConnected(); + setTimeout( + function () { + this._conv = new Conversation(this); + this._conv.writeMessage("jstest", "You are now talking to /dev/null", { + system: true, + }); + }.bind(this), + 0 + ); + }, + _conv: null, + disconnect(aSilent) { + this.reportDisconnecting(Ci.prplIAccount.NO_ERROR, ""); + if (!aSilent) { + this._conv.writeMessage("jstest", "You have disconnected.", { + system: true, + }); + } + if (this._conv) { + this._conv._setDisconnected(); + delete this._conv; + } + this.reportDisconnected(); + }, + + get canJoinChat() { + return true; + }, + chatRoomFields: { + channel: { label: "_Channel Field", required: true }, + channelDefault: { label: "_Field with default", default: "Default Value" }, + password: { + label: "_Password Field", + default: "", + isPassword: true, + required: false, + }, + sampleIntField: { + label: "_Int Field", + default: 4, + min: 0, + max: 10, + required: true, + }, + }, + + // Nothing to do. + unInit() {}, + remove() {}, +}; + +export function JSTestProtocol() {} +JSTestProtocol.prototype = { + __proto__: GenericProtocolPrototype, + get id() { + return "prpl-jstest"; + }, + get normalizedName() { + return "jstest"; + }, + get name() { + return "JS Test"; + }, + options: { + text: { label: "Text option", default: "foo" }, + bool: { label: "Boolean option", default: true }, + int: { label: "Integer option", default: 42 }, + list: { + label: "Select option", + default: "option2", + listValues: { + option1: "First option", + option2: "Default option", + option3: "Other option", + }, + }, + }, + usernameSplits: [ + { + label: "Server", + separator: "@", + defaultValue: "default.server", + }, + ], + getAccount(aImAccount) { + return new Account(this, aImAccount); + }, +}; diff --git a/comm/chat/protocols/jsTest/moz.build b/comm/chat/protocols/jsTest/moz.build new file mode 100644 index 0000000000..87f7a792ed --- /dev/null +++ b/comm/chat/protocols/jsTest/moz.build @@ -0,0 +1,13 @@ +# 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/. + +if CONFIG["MOZ_DEBUG"]: + EXTRA_JS_MODULES += [ + "jsTestProtocol.sys.mjs", + ] + + XPCOM_MANIFESTS += [ + "components.conf", + ] |