Skip to content

Commit

Permalink
Step 5.26: Bind users to new messages
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB authored and Dotan Simha committed Nov 22, 2016
1 parent 6f4f878 commit 813100d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/server/methods.js
Expand Up @@ -4,12 +4,18 @@ import { Chats, Messages } from './collections';

Meteor.methods({
newMessage(message) {
if (!this.userId) {
throw new Meteor.Error('not-logged-in',
'Must be logged in to send message.');
}

check(message, {
text: String,
chatId: String
});

message.timestamp = new Date();
message.userId = this.userId;

const messageId = Messages.insert(message);
Chats.update(message.chatId, { $set: { lastMessage: message } });
Expand Down

0 comments on commit 813100d

Please sign in to comment.