def process_new_human_user(user_profile: UserProfile, prereg_user: Optional[PreregistrationUser]=None, newsletter_data: Optional[Mapping[(str, str)]]=None, default_stream_groups: Sequence[DefaultStreamGroup]=[], realm_creation: bool=False) -> None:
    mit_beta_user = user_profile.realm.is_zephyr_mirror_realm
    if (prereg_user is not None):
        prereg_user.status = confirmation_settings.STATUS_ACTIVE
        prereg_user.save(update_fields=['status'])
        streams = prereg_user.streams.all()
        acting_user: Optional[UserProfile] = prereg_user.referred_by
    else:
        streams = []
        acting_user = None
    if (len(streams) == 0):
        streams = get_default_subs(user_profile)
    for default_stream_group in default_stream_groups:
        default_stream_group_streams = default_stream_group.streams.all()
        for stream in default_stream_group_streams:
            if (stream not in streams):
                streams.append(stream)
    bulk_add_subscriptions(streams, [user_profile], acting_user=acting_user)
    add_new_user_history(user_profile, streams)
    if ((not mit_beta_user) and (prereg_user is not None) and (prereg_user.referred_by is not None)):
        with override_language(prereg_user.referred_by.default_language):
            internal_send_private_message(user_profile.realm, get_system_bot(settings.NOTIFICATION_BOT), prereg_user.referred_by, _('{user} accepted your invitation to join Zulip!').format(user=f'{user_profile.full_name} <`{user_profile.email}`>'))
    if (prereg_user is not None):
        PreregistrationUser.objects.filter(email__iexact=user_profile.delivery_email).exclude(id=prereg_user.id).update(status=confirmation_settings.STATUS_REVOKED)
        if (prereg_user.referred_by is not None):
            notify_invites_changed(user_profile)
    else:
        PreregistrationUser.objects.filter(email__iexact=user_profile.delivery_email).update(status=confirmation_settings.STATUS_REVOKED)
    notify_new_user(user_profile)
    clear_scheduled_invitation_emails(user_profile.delivery_email)
    if user_profile.realm.send_welcome_emails:
        enqueue_welcome_emails(user_profile, realm_creation)
    from zerver.lib.onboarding import send_initial_pms
    send_initial_pms(user_profile)
    if (newsletter_data is not None):
        queue_json_publish('signups', {'email_address': user_profile.delivery_email, 'user_id': user_profile.id, 'merge_fields': {'NAME': user_profile.full_name, 'REALM_ID': user_profile.realm_id, 'OPTIN_IP': newsletter_data['IP'], 'OPTIN_TIME': datetime.datetime.isoformat(timezone_now().replace(microsecond=0))}}, (lambda event: None))
def process_new_human_user(user_profile: UserProfile, prereg_user: Optional[PreregistrationUser]=None, newsletter_data: Optional[Mapping[(str, str)]]=None, default_stream_groups: Sequence[DefaultStreamGroup]=[], realm_creation: bool=False) -> None:
    mit_beta_user = user_profile.realm.is_zephyr_mirror_realm
    if (prereg_user is not None):
        prereg_user.status = confirmation_settings.STATUS_ACTIVE
        prereg_user.save(update_fields=['status'])
        streams = prereg_user.streams.all()
        acting_user: Optional[UserProfile] = prereg_user.referred_by
    else:
        streams = []
        acting_user = None
    if (len(streams) == 0):
        streams = get_default_subs(user_profile)
    for default_stream_group in default_stream_groups:
        default_stream_group_streams = default_stream_group.streams.all()
        for stream in default_stream_group_streams:
            if (stream not in streams):
                streams.append(stream)
    bulk_add_subscriptions(streams, [user_profile], acting_user=acting_user)
    add_new_user_history(user_profile, streams)
    if ((not mit_beta_user) and (prereg_user is not None) and (prereg_user.referred_by is not None)):
        with override_language(prereg_user.referred_by.default_language):
            internal_send_private_message(user_profile.realm, get_system_bot(settings.NOTIFICATION_BOT), prereg_user.referred_by, _('{user} accepted your invitation to join Zulip!').format(user=f'{user_profile.full_name} <`{user_profile.email}`>'))
    if (prereg_user is not None):
        PreregistrationUser.objects.filter(email__iexact=user_profile.delivery_email).exclude(id=prereg_user.id).update(status=confirmation_settings.STATUS_REVOKED)
        if (prereg_user.referred_by is not None):
            notify_invites_changed(user_profile)
    else:
        PreregistrationUser.objects.filter(email__iexact=user_profile.delivery_email).update(status=confirmation_settings.STATUS_REVOKED)
    notify_new_user(user_profile)
    clear_scheduled_invitation_emails(user_profile.delivery_email)
    if user_profile.realm.send_welcome_emails:
        enqueue_welcome_emails(user_profile, realm_creation)
    from zerver.lib.onboarding import send_initial_pms
    send_initial_pms(user_profile)
    if (newsletter_data is not None):
        queue_json_publish('signups', {'email_address': user_profile.delivery_email, 'user_id': user_profile.id, 'merge_fields': {'NAME': user_profile.full_name, 'REALM_ID': user_profile.realm_id, 'OPTIN_IP': newsletter_data['IP'], 'OPTIN_TIME': datetime.datetime.isoformat(timezone_now().replace(microsecond=0))}}, (lambda event: None))