Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. app.service('messages').dispatch('eventname', (message, hook) => {
  2. // Just dispatch to one user
  3. if(message.isPrivate) {
  4. return app.channel(message.receiver_id);
  5. }
  6.  
  7. // Returning falsy or nothing will do nothing
  8. });
  9.  
  10. // Send to a certain room
  11. app.service('messages').dispatch('eventname', (message, hook) => {
  12. return app.channel(`rooms/${message.roomId}`);
  13. });
  14.  
  15. // EVERYONE
  16. app.service('messages').dispatch('eventname', (message, hook) => {
  17. return app.channel(app.channels);
  18. });
  19.  
  20. // Filter connections manually, e.g. if the connection user and message user are friends
  21. // This works similar to the old event filters
  22. app.service('messages').dispatch('eventname', (message, hook) => {
  23. return app.channel(app.channels).filter(connection => connection.user.friends.indexOf(message.user) !== -1);
  24. });
  25.  
  26. // Modify the data that are sent to the channel for that event
  27. app.service('messages').dispatch('eventname', (message, hook) => {
  28. const modifiedMessage = cloneAndModify(message);
  29.  
  30. return app.channel(`rooms/${message.roomId}`, `rooms/general`).send(modifiedMessage);
  31. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement