<commit_before>const reqStrNotNull = Validators.and([
  Validators.required(),
  Validators.string(),
  Validators.notNull()
]);

Chatter.Message = ChatterMessage = Astro.Class({
  name: "ChatterMessage",
  collection: new Mongo.Collection("chattermessage"),

  fields: {
    userId: {
      type: "string"
    },

    roomId: {
      type: "string"
    },

    message: {
      type: "string"
    },

    nickname: {
      type: "string"
    },

    avatar: {
      type: "string"
    }
  },

  validators: {
    userId: [
      reqStrNotNull
    ],

    roomId: [
      reqStrNotNull
    ],

    message: [
      Validators.minLength(1, 'The message must not be empty!'),
      Validators.maxLength(1000),
      reqStrNotNull
    ]
  },

  events: {
    beforeSave: function(e) {
      increaseCounter(this);
      updateRoom(this.roomId);
    }
  },

  methods: {
    timeAgo: function () {
      return moment(this.get("createdAt")).fromNow();
    }
  },

  behaviors: ["timestamp"]
});


const increaseCounter = function(message) {
  const userRooms = Chatter.UserRoom.find({"roomId": message.roomId, "userId": {$nin:[message.userId]}}).fetch();
  const users = userRooms.map(function(userRoom) {
    Chatter.UserRoom.update({
      roomId : userRoom.roomId,
      userId: userRoom.userId
    },
    {<commit_msg>added some model methods to message model<commit_after>const reqStrNotNull = Validators.and([
  Validators.required(),
  Validators.string(),
  Validators.notNull()
]);

Chatter.Message = ChatterMessage = Astro.Class({
  name: "ChatterMessage",
  collection: new Mongo.Collection("chattermessage"),

  fields: {
    userId: {
      type: "string"
    },

    roomId: {
      type: "string"
    },

    message: {
      type: "string"
    },

    nickname: {
      type: "string"
    },

    avatar: {
      type: "string"
    }
  },

  validators: {
    userId: [
      reqStrNotNull
    ],

    roomId: [
      reqStrNotNull
    ],

    message: [
      Validators.minLength(1, 'The message must not be empty!'),
      Validators.maxLength(1000),
      reqStrNotNull
    ]
  },

  events: {
    beforeSave: function(e) {
      increaseCounter(this);
      updateRoom(this.roomId);
    }
  },

  methods: {
    timeAgo: function () {
      return moment(this.get("createdAt")).fromNow();
    },
    hoursAgo: function () {
      const now = moment(new Date());
      const then = this.get("createdAt");
      const duration = moment.duration(now.diff(then)).asHours();
      return duration;
    },
    timestamp: function () {
      return moment(this.get("createdAt")).format("MMMM Do, h:mm");
    }
  },

  behaviors: ["timestamp"]
});


const increaseCounter = function(message) {
  const userRooms = Chatter.UserRoom.find({"roomId": message.roomId, "userId": {$nin:[message.userId]}}).fetch();
  const users = userRooms.map(function(userRoom) {
    Chatter.UserRoom.update({
      roomId : userRoom.roomId,
      userId: userRoom.userId
    },
    {
{'fraction_non_alphanumeric': 0.148721399730821, 'fraction_numerical': 0.0033647375504710633, 'mean_word_length': 2.6344743276283618, 'pattern_counts': {'":': 4, '<': 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': '5151486', 'n_tokens_mistral': 989, 'n_tokens_neox': 973, 'n_words': 174}