chat_page.js 790 B

12345678910111213141516171819202122232425
  1. Template.chat_page.helpers({
  2. messages: function () {
  3. const chat = Chats.findOne({ _id: Session.get("chatId") });
  4. console.log("messages context", this, chat.messages);
  5. return chat.messages;
  6. }
  7. });
  8. Template.chat_page.events({
  9. // this event fires when the user sends a message on the chat page
  10. "submit .js-send-chat": function (event) {
  11. // stop the form from triggering a page reload
  12. event.preventDefault();
  13. // see if we can find a chat object in the database
  14. // to which we'll add the message
  15. const chat = Chats.findOne({ _id: Session.get("chatId") });
  16. if (chat) {
  17. // OK - we have a chat to use.
  18. Meteor.call("chats.pushMessage", chat, event.target.chat.value);
  19. // reset the form
  20. event.target.chat.value = "";
  21. }
  22. }
  23. });