12345678910111213141516171819202122232425 |
- Template.chat_page.helpers({
- messages: function () {
- const chat = Chats.findOne({ _id: Session.get("chatId") });
- console.log("messages context", this, chat.messages);
- return chat.messages;
- }
- });
- Template.chat_page.events({
- // this event fires when the user sends a message on the chat page
- "submit .js-send-chat": function (event) {
- // stop the form from triggering a page reload
- event.preventDefault();
- // see if we can find a chat object in the database
- // to which we'll add the message
- const chat = Chats.findOne({ _id: Session.get("chatId") });
- if (chat) {
- // OK - we have a chat to use.
- Meteor.call("chats.pushMessage", chat, event.target.chat.value);
- // reset the form
- event.target.chat.value = "";
- }
- }
- });
|