message: Announce and leave DM rooms if not supported
diff: @@ -13,6 +13,9 @@ var BridgeRequest = require("../models/BridgeRequest");
  var toIrcLowerCase = require("../irc/formatting").toIrcLowerCase;
  var StateLookup = require('matrix-appservice-bridge').StateLookup;
  +const MSG_PMS_DISABLED = "[Bridge] Sorry, DMs are disabled on this bridge.";
  +const MSG_PMS_DISABLED_FEDERATION = "[Bridge] Sorry, DMs are disabled on this bridge over federation.";
  +
  function MatrixHandler(ircBridge) {
  this.ircBridge = ircBridge;
  // maintain a list of room IDs which are being processed invite-wise. This is
  @@ -83,10 +86,17 @@ MatrixHandler.prototype._handleInviteFromUser = Promise.coroutine(function*(req,
  invitedIrcUser) {
  req.log.info("Handling invite from user directed at %s on %s",
  invitedIrcUser.server.domain, invitedIrcUser.nick);
  + const intent = this.ircBridge.getAppServiceBridge().getIntent(invitedUser.getId());
  + const mxRoom = new MatrixRoom(event.room_id);
  // Real MX user inviting VMX to a matrix room for PM chat
  if (!invitedIrcUser.server.allowsPms()) {
  req.log.error("Rejecting invite: This server does not allow PMs.");
  + yield this.ircBridge.sendMatrixAction(mxRoom, invitedUser, new MatrixAction(
  + "notice",
  + MSG_PMS_DISABLED
  + ), req);
  + yield intent.leave(event.room_id);
  throw new Error("Server disallows PMs");
  }
  @@ -97,6 +107,11 @@ MatrixHandler.prototype._handleInviteFromUser = Promise.coroutine(function*(req,
  var localpart = event.user_id.match(/[^:]*:(.*)/)[1];
  if (localpart !== this.ircBridge.domain) {
  req.log.error("Rejecting invite: This server does not allow federated PMs.");
  + yield this.ircBridge.sendMatrixAction(mxRoom, invitedUser, new MatrixAction(
  + "notice",
  + MSG_PMS_DISABLED_FEDERATION
  + ), req);
  + yield intent.leave(event.room_id);
  throw new Error("Server disallows federated PMs");
  }
  else {
  @@ -107,16 +122,12 @@ MatrixHandler.prototype._handleInviteFromUser = Promise.coroutine(function*(req,
  req.log.info("(PM federation)Invite not rejected: federated PMs allowed");
  }
  - let mxRoom = new MatrixRoom(event.room_id);
  // create a virtual Matrix user for the IRC user
  let invitedUser = yield this.ircBridge.getMatrixUser(invitedIrcUser);
  - yield this.ircBridge.getAppServiceBridge().getIntent(invitedUser.getId()).join(
  - event.room_id
  - );
  + yield intent.join(event.room_id);
  req.log.info("Joined %s to room %s", invitedUser.getId(), event.room_id);
  // check if this room is a PM room or not.
  - let intent = this.ircBridge.getAppServiceBridge().getIntent(invitedUser.getId());
  let roomState = yield intent.roomState(event.room_id);
  let joinedMembers = roomState.filter((ev) => {
  return ev.type === "m.room.member" && ev.content.membership === "join";
  @@ -146,7 +157,7 @@ MatrixHandler.prototype._handleInviteFromUser = Promise.coroutine(function*(req,
  catch (err) {
  // ignore, we want to leave the room regardless.
  }
  - yield this.ircBridge.getAppServiceBridge().getIntent(invitedUser.getId()).leave(
  + yield intent.leave(
  event.room_id
  );
  });
  