def add_new_user_history(user_profile: UserProfile, streams: Iterable[Stream]) -> None:
    'Give you the last ONBOARDING_TOTAL_MESSAGES messages on your public\n    streams, so you have something to look at in your home view once\n    you finish the tutorial.  The most recent ONBOARDING_UNREAD_MESSAGES\n    are marked unread.\n    '
    one_week_ago = (timezone_now() - datetime.timedelta(weeks=1))
    recipient_ids = [stream.recipient_id for stream in streams if (not stream.invite_only)]
    recent_messages = Message.objects.filter(recipient_id__in=recipient_ids, date_sent__gt=one_week_ago).order_by('-id')
    message_ids_to_use = list(reversed(recent_messages.values_list('id', flat=True)[0:ONBOARDING_TOTAL_MESSAGES]))
    if (len(message_ids_to_use) == 0):
        return
    already_ids = set(UserMessage.objects.filter(message_id__in=message_ids_to_use, user_profile=user_profile).values_list('message_id', flat=True))
    marked_unread = 0
    ums_to_create = []
    for message_id in reversed(message_ids_to_use):
        if (message_id in already_ids):
            continue
        um = UserMessage(user_profile=user_profile, message_id=message_id)
        if (marked_unread < ONBOARDING_UNREAD_MESSAGES):
            marked_unread += 1
        else:
            um.flags = UserMessage.flags.read
        ums_to_create.append(um)
    UserMessage.objects.bulk_create(reversed(ums_to_create))
Give you the last ONBOARDING_TOTAL_MESSAGES messages on your public
streams, so you have something to look at in your home view once
you finish the tutorial.  The most recent ONBOARDING_UNREAD_MESSAGES
are marked unread.
def add_new_user_history(user_profile: UserProfile, streams: Iterable[Stream]) -> None:
    'Give you the last ONBOARDING_TOTAL_MESSAGES messages on your public\n    streams, so you have something to look at in your home view once\n    you finish the tutorial.  The most recent ONBOARDING_UNREAD_MESSAGES\n    are marked unread.\n    '
    one_week_ago = (timezone_now() - datetime.timedelta(weeks=1))
    recipient_ids = [stream.recipient_id for stream in streams if (not stream.invite_only)]
    recent_messages = Message.objects.filter(recipient_id__in=recipient_ids, date_sent__gt=one_week_ago).order_by('-id')
    message_ids_to_use = list(reversed(recent_messages.values_list('id', flat=True)[0:ONBOARDING_TOTAL_MESSAGES]))
    if (len(message_ids_to_use) == 0):
        return
    already_ids = set(UserMessage.objects.filter(message_id__in=message_ids_to_use, user_profile=user_profile).values_list('message_id', flat=True))
    marked_unread = 0
    ums_to_create = []
    for message_id in reversed(message_ids_to_use):
        if (message_id in already_ids):
            continue
        um = UserMessage(user_profile=user_profile, message_id=message_id)
        if (marked_unread < ONBOARDING_UNREAD_MESSAGES):
            marked_unread += 1
        else:
            um.flags = UserMessage.flags.read
        ums_to_create.append(um)
    UserMessage.objects.bulk_create(reversed(ums_to_create))