<commit_before>Messages = new Meteor.Collection('messages'); // jshint ignore:line

Meteor.methods({
    'likeMessage': function (id) {
        Messages.update({_id: id}, {$addToSet: {likedBy: Meteor.userId()}});
    },
    'unlikeMessage': function (id) {
        Messages.update({_id: id}, {$pull: {likedBy: Meteor.userId()}});
    },
    'editMessage': function (editMessageStub) {
        var message = Messages.findOne({_id: editMessageStub._id});
        if (!message) {
            throw new Meteor.Error("Couldn't find message to edit.");
        }
        if (Meteor.userId() !== message.authorId) {
            throw new Meteor.Error("Can't edit a message you didn't author.");
        }
        Messages.update({_id: editMessageStub._id}, {
            $set: {
                message: editMessageStub.message,
                lastedited: new Date().getTime()
            }
        });
    },
    'removeMessage': function (id) {
        var message = Messages.findOne({_id: id});
        if (!message) {
            throw new Meteor.Error("Couldn't find message to edit.");
        }
        if (Meteor.userId() !== message.authorId) {
            throw new Meteor.Error("Can't remove a message you didn't author.");
        }
        Messages.remove({_id: id});
    },
    'message': function (messageStub) {
        var user = Meteor.user();
        var room = Rooms.findOne(messageStub.roomId);
        try {
            if (!user) {
                throw new Meteor.Error(401, "You need to login to send messages");
            }
            if (_s.isBlank(messageStub.message))
            {
                throw new Meteor.Error(401, "You must specify a message");
            }
            if (!room) {
                throw new Meteor.Error(401, "You must specify a valid room");
            }
            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.");
            }
<commit_msg>add checks and es6 style to messages collection<commit_after>Messages = new Meteor.Collection('messages'); // jshint ignore:line

Meteor.methods({
    likeMessage(id) {
        check(id, String);
        Messages.update({_id: id}, {$addToSet: {likedBy: Meteor.userId()}});
    },
    unlikeMessage(id) {
        check(id, String);
        Messages.update({_id: id}, {$pull: {likedBy: Meteor.userId()}});
    },
    editMessage(editMessageStub) {
        check(editMessageStub, {_id: String, message: String});
        var message = Messages.findOne({_id: editMessageStub._id});
        if (!message) {
            throw new Meteor.Error("Couldn't find message to edit.");
        }
        if (Meteor.userId() !== message.authorId) {
            throw new Meteor.Error("Can't edit a message you didn't author.");
        }
        Messages.update({_id: editMessageStub._id}, {
            $set: {
                message: editMessageStub.message,
                lastedited: new Date().getTime()
            }
        });
    },
    removeMessage(id) {
        check(id, String);
        var message = Messages.findOne({_id: id});
        if (!message) {
            throw new Meteor.Error("Couldn't find message to edit.");
        }
        if (Meteor.userId() !== message.authorId) {
            throw new Meteor.Error("Can't remove a message you didn't author.");
        }
        Messages.remove({_id: id});
    },
    message(messageStub) {
        check(messageStub, {message: String, roomId: String});
        var user = Meteor.user();
        var room = Rooms.findOne(messageStub.roomId);
        try {
            if (!user) {
                throw new Meteor.Error(401, "You need to login to send messages");
            }
            if (_s.isBlank(messageStub.message))
            {
                throw new Meteor.Error(401, "You must specify a message");
            }
            if (!room) {
                throw new Meteor.Error(401, "You must specify a valid room");
            }
            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.");
            }

{'fraction_non_alphanumeric': 0.13615912858157708, 'fraction_numerical': 0.005919962112242482, 'mean_word_length': 1.9497206703910615, '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': '5740292', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1200, 'n_words': 313}