- let community_form = CommunityForm {
- name: data.name.to_owned(),
- title: data.title.to_owned(),
- description: data.description.to_owned(),
- icon,
- banner,
- nsfw: data.nsfw,
- actor_id: Some(community_actor_id.to_owned()),
- private_key: Some(keypair.private_key),
- public_key: Some(keypair.public_key),
- followers_url: Some(generate_followers_url(&community_actor_id)?),
- inbox_url: Some(generate_inbox_url(&community_actor_id)?),
- shared_inbox_url: Some(Some(generate_shared_inbox_url(&community_actor_id)?)),
- ..CommunityForm::default()
- };
-
- let inserted_community = blocking(context.pool(), move |conn| {
- Community::create(conn, &community_form)
- })
- .await?
- .map_err(|e| ApiError::err("community_already_exists", e))?;
+ let community_form = CommunityInsertForm::builder()
+ .name(name)
+ .title(title)
+ .description(description)
+ .icon(icon)
+ .banner(banner)
+ .nsfw(data.nsfw)
+ .actor_id(Some(community_actor_id.clone()))
+ .private_key(Some(keypair.private_key))
+ .public_key(keypair.public_key)
+ .followers_url(Some(generate_followers_url(&community_actor_id)?))
+ .inbox_url(Some(generate_inbox_url(&community_actor_id)?))
+ .shared_inbox_url(Some(generate_shared_inbox_url(&community_actor_id)?))
+ .posting_restricted_to_mods(data.posting_restricted_to_mods)
+ .instance_id(site_view.site.instance_id)
+ .build();
+
+ let inserted_community = Community::create(&mut context.pool(), &community_form)
+ .await
+ .with_lemmy_type(LemmyErrorType::CommunityAlreadyExists)?;