mirror of
https://github.com/zulip/zulip.git
synced 2026-07-12 21:04:41 +08:00
Return both subscribed and unsubscribed stream information when listing streams
(imported from commit 0aee84712eefd93aebc1041b371e471182eb7e9b)
This commit is contained in:
parent
969e0dd827
commit
625f8427e6
@ -1044,7 +1044,6 @@ def gather_subscriptions(user_profile):
|
||||
# For now, don't display subscriptions for private messages.
|
||||
subs = Subscription.objects.select_related().filter(
|
||||
user_profile = user_profile,
|
||||
active = True,
|
||||
recipient__type = Recipient.STREAM)
|
||||
|
||||
stream_ids = [sub.recipient.type_id for sub in subs]
|
||||
@ -1053,16 +1052,22 @@ def gather_subscriptions(user_profile):
|
||||
for stream in Stream.objects.filter(id__in=stream_ids):
|
||||
stream_hash[stream.id] = (stream.name, stream.invite_only)
|
||||
|
||||
result = []
|
||||
subscribed = []
|
||||
unsubscribed = []
|
||||
|
||||
for sub in subs:
|
||||
(stream_name, invite_only) = stream_hash[sub.recipient.type_id]
|
||||
result.append({'name': stream_name,
|
||||
stream = {'name': stream_name,
|
||||
'in_home_view': sub.in_home_view,
|
||||
'invite_only': invite_only,
|
||||
'color': sub.color,
|
||||
'notifications': sub.notifications})
|
||||
'notifications': sub.notifications}
|
||||
if sub.active:
|
||||
subscribed.append(stream)
|
||||
else:
|
||||
unsubscribed.append(stream)
|
||||
|
||||
return sorted(result)
|
||||
return (sorted(subscribed), sorted(unsubscribed))
|
||||
|
||||
@cache_with_key(status_dict_cache_key, timeout=60)
|
||||
def get_status_dict(requesting_user_profile):
|
||||
@ -1114,7 +1119,9 @@ def do_events_register(user_profile, user_client, apply_markdown=True,
|
||||
ret['onboarding_steps'] = [{'email' : profile.email,
|
||||
'steps' : profile.onboarding_steps}]
|
||||
if event_types is None or "subscription" in event_types:
|
||||
ret['subscriptions'] = gather_subscriptions(user_profile)
|
||||
subs = gather_subscriptions(user_profile)
|
||||
ret['subscriptions'] = subs[0]
|
||||
ret['unsubscribed'] = subs[1]
|
||||
if event_types is None or "presence" in event_types:
|
||||
ret['presences'] = get_status_dict(user_profile)
|
||||
|
||||
@ -1141,6 +1148,7 @@ def do_events_register(user_profile, user_client, apply_markdown=True,
|
||||
sub = event['subscription']
|
||||
ret['subscriptions'] = filter(lambda s: s['name'] != sub['name'],
|
||||
ret['subscriptions'])
|
||||
ret['unsubscribed'].append(sub)
|
||||
elif event['type'] == "presence":
|
||||
ret['presences'][event['email']] = event['presence']
|
||||
elif event['type'] == "update_message":
|
||||
|
||||
@ -619,7 +619,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
"""
|
||||
test_email = "hamlet@humbughq.com"
|
||||
self.login(test_email)
|
||||
subs = gather_subscriptions(self.get_user_profile(test_email))
|
||||
subs = gather_subscriptions(self.get_user_profile(test_email))[0]
|
||||
result = self.client.get("/json/subscriptions/property",
|
||||
{"property": "color",
|
||||
"stream_name": subs[0]['name']})
|
||||
@ -642,7 +642,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
test_email = "hamlet@humbughq.com"
|
||||
self.login(test_email)
|
||||
|
||||
old_subs = gather_subscriptions(self.get_user_profile(test_email))
|
||||
old_subs, _ = gather_subscriptions(self.get_user_profile(test_email))
|
||||
sub = old_subs[0]
|
||||
stream_name = sub['name']
|
||||
old_color = sub['color']
|
||||
@ -655,7 +655,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
|
||||
self.assert_json_success(result)
|
||||
|
||||
new_subs = gather_subscriptions(self.get_user_profile(test_email))
|
||||
new_subs = gather_subscriptions(self.get_user_profile(test_email))[0]
|
||||
sub = {'name': stream_name, 'in_home_view': True, 'color': new_color,
|
||||
'invite_only': invite_only, 'notifications': False}
|
||||
self.assertIn(sub, new_subs)
|
||||
@ -683,7 +683,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
"""
|
||||
test_email = "hamlet@humbughq.com"
|
||||
self.login(test_email)
|
||||
subs = gather_subscriptions(self.get_user_profile(test_email))
|
||||
subs = gather_subscriptions(self.get_user_profile(test_email))[0]
|
||||
result = self.client.post("/json/subscriptions/property",
|
||||
{"property": "color",
|
||||
"stream_name": subs[0]["name"]})
|
||||
@ -696,7 +696,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
"""
|
||||
test_email = "hamlet@humbughq.com"
|
||||
self.login(test_email)
|
||||
subs = gather_subscriptions(self.get_user_profile(test_email))
|
||||
subs = gather_subscriptions(self.get_user_profile(test_email))[0]
|
||||
result = self.client.post("/json/subscriptions/property",
|
||||
{"property": "bad",
|
||||
"stream_name": subs[0]["name"]})
|
||||
@ -1795,7 +1795,7 @@ class GetSubscribersTest(AuthedTestCase):
|
||||
"""
|
||||
get_subscribers returns the list of subscribers.
|
||||
"""
|
||||
stream_name = gather_subscriptions(self.user_profile)[0]['name']
|
||||
stream_name = gather_subscriptions(self.user_profile)[0][0]['name']
|
||||
self.make_successful_subscriber_request(stream_name)
|
||||
|
||||
def test_nonsubscriber(self):
|
||||
|
||||
@ -541,6 +541,7 @@ def home(request):
|
||||
poll_timeout = settings.POLL_TIMEOUT,
|
||||
have_initial_messages = user_has_messages,
|
||||
stream_list = register_ret['subscriptions'],
|
||||
unsubbed_info = register_ret['unsubscribed'],
|
||||
people_list = register_ret['realm_users'],
|
||||
initial_pointer = register_ret['pointer'],
|
||||
initial_presences = register_ret['presences'],
|
||||
@ -1151,14 +1152,12 @@ def get_public_streams_backend(request, user_profile):
|
||||
|
||||
@authenticated_api_view
|
||||
def api_list_subscriptions(request, user_profile):
|
||||
return list_subscriptions_backend(request, user_profile)
|
||||
return json_success({"subscriptions": gather_subscriptions(user_profile)[0]})
|
||||
|
||||
@authenticated_json_post_view
|
||||
def json_list_subscriptions(request, user_profile):
|
||||
return list_subscriptions_backend(request, user_profile)
|
||||
|
||||
def list_subscriptions_backend(request, user_profile):
|
||||
return json_success({"subscriptions": gather_subscriptions(user_profile)})
|
||||
all_subs = gather_subscriptions(user_profile)
|
||||
return json_success({"subscriptions": all_subs[0], "unsubscribed": all_subs[1]})
|
||||
|
||||
@transaction.commit_on_success
|
||||
@has_request_variables
|
||||
|
||||
Loading…
Reference in New Issue
Block a user