def do_change_default_sending_stream(user_profile: UserProfile, stream: Optional[Stream], log: bool=True) -> None:
    user_profile.default_sending_stream = stream
    user_profile.save(update_fields=['default_sending_stream'])
    if log:
        log_event({'type': 'user_change_default_sending_stream', 'user': user_profile.email, 'stream': str(stream)})
    if user_profile.is_bot:
        if stream:
            stream_name: Optional[str] = stream.name
        else:
            stream_name = None
        send_event(user_profile.realm, dict(type='realm_bot', op='update', bot=dict(user_id=user_profile.id, default_sending_stream=stream_name)), bot_owner_user_ids(user_profile))
def do_change_default_sending_stream(user_profile: UserProfile, stream: Optional[Stream], log: bool=True) -> None:
    user_profile.default_sending_stream = stream
    user_profile.save(update_fields=['default_sending_stream'])
    if log:
        log_event({'type': 'user_change_default_sending_stream', 'user': user_profile.email, 'stream': str(stream)})
    if user_profile.is_bot:
        if stream:
            stream_name: Optional[str] = stream.name
        else:
            stream_name = None
        send_event(user_profile.realm, dict(type='realm_bot', op='update', bot=dict(user_id=user_profile.id, default_sending_stream=stream_name)), bot_owner_user_ids(user_profile))