message: Refresh the member list and remove old ghosts on room upgrade
diff: @@ -101,6 +101,10 @@ function IrcBridge(config, registration) {
  }
  },
  roomLinkValidation,
  + roomUpgradeOpts: {
  + consumeEvent: true,
  + onRoomMigrated: this._onRoomUpgrade.bind(this),
  + }
  });
  this._timers = null; // lazy map of Histogram instances used as metrics
  @@ -990,6 +994,7 @@ IrcBridge.prototype.getBotClient = function(server) {
  return this._clientPool.getBot(server);
  });
  }
  +
  IrcBridge.prototype._fetchJoinedRooms = Promise.coroutine(function*() {
  /** Fetching joined rooms is quicker on larger homeservers than trying to
  * /join each room in the mappings list. To ensure we start quicker,
  @@ -1016,6 +1021,36 @@ IrcBridge.prototype._fetchJoinedRooms = Promise.coroutine(function*() {
  }
  });
  +IrcBridge.prototype._onRoomUpgrade = Promise.coroutine(function*(oldRoomId, newRoomId) {
  + // Get the channels for the room_id
  + const rooms = yield this.getStore().getIrcChannelsForRoomId(newRoomId);
  + // Get users who we wish to leave.
  + const asBot = this._ircBridge.getAppServiceBridge().getBot();
  + const stateEvents = yield asBot.getClient().roomState(roomId);
  + const roomInfo = asBot._getRoomInfo(roomId, {
  + state: {
  + events: stateEvents
  + }
  + });
  + yield Promise.all(rooms.map((room) => {
  + return this.getBotClient(room.getServer()).then((bot) => {
  + // This will invoke NAMES and make members join the new room,
  + // so we don't need to await it.
  + bot.getNicks(room.getChannel()).catch(() => {
  + log.error("Failed to get nicks for upgraded room");
  + });
  + req.log.info(
  + `Leaving ${roomInfo.remoteJoinedUsers.length} users from old room ${oldRoomId}.`
  + );
  + this.memberListSyncers[room.getServer().domain].addToLeavePool(
  + roomInfo.remoteJoinedUsers,
  + oldRoomId,
  + room
  + );
  + })
  + }))
  +});
  +
  IrcBridge.DEFAULT_LOCALPART = "appservice-irc";
  module.exports = IrcBridge;
  