function checkAndDeactivateRoom(room) {
  // Getting most recent event for this room
  return dbEvent.findOne({
    where: { roomId: room.id },
    order: [['createdAt', 'DESC']],
  })
  .then((evt) => {
    if (evt) {
      // Time in minutes since any activity in this room
      const minsSinceLastEvent =
        moment().diff(moment(evt.createdAt), 'minutes');
      if (minsSinceLastEvent > conf.minRoomDeactivationAge) {
        // If a sync is defined we need to create an action
        if (room.settings && room.settings.sync) {
          room.settings.sync.forEach((bot) => {
            if (bot.botId && bot.botAction) {
              const syncBotAction = {
                name: bot.botAction,
                botId: bot.botId,
                roomId: room.id,
                isPending: true,
                parameters: [],
              };

              dbBotAction.create(syncBotAction);
            }
          });
        }

        return room.update({ active: false })
        .then(() => {
          const message = 'Room automatically deactivated due to ' +
            `${conf.minRoomDeactivationAge} minutes of inactivity.`;
          const eventType = {
            type: 'RoomState',
            active: false,
          };
          const deactivateEvent = {
            log: message,
            context: eventType,
            roomId: room.id,
          };

          return dbEvent.create(deactivateEvent);
        });
      }
    }
  });
}
/**
 * Deactivates a room if there has not been any recent activity in the room.
 * If a sync is defined in the settings of the room, it creates an action.
 *
 * @param {Object} room - Active room.
 * @returns {Promise} - Promise that room was deactivated.
 */
Deactivates a room if there has not been any recent activity in the room.
If a sync is defined in the settings of the room, it creates an action.

@param {Object} room - Active room.
@returns {Promise} - Promise that room was deactivated.
Deactivates a room if there has not been any recent activity in the room . If a sync is defined in the settings of the room it creates an action . @param { Object } room - Active room . @returns { Promise } - Promise that room was deactivated .
function checkAndDeactivateRoom(room) {
  return dbEvent.findOne({
    where: { roomId: room.id },
    order: [['createdAt', 'DESC']],
  })
  .then((evt) => {
    if (evt) {
      const minsSinceLastEvent =
        moment().diff(moment(evt.createdAt), 'minutes');
      if (minsSinceLastEvent > conf.minRoomDeactivationAge) {
        if (room.settings && room.settings.sync) {
          room.settings.sync.forEach((bot) => {
            if (bot.botId && bot.botAction) {
              const syncBotAction = {
                name: bot.botAction,
                botId: bot.botId,
                roomId: room.id,
                isPending: true,
                parameters: [],
              };
              dbBotAction.create(syncBotAction);
            }
          });
        }
        return room.update({ active: false })
        .then(() => {
          const message = 'Room automatically deactivated due to ' +
            `${conf.minRoomDeactivationAge} minutes of inactivity.`;
          const eventType = {
            type: 'RoomState',
            active: false,
          };
          const deactivateEvent = {
            log: message,
            context: eventType,
            roomId: room.id,
          };
          return dbEvent.create(deactivateEvent);
        });
      }
    }
  });
}
function checkAndDeactivateRoom ( room ) { return dbEvent . findOne ( { where : { roomId : room . id } , order : [ [ 'createdAt' , 'DESC' ] ] , } ) . then ( ( evt ) => { if ( evt ) { const minsSinceLastEvent = moment ( ) . diff ( moment ( evt . createdAt ) , 'minutes' ) ; if ( minsSinceLastEvent > conf . minRoomDeactivationAge ) { if ( room . settings && room . settings . sync ) { room . settings . sync . forEach ( ( bot ) => { if ( bot . botId && bot . botAction ) { const syncBotAction = { name : bot . botAction , botId : bot . botId , roomId : room . id , isPending : true , parameters : [ ] , } ; dbBotAction . create ( syncBotAction ) ; } } ) ; } return room . update ( { active : false } ) . then ( ( ) => { const message = 'Room automatically deactivated due to ' + ` ${ conf . minRoomDeactivationAge } ` ; const eventType = { type : 'RoomState' , active : false , } ; const deactivateEvent = { log : message , context : eventType , roomId : room . id , } ; return dbEvent . create ( deactivateEvent ) ; } ) ; } } } ) ; }
Deactivates a room if there has not been any recent activity in the room.
Deactivates a room if there has not been any recent activity in the room .
// Getting most recent event for this room // Time in minutes since any activity in this room // If a sync is defined we need to create an action