Skip to content

Instantly share code, notes, and snippets.

@maxnowack
Last active February 22, 2018 09:39
Show Gist options
  • Save maxnowack/9ef59ab12c49699c861e7069a495a49a to your computer and use it in GitHub Desktop.
Save maxnowack/9ef59ab12c49699c861e7069a495a49a to your computer and use it in GitHub Desktop.
Monkeypatch for rocketchat:streamer until RocketChat/meteor-streamer#28 gets merged
import { Meteor } from 'meteor/meteor'
import { check, Match } from 'meteor/check'
// Monkeypatch publication function to add missing check.
// should be removed if RocketChat/meteor-streamer#28 gets merged
Meteor.Streamer.prototype.iniPublication = function iniPublication() {
const stream = this
Meteor.publish(this.subscriptionName, function publishStream(eventName, options) {
check(eventName, String)
check(options, Match.OneOf(Boolean, {
useCollection: Boolean,
args: Array,
}))
let { useCollection, args } = options
if (typeof options === 'boolean') {
useCollection = options
} else {
if (!options.useCollection) {
useCollection = false
}
if (!options.args) {
args = []
}
}
if (eventName.length === 0) {
this.stop()
return
}
if (stream.isReadAllowed(this, eventName, args) !== true) {
this.stop()
return
}
const subscription = {
subscription: this,
eventName,
}
stream.addSubscription(subscription, eventName)
this.onStop(() => {
stream.removeSubscription(subscription, eventName)
})
if (useCollection === true) {
// Collection compatibility
this._session.sendAdded(stream.subscriptionName, 'id', { // eslint-disable-line no-underscore-dangle
eventName,
})
}
this.ready()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment