Add blueslip warnings to stream_data functions.

Warn inside these functions when you get data on streams that you
are not subscribed to:

  add_subscriber
  remove_subscriber
  user_is_subscribed

The back end should be smart enough not to spam us with subscriber
info that we don't care about.

(imported from commit b27644be2abc37c11ddff884ef392ea208bd1bd3)
This commit is contained in:
Steve Howell
2013-09-16 10:56:46 -04:00
parent 3c69a6dd26
commit c6a9297f1a
2 changed files with 6 additions and 0 deletions

View File

@@ -113,6 +113,7 @@ exports.add_subscriber = function (stream_name, user_email) {
// If we're not subscribed, we don't track this, and shouldn't
// get these events. Likewise, if we don't know about the stream,
// we don't want to track this.
blueslip.warning("We got an add_subscriber call for a non-existent or unsubscribed stream.");
return;
}
sub.subscribers.set(user_email, true);
@@ -124,6 +125,7 @@ exports.remove_subscriber = function (stream_name, user_email) {
// If we're not subscribed, we don't track this, and shouldn't
// get these events. Likewise, if we don't know about the stream,
// we don't want to track this.
blueslip.warning("We got a remove_subscriber call for a non-existent or unsubscribed stream.");
return;
}
sub.subscribers.del(user_email);
@@ -135,6 +137,7 @@ exports.user_is_subscribed = function (stream_name, user_email) {
// If we don't know about the stream, or we ourselves are not
// subscribed, we can't keep track of the subscriber list in general,
// so we return undefined (treated as falsy if not explicitly handled).
blueslip.warning("We got a user_is_subscribed call for a non-existent or unsubscribed stream.");
return undefined;
}
return sub.subscribers.has(user_email);

View File

@@ -6,6 +6,8 @@ add_dependencies({
stream_color: 'js/stream_color.js'
});
set_global('blueslip', {});
var stream_data = require('js/stream_data.js');
(function test_basics() {
@@ -102,6 +104,7 @@ var stream_data = require('js/stream_data.js');
// Verify that we noop and don't crash when unsubsribed.
sub.subscribed = false;
global.blueslip.warning = function () {};
stream_data.add_subscriber('Rome', email);
assert.equal(stream_data.user_is_subscribed('Rome', email), undefined);
stream_data.remove_subscriber('Rome', email);