Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.service('messages').dispatch('eventname', (message, hook) => {
- // Just dispatch to one user
- if(message.isPrivate) {
- return app.channel(message.receiver_id);
- }
- // Returning falsy or nothing will do nothing
- });
- // Send to a certain room
- app.service('messages').dispatch('eventname', (message, hook) => {
- return app.channel(`rooms/${message.roomId}`);
- });
- // EVERYONE
- app.service('messages').dispatch('eventname', (message, hook) => {
- return app.channel(app.channels);
- });
- // Filter connections manually, e.g. if the connection user and message user are friends
- // This works similar to the old event filters
- app.service('messages').dispatch('eventname', (message, hook) => {
- return app.channel(app.channels).filter(connection => connection.user.friends.indexOf(message.user) !== -1);
- });
- // Modify the data that are sent to the channel for that event
- app.service('messages').dispatch('eventname', (message, hook) => {
- const modifiedMessage = cloneAndModify(message);
- return app.channel(`rooms/${message.roomId}`, `rooms/general`).send(modifiedMessage);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement