def get_recipient_from_user_profiles(recipient_profiles: Sequence[UserProfile], forwarded_mirror_message: bool, forwarder_user_profile: Optional[UserProfile], sender: UserProfile) -> Recipient:
    recipient_profiles_map = {}
    for user_profile in recipient_profiles:
        recipient_profiles_map[user_profile.id] = user_profile
    if forwarded_mirror_message:
        assert (forwarder_user_profile is not None)
        if (forwarder_user_profile.id not in recipient_profiles_map):
            raise ValidationError(_('User not authorized for this query'))
    if ((len(recipient_profiles_map) == 2) and (sender.id in recipient_profiles_map)):
        del recipient_profiles_map[sender.id]
    assert (len(recipient_profiles_map) != 0)
    if (len(recipient_profiles_map) == 1):
        user_profile = list(recipient_profiles_map.values())[0]
        return user_profile.recipient
    recipient_profiles_map[sender.id] = sender
    user_ids: Set[int] = {user_id for user_id in recipient_profiles_map}
    return get_huddle_recipient(user_ids)
def get_recipient_from_user_profiles(recipient_profiles: Sequence[UserProfile], forwarded_mirror_message: bool, forwarder_user_profile: Optional[UserProfile], sender: UserProfile) -> Recipient:
    recipient_profiles_map = {}
    for user_profile in recipient_profiles:
        recipient_profiles_map[user_profile.id] = user_profile
    if forwarded_mirror_message:
        assert (forwarder_user_profile is not None)
        if (forwarder_user_profile.id not in recipient_profiles_map):
            raise ValidationError(_('User not authorized for this query'))
    if ((len(recipient_profiles_map) == 2) and (sender.id in recipient_profiles_map)):
        del recipient_profiles_map[sender.id]
    assert (len(recipient_profiles_map) != 0)
    if (len(recipient_profiles_map) == 1):
        user_profile = list(recipient_profiles_map.values())[0]
        return user_profile.recipient
    recipient_profiles_map[sender.id] = sender
    user_ids: Set[int] = {user_id for user_id in recipient_profiles_map}
    return get_huddle_recipient(user_ids)