chat_page.js 824 B

12345678910111213141516171819202122232425262728
  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. other_user: function () {
  8. }
  9. });
  10. Template.chat_page.events({
  11. // this event fires when the user sends a message on the chat page
  12. "submit .js-send-chat": function (event) {
  13. // stop the form from triggering a page reload
  14. event.preventDefault();
  15. // see if we can find a chat object in the database
  16. // to which we'll add the message
  17. const chat = Chats.findOne({ _id: Session.get("chatId") });
  18. if (chat) {
  19. // OK - we have a chat to use.
  20. Meteor.call("chats.pushMessage", chat, event.target.chat.value);
  21. // reset the form
  22. event.target.chat.value = "";
  23. }
  24. }
  25. });