Safety check for stream_data:[add|remove]_subscriber

Though this should not be common, getting a peer subscribed/
unsubscribed notification to a stream we don't yet know about should
not be fatal

(imported from commit ee28b163e0efc9adfad31e1b321e986dfe56271e)
This commit is contained in:
Leo Franchi 2013-09-10 17:13:02 -04:00
parent 0165dc54ad
commit f86c8255bb
1 changed files with 6 additions and 4 deletions

View File

@ -101,9 +101,10 @@ exports.get_name = function (stream_name) {
exports.add_subscriber = function (stream_name, user_email) {
var sub = exports.get_sub(stream_name);
if (!sub.subscribed) {
if (typeof sub === 'undefined' || !sub.subscribed) {
// If we're not subscribed, we don't track this, and shouldn't
// get these events.
// get these events. Likewise, if we don't know about the stream,
// we don't want to track this.
return;
}
sub.subscribers.set(user_email, true);
@ -111,9 +112,10 @@ exports.add_subscriber = function (stream_name, user_email) {
exports.remove_subscriber = function (stream_name, user_email) {
var sub = exports.get_sub(stream_name);
if (!sub.subscribed) {
if (typeof sub === 'undefined' || !sub.subscribed) {
// If we're not subscribed, we don't track this, and shouldn't
// get these events.
// get these events. Likewise, if we don't know about the stream,
// we don't want to track this.
return;
}
sub.subscribers.del(user_email);