message: Allow users to opt out of being mentioned
diff: @@ -83,6 +83,9 @@ function IrcHandler(ircBridge, config) {
  }
  );
  + // One of ["on", "off", "force-off"]
  + this._mentionMode = config.mapIrcMentionsToMatrix || "on";
  +
  this.getMetrics();
  }
  @@ -515,21 +518,40 @@ IrcHandler.prototype.onMessage = Promise.coroutine(function*(req, server, fromUs
  return;
  }
  - let mapping;
  + let mapping = null;
  if (this.nickUserIdMapCache.has(`${server.domain}:${channel}`)) {
  mapping = this.nickUserIdMapCache.get(`${server.domain}:${channel}`);
  }
  - else {
  + else if (this._mentionMode !== "force-off") {
  + // Some users want to opt out of being mentioned.
  mapping = this.ircBridge.getClientPool().getNickUserIdMappingForChannel(
  - server, channel
  + server, channel, this._mentionMode
  );
  + const store = this._ircBridge.getStore();
  + const nicks = Object.keys(mapping);
  +
  + for (let nick in nicks) {
  + const userId = mapping[nick];
  + const feature = (yield store.getUserFeatures(userId)).mentions;
  + const disabled = feature === true ||
  + (feature === undefined && this._mentionMode === "on");
  + if (disabled) {
  + delete mapping[nick];
  + }
  + }
  this.nickUserIdMapCache.set(`${server.domain}:${channel}`, mapping);
  if (this.nickUserIdMapCache.size > NICK_USERID_CACHE_MAX) {
  this.nickUserIdMapCache.delete(this.nickUserIdMapCache.keys()[0]);
  }
  }
  - yield mxAction.formatMentions(mapping, this.ircBridge.getAppServiceBridge().getIntent());
  + if (mapping !== null) {
  + yield mxAction.formatMentions(
  + mapping,
  + this.ircBridge.getAppServiceBridge().getIntent(),
  + this._mentionMode === "on"
  + );
  + }
  const nickKey = server.domain + " " + fromUser.nick;
  let virtualMatrixUser;
  