{"action":"created","issue":{"url":"https://api.github.com/repos/feathersjs/feathers/issues/904","repository_url":"https://api.github.com/repos/feathersjs/feathers","labels_url":"https://api.github.com/repos/feathersjs/feathers/issues/904/labels{/name}","comments_url":"https://api.github.com/repos/feathersjs/feathers/issues/904/comments","events_url":"https://api.github.com/repos/feathersjs/feathers/issues/904/events","html_url":"https://github.com/feathersjs/feathers/issues/904","id":338266233,"node_id":"MDU6SXNzdWUzMzgyNjYyMzM=","number":904,"title":"channel unsubscribe","user":{"login":"GlauberF","id":11314585,"node_id":"MDQ6VXNlcjExMzE0NTg1","avatar_url":"https://avatars3.githubusercontent.com/u/11314585?v=4","gravatar_id":"","url":"https://api.github.com/users/GlauberF","html_url":"https://github.com/GlauberF","followers_url":"https://api.github.com/users/GlauberF/followers","following_url":"https://api.github.com/users/GlauberF/following{/other_user}","gists_url":"https://api.github.com/users/GlauberF/gists{/gist_id}","starred_url":"https://api.github.com/users/GlauberF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GlauberF/subscriptions","organizations_url":"https://api.github.com/users/GlauberF/orgs","repos_url":"https://api.github.com/users/GlauberF/repos","events_url":"https://api.github.com/users/GlauberF/events{/privacy}","received_events_url":"https://api.github.com/users/GlauberF/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-04T12:58:40Z","updated_at":"2018-07-04T15:59:39Z","closed_at":null,"author_association":"NONE","body":"### problem\r\ntoday every time the user creates / changes a new data in the database, it is also notified.\r\n\r\nI need that for the user who changed or created the data in the database, it is not notified with the events (updated, created).\r\n\r\nps: the user is not authenticated, because these channels are public\r\n\r\n### file channel\r\n\r\n```javascript\r\nmodule.exports = function(app) {\r\n  if(typeof app.channel !== 'function') {\r\n    return;\r\n  }\r\n\r\n  app.on('connection', connection => {\r\n    console.loog('\\n\\n\\n connection', connection)\r\n    app.channel('anonymous').join(connection);\r\n  });\r\n\r\n  app.on('login', (authResult, { connection }) => {\r\n    if(connection) {\r\n      app.channel('anonymous').leave(connection);\r\n\r\n      app.channel('authenticated').join(connection);\r\n    }\r\n  });\r\n\r\n  app.publish((data, hook) => { // eslint-disable-line no-unused-vars\r\n    console.log('Publishing all events to all authenticated users. See `channels.js` and https://docs.feathersjs.com/api/channels.html for more information.'); // eslint-disable-line\r\n\r\n    return app.channel('authenticated', 'anonymous');\r\n  });\r\n};\r\n```\r\n\r\n### file service (task)\r\n\r\n```javascript\r\n// Initializes the `task` service on path `/task`\r\nconst createService = require('feathers-mongoose');\r\nconst createModel = require('../../models/task.model');\r\nconst hooks = require('./task.hooks');\r\n\r\nmodule.exports = function (app) {\r\n  const Model = createModel(app);\r\n  const paginate = app.get('paginate');\r\n\r\n  const options = {\r\n    name: 'task',\r\n    Model,\r\n    paginate\r\n  };\r\n\r\n  // Initialize our service with any options it requires\r\n  app.use('/task', createService(options));\r\n\r\n  // Get our initialized service so that we can register hooks and filters\r\n  const service = app.service('task');\r\n\r\n  service.hooks(hooks);\r\n};\r\n```\r\n\r\nas I have no logged in user, must have an identifier (id) on the connection, maybe pick up that identifier and remove it from the notification\r\n\r\nif you can help me, set an example above my need. will be of great help"},"comment":{"url":"https://api.github.com/repos/feathersjs/feathers/issues/comments/402516597","html_url":"https://github.com/feathersjs/feathers/issues/904#issuecomment-402516597","issue_url":"https://api.github.com/repos/feathersjs/feathers/issues/904","id":402516597,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMjUxNjU5Nw==","user":{"login":"GlauberF","id":11314585,"node_id":"MDQ6VXNlcjExMzE0NTg1","avatar_url":"https://avatars3.githubusercontent.com/u/11314585?v=4","gravatar_id":"","url":"https://api.github.com/users/GlauberF","html_url":"https://github.com/GlauberF","followers_url":"https://api.github.com/users/GlauberF/followers","following_url":"https://api.github.com/users/GlauberF/following{/other_user}","gists_url":"https://api.github.com/users/GlauberF/gists{/gist_id}","starred_url":"https://api.github.com/users/GlauberF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GlauberF/subscriptions","organizations_url":"https://api.github.com/users/GlauberF/orgs","repos_url":"https://api.github.com/users/GlauberF/repos","events_url":"https://api.github.com/users/GlauberF/events{/privacy}","received_events_url":"https://api.github.com/users/GlauberF/received_events","type":"User","site_admin":false},"created_at":"2018-07-04T15:59:39Z","updated_at":"2018-07-04T15:59:39Z","author_association":"NONE","body":"\r\n\r\n![captura de tela de 2018-07-04 13-07-22](https://user-images.githubusercontent.com/11314585/42286650-04436b18-7f8a-11e8-9a8d-961bdefa354a.png)\r\n\r\n\r\n```javascript\r\nmodule.exports = function(app) {\r\n  if(typeof app.channel !== 'function') {\r\n    // If no real-time functionality has been configured just return\r\n    return;\r\n  }\r\n\r\n  app.on('connection', connection => {\r\n    // On a new real-time connection, add it to the anonymous channel\r\n    app.channel('anonymous').join(connection);\r\n  });\r\n\r\n  app.on('login', (authResult, { connection }) => {\r\n    // connection can be undefined if there is no\r\n    // real-time connection, e.g. when logging in via REST\r\n    if(connection) {\r\n      // Obtain the logged in user from the connection\r\n      // const user = connection.user;\r\n      \r\n      // The connection is no longer anonymous, remove it\r\n      app.channel('anonymous').leave(connection);\r\n\r\n      // Add it to the authenticated user channel\r\n      app.channel('authenticated').join(connection);\r\n\r\n      // Channels can be named anything and joined on any condition \r\n      \r\n      // E.g. to send real-time events only to admins use\r\n      // if(user.isAdmin) { app.channel('admins').join(connection); }\r\n\r\n      // If the user has joined e.g. chat rooms\r\n      // if(Array.isArray(user.rooms)) user.rooms.forEach(room => app.channel(`rooms/${room.id}`).join(channel));\r\n      \r\n      // Easily organize users by email and userid for things like messaging\r\n      // app.channel(`emails/${user.email}`).join(channel);\r\n      // app.channel(`userIds/$(user.id}`).join(channel);\r\n    }\r\n  });\r\n\r\n  app.publish((data, hook) => { // eslint-disable-line no-unused-vars\r\n    // Here you can add event publishers to channels set up in `channels.js`\r\n    // To publish only for a specific event use `app.publish(eventname, () => {})`\r\n\r\n    console.log('Publishing all events to all authenticated users. See `channels.js` and https://docs.feathersjs.com/api/channels.html for more information.'); // eslint-disable-line\r\n\r\n    // e.g. to publish all service events to all authenticated users use\r\n    // return app.channel('authenticated', 'anonymous'); //padrao\r\n\r\n    // inicio - nova implementação\r\n    // evita que quem gerou o novo dado, receba os eventos do tipo (created, eupdated etc...)\r\n    return app.channel('authenticated', 'anonymous')\r\n      .filter(connection => connection.user._id !== hook.params.user._id);\r\n    // final - nova implementação\r\n\r\n  });\r\n\r\n  // Here you can also add service specific event publishers\r\n  // e..g the publish the `users` service `created` event to the `admins` channel\r\n  // app.service('users').publish('created', () => app.channel('admins'));\r\n  \r\n  // With the userid and email organization from above you can easily select involved users\r\n  // app.service('messages').publish(() => {\r\n  //   return [\r\n  //     app.channel(`userIds/${data.createdBy}`),\r\n  //     app.channel(`emails/${data.recipientEmail}`)\r\n  //   ];\r\n  // });\r\n};\r\n```"}}
{"actor":{"display_login":"GlauberF"}}