diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index c31801298d..c038fe569f 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -164,12 +164,13 @@ def process_new_human_user(user_profile, prereg_user=None, newsletter_data=None) streams = get_default_subs(user_profile) bulk_add_subscriptions(streams, [user_profile]) - # Give you the last 100 messages on your streams, so you have + # Give you the last 100 messages on your public streams, so you have # something to look at in your home view once you finish the # tutorial. one_week_ago = now() - datetime.timedelta(weeks=1) recipients = Recipient.objects.filter(type=Recipient.STREAM, - type_id__in=[stream.id for stream in streams]) + type_id__in=[stream.id for stream in streams + if not stream.invite_only]) messages = Message.objects.filter(recipient_id__in=recipients, pub_date__gt=one_week_ago).order_by("-id")[0:100] if len(messages) > 0: ums_to_create = [UserMessage(user_profile=user_profile, message=message, diff --git a/zerver/test_signup.py b/zerver/test_signup.py index 78a9c85488..5e183448e1 100644 --- a/zerver/test_signup.py +++ b/zerver/test_signup.py @@ -6,7 +6,7 @@ from zilencer.models import Deployment from zerver.models import ( get_realm, get_user_profile_by_email, - PreregistrationUser, Realm, ScheduledJob, UserProfile, + PreregistrationUser, Realm, Recipient, ScheduledJob, UserProfile, UserMessage, ) from zerver.lib.actions import ( @@ -298,6 +298,31 @@ class InviteUserTest(AuthedTestCase): self.assertTrue(find_key_by_email(invitee)) self.check_sent_emails([invitee]) + def test_invite_user_signup_initial_history(self): + """ + Test that a new user invited to a stream receives some initial + history but only from public streams. + """ + self.login("hamlet@zulip.com") + user_profile = get_user_profile_by_email("hamlet@zulip.com") + private_stream_name = "Secret" + (stream, _) = create_stream_if_needed(user_profile.realm, private_stream_name, invite_only=True) + do_add_subscription(user_profile, stream) + public_msg_id = self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, + "Public topic", "Public message") + secret_msg_id = self.send_message("hamlet@zulip.com", private_stream_name, Recipient.STREAM, + "Secret topic", "Secret message") + invitee = "alice-test@zulip.com" + self.assert_json_success(self.invite(invitee, [private_stream_name, "Denmark"])) + self.assertTrue(find_key_by_email(invitee)) + + self.submit_reg_form_for_user("alice-test", "password") + invitee_profile = get_user_profile_by_email(invitee) + invitee_msg_ids = [um.message_id for um in + UserMessage.objects.filter(user_profile=invitee_profile)] + self.assertTrue(public_msg_id in invitee_msg_ids) + self.assertFalse(secret_msg_id in invitee_msg_ids) + def test_multi_user_invite(self): """ Invites multiple users with a variety of delimiters.