<commit_before>const Api = new Restivus({
  useDefaultAuth: true,
  apiPath: 'api/lg/',
  prettyJson: true,
  enableCors: false,
})

function errorResponse(error, statusCode = 500) {
  return {
    statusCode,
    body: {
      status: 'fail',
      message: `${error.name}::${error.message}`
    },
  }
}

function successResponse(data, statusCode = 200) {
  return {
    statusCode,
    body: Object.assign({}, {
      status: 'success',
    }, data)
  }
}

const validRoomName = new RegExp('^[0-9a-zA-Z-_.]+$', 'i')

Api.addRoute('rooms', {authRequired: true}, {
  post() {
    try {
      const {
        userId,
        bodyParams: {
          name,
          topic,
          members,
        },
      } = this
      if (!RocketChat.authz.hasPermission(userId, 'create-c')) {
        throw new Meteor.Error('insufficient-permissions', 'you do not have permission to do this')
      }
      if (!validRoomName.test(name)) {
        throw new Meteor.Error('invalid-room-name', `${name} is not a valid room name`)
      }
      /* eslint-disable prefer-arrow-callback */
      const result = Meteor.runAsUser(userId, function () {
        const {rid} = Meteor.call('createChannel', name, members)
        RocketChat.saveRoomTopic(rid, topic)
        return {
          status: 'success',
          room: {
            rid,
            name,
            topic,
            members,
          },
        }
      })<commit_msg>RocketChat.saveRoomTopic takes a user as a thrid argument now.<commit_after>const Api = new Restivus({
  useDefaultAuth: true,
  apiPath: 'api/lg/',
  prettyJson: true,
  enableCors: false,
})

function errorResponse(error, statusCode = 500) {
  return {
    statusCode,
    body: {
      status: 'fail',
      message: `${error.name}::${error.message}`
    },
  }
}

function successResponse(data, statusCode = 200) {
  return {
    statusCode,
    body: Object.assign({}, {
      status: 'success',
    }, data)
  }
}

const validRoomName = new RegExp('^[0-9a-zA-Z-_.]+$', 'i')

Api.addRoute('rooms', {authRequired: true}, {
  post() {
    try {
      const {
        userId,
        bodyParams: {
          name,
          topic,
          members,
        },
      } = this
      if (!RocketChat.authz.hasPermission(userId, 'create-c')) {
        throw new Meteor.Error('insufficient-permissions', 'you do not have permission to do this')
      }
      if (!validRoomName.test(name)) {
        throw new Meteor.Error('invalid-room-name', `${name} is not a valid room name`)
      }
      /* eslint-disable prefer-arrow-callback */
      const result = Meteor.runAsUser(userId, function () {
        const {rid} = Meteor.call('createChannel', name, members)
        const user = RocketChat.models.Users.findOneById(userId)
        RocketChat.saveRoomTopic(rid, topic, user)
        return {
          status: 'success',
          room: {
            rid,
            name,
            topic,
            members,
          },
        }
      })
{'fraction_non_alphanumeric': 0.13954270342972427, 'fraction_numerical': 0.005379959650302623, 'mean_word_length': 2.0957336108220606, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5623110', 'n_tokens_mistral': 945, 'n_tokens_neox': 937, 'n_words': 208}