From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- comm/chat/protocols/jsTest/jsTestProtocol.sys.mjs | 145 ++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 comm/chat/protocols/jsTest/jsTestProtocol.sys.mjs (limited to 'comm/chat/protocols/jsTest/jsTestProtocol.sys.mjs') 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); + }, +}; -- cgit v1.2.3