Skip to content

Commit

Permalink
Step 6.15: Implement Meteor method for adding a new message
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Feb 13, 2017
1 parent 184b046 commit 9eba9e7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions api/server/methods.ts
@@ -0,0 +1,23 @@
import { Chats } from './collections/chats';
import { Messages } from './collections/messages';
import { MessageType } from './models';

Meteor.methods({
addMessage(type: MessageType, chatId: string, content: string) {
const chatExists = !!Chats.collection.find(chatId).count();

if (!chatExists) {
throw new Meteor.Error('chat-not-exists',
'Chat doesn\'t exist');
}

return {
messageId: Messages.collection.insert({
chatId: chatId,
content: content,
createdAt: new Date(),
type: type
})
};
}
});

1 comment on commit 9eba9e7

@trancaohuy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the tutorial, it said that this method will add messages to our messages collection and run on both client's local cache and server. I test this theory out by start both the ionic app and the meteor server. The messages get added to the collection perfectly. I then stop the meteor server to emulate the system offline and notice the call no longer work.
I guess my question is this tutorial supports offline database? If not, what do you recommend in achieving both meteor server and an offline database?

Please sign in to comment.