Use stream_id as key for subscription removals.

Have the server send down the stream's id for removal
events, and have the client use that id to look up the
stream in its internal data structures.  This sets the
stage for eventually just sending the stream id (and not
the stream name) down to clients, once all our clients
are ready to use the stream id.

(imported from commit 922516c98fb79ffad8ae7da0396646663ca54fd0)
This commit is contained in:
Steve Howell
2014-02-07 13:06:02 -05:00
committed by Tim Abbott
parent 194464f596
commit 72ee636571
4 changed files with 6 additions and 4 deletions

View File

@@ -99,8 +99,9 @@ function get_events_success(events) {
subs.mark_subscribed(sub.name, sub); subs.mark_subscribed(sub.name, sub);
}); });
} else if (event.op === 'remove') { } else if (event.op === 'remove') {
_.each(event.subscriptions, function (sub) { _.each(event.subscriptions, function (rec) {
subs.mark_unsubscribed(sub.name); var sub = stream_data.get_sub_by_id(rec.stream_id);
subs.mark_sub_unsubscribed(sub);
}); });
} else if (event.op === 'update') { } else if (event.op === 'update') {
subs.update_subscription_properties(event.name, event.property, event.value); subs.update_subscription_properties(event.name, event.property, event.value);

View File

@@ -1054,7 +1054,7 @@ def notify_subscriptions_removed(user_profile, streams, no_log=False):
'names': [stream.name for stream in streams], 'names': [stream.name for stream in streams],
'domain': stream.realm.domain}) 'domain': stream.realm.domain})
payload = [dict(name=stream.name) for stream in streams] payload = [dict(name=stream.name, stream_id=stream.id) for stream in streams]
event = dict(type="subscription", op="remove", event = dict(type="subscription", op="remove",
subscriptions=payload) subscriptions=payload)
send_event(event, [user_profile.id]) send_event(event, [user_profile.id])

View File

@@ -295,6 +295,7 @@ class EventsRegisterTest(AuthedTestCase):
('subscriptions', check_list( ('subscriptions', check_list(
check_dict([ check_dict([
('name', equals('test_stream')), ('name', equals('test_stream')),
('stream_id', check_int),
]), ]),
)), )),
]) ])

View File

@@ -231,7 +231,7 @@ class StreamAdminTest(AuthedTestCase):
self.assertEqual(deletion_event, dict( self.assertEqual(deletion_event, dict(
op='remove', op='remove',
type='subscription', type='subscription',
subscriptions=[{'name': active_name}] subscriptions=[{'name': active_name, 'stream_id': stream.id}]
)) ))
else: else:
# You could delete the stream, but you weren't on it so you don't # You could delete the stream, but you weren't on it so you don't