summaryrefslogtreecommitdiffstats
path: root/comm/chat/protocols/irc/ircEchoMessage.sys.mjs
blob: 24a27be9026f30aa05d5e42b269e718c3ffe5d12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* 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/. */

/*
 * This implements the echo-message capability for IRC.
 *   https://ircv3.net/specs/extensions/echo-message-3.2
 *
 * When enabled, displaying of a sent messages is disabled (until it is received
 * by the server and sent back to the sender). This helps to ensure the ordering
 * of messages is consistent for all participants in a channel and also helps
 * signify whether a message was properly sent to a channel during disconnect.
 */

import { ircHandlerPriorities } from "resource:///modules/ircHandlerPriorities.sys.mjs";

export var capEchoMessage = {
  name: "echo-message CAP",
  priority: ircHandlerPriorities.DEFAULT_PRIORITY,
  isEnabled: () => true,

  commands: {
    "echo-message": function (aMessage) {
      if (
        aMessage.cap.subcommand === "LS" ||
        aMessage.cap.subcommand === "NEW"
      ) {
        this.addCAP("echo-message");
        this.sendMessage("CAP", ["REQ", "echo-message"]);
      } else if (
        aMessage.cap.subcommand === "ACK" ||
        aMessage.cap.subcommand === "NAK"
      ) {
        this.removeCAP("echo-message");
      } else {
        return false;
      }
      return true;
    },
  },
};