Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 6.15: Implement Meteor method for adding a new message
- Loading branch information
1 parent
184b046
commit 9eba9e7
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}) | ||
}; | ||
} | ||
}); |
9eba9e7
There was a problem hiding this comment.
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?