<commit_before>insertMessage = function(user, room, messageStub, opts) {
    var options = _.defaults(opts || {}, {
        fromMobile: false,
    });

    // Create regular message
    var timestamp = new Date().getTime();
    var message = {
        authorId: user._id,
        roomId: room._id,
        timestamp: timestamp,
        type: "plain",
        message: messageStub.message,
        seenBy: [],
        likedBy: [],
        fromMobile:options.fromMobile
    };
    var messageId = Messages.insert(message);


    if (Meteor.isServer) {
        // Create content message
        var contentMessage = runContentProcessors(messageStub);
        if (contentMessage) {
            var richMessage = {
                authorId: user._id,
                roomId: room._id,<commit_msg>Add validation to insertMessage closed #113<commit_after>insertMessage = function (user, room, messageStub, opts) {
    check(user, Match.ObjectIncluding({_id: String, username: String}));
    check(room, Match.ObjectIncluding({_id: String, users: [String]}));
    check(messageStub, Match.ObjectIncluding({message: String}));

    if (room.isPrivate === true && !_.contains(room.invited, user._id)) {
        throw new Meteor.Error(401, "You must be invited to send a message to this room.");
    }

    var options = _.defaults(opts || {}, {
        fromMobile: false,
    });

    // Create regular message
    var timestamp = new Date().getTime();
    var message = {
        authorId: user._id,
        roomId: room._id,
        timestamp: timestamp,
        type: "plain",
        message: messageStub.message,
        seenBy: [],
        likedBy: [],
        fromMobile: options.fromMobile
    };
    var messageId = Messages.insert(message);


    if (Meteor.isServer) {
        // Create content message
        var contentMessage = runContentProcessors(messageStub);
        if (contentMessage) {
            var richMessage = {
                authorId: user._id,
                roomId: room._id,
{'fraction_non_alphanumeric': 0.11905952976488245, 'fraction_numerical': 0.0030015007503751876, 'mean_word_length': 2.316749585406302, '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': '63985', 'n_tokens_mistral': 563, 'n_tokens_neox': 548, 'n_words': 140}