Use events insted of observers for streams

pull/3483/merge
Rodrigo Nascimento 10 years ago
parent 3b7729e465
commit 6fe7bc4e23
No known key found for this signature in database
GPG Key ID: 2C85B3AFE75D23F9
  1. 23
      packages/rocketchat-authorization/server/publications/permissions.js
  2. 2
      packages/rocketchat-lib/client/lib/cachedCollection.js
  3. 24
      packages/rocketchat-lib/server/publications/settings.coffee
  4. 53
      server/publications/subscription.coffee

@ -7,25 +7,10 @@ Meteor.methods({
});
let subscriptionsReady = false;
RocketChat.models.Settings.findNotHidden().observe({
added(record) {
if (subscriptionsReady) {
RocketChat.Notifications.notifyAll('permissions-changed', 'added', record);
}
},
RocketChat.models.Permissions.on('change', (type, ...args) => {
const records = RocketChat.models.Permissions.getChangedRecords(type, args[0]);
changed(record) {
if (subscriptionsReady) {
RocketChat.Notifications.notifyAll('permissions-changed', 'changed', record);
}
},
removed(record) {
if (subscriptionsReady) {
RocketChat.Notifications.notifyAll('permissions-changed', 'removed', { _id: record._id });
}
for (const record of records) {
RocketChat.Notifications.notifyAll('permissions-changed', type, record);
}
});
subscriptionsReady = true;

@ -82,7 +82,7 @@ class CachedCollection {
setupListener(eventType, eventName) {
RocketChat.Notifications[eventType || this.eventType](eventName || this.eventName, (t, record) => {
if (t === 'removed') {
if (t === 'remove') {
this.collection.remove(record._id);
} else {
const _id = record._id;

@ -16,24 +16,12 @@ Meteor.methods
return RocketChat.models.Settings.findNotHidden().fetch()
subscriptionsReady = false
RocketChat.models.Settings.findNotHidden().observe
added: (record) ->
if subscriptionsReady
e = if record.public is true then 'public-settings-changed' else 'private-settings-changed'
RocketChat.Notifications.notifyAll e, 'added', record
changed: (record) ->
if subscriptionsReady
e = if record.public is true then 'public-settings-changed' else 'private-settings-changed'
RocketChat.Notifications.notifyAll e, 'changed', record
removed: (record) ->
if subscriptionsReady
e = if record.public is true then 'public-settings-changed' else 'private-settings-changed'
RocketChat.Notifications.notifyAll e, 'removed', { _id: record._id }
subscriptionsReady = true
RocketChat.models.Settings.on 'change', (type, args...) ->
records = RocketChat.models.Settings.getChangedRecords type, args[0]
for record in records
e = if record.public is true then 'public-settings-changed' else 'private-settings-changed'
RocketChat.Notifications.notifyAll e, type, record
RocketChat.Notifications.streamAll.allowRead 'private-settings-changed', ->

@ -1,3 +1,22 @@
fields =
t: 1
ts: 1
ls: 1
name: 1
rid: 1
code: 1
f: 1
u: 1
open: 1
alert: 1
roles: 1
unread: 1
archived: 1
desktopNotifications: 1
mobilePushNotifications: 1
emailNotifications: 1
Meteor.methods
subscriptions: ->
unless Meteor.userId()
@ -6,37 +25,13 @@ Meteor.methods
this.unblock()
options =
fields:
t: 1
ts: 1
ls: 1
name: 1
rid: 1
code: 1
f: 1
open: 1
alert: 1
roles: 1
unread: 1
archived: 1
desktopNotifications: 1
mobilePushNotifications: 1
emailNotifications: 1
fields: fields
return RocketChat.models.Subscriptions.findByUserId(Meteor.userId(), options).fetch()
subscriptionsReady = false
RocketChat.models.Subscriptions.find().observe
added: (record) ->
if subscriptionsReady
RocketChat.Notifications.notifyUser record.u._id, 'subscription-change', 'added', record
changed: (record) ->
if subscriptionsReady
RocketChat.Notifications.notifyUser record.u._id, 'subscription-change', 'changed', record
removed: (record) ->
if subscriptionsReady
RocketChat.Notifications.notifyUser record.u._id, 'subscription-change', 'removed', {_id: record._id}
RocketChat.models.Subscriptions.on 'change', (type, args...) ->
records = RocketChat.models.Subscriptions.getChangedRecords type, args[0], fields
subscriptionsReady = true
for record in records
RocketChat.Notifications.notifyUser record.u._id, 'subscription-change', type, record

Loading…
Cancel
Save