- fn create(conn: &mut PgConnection, new_community: &CommunityForm) -> Result<Self, Error> {
- use crate::schema::community::dsl::*;
- let community_ = insert_into(community)
- .values(new_community)
- .get_result::<Self>(conn)?;
-
- let site_languages = SiteLanguage::read_local(conn);
- if let Ok(langs) = site_languages {
- // if site exists, init user with site languages
- CommunityLanguage::update(conn, langs, community_.id)?;
- } else {
- // otherwise, init with all languages (this only happens during tests)
- CommunityLanguage::update(conn, vec![], community_.id)?;
- }
-
- Ok(community_)
- }
-
- fn update(
- conn: &mut PgConnection,
- community_id: CommunityId,
- new_community: &CommunityForm,
- ) -> Result<Self, Error> {
- use crate::schema::community::dsl::*;
- diesel::update(community.find(community_id))
- .set(new_community)
- .get_result::<Self>(conn)
- }
-}
-
-impl Community {
- pub fn update_deleted(
- conn: &mut PgConnection,
- community_id: CommunityId,
- new_deleted: bool,
- ) -> Result<Community, Error> {
- use crate::schema::community::dsl::*;
- diesel::update(community.find(community_id))
- .set((deleted.eq(new_deleted), updated.eq(naive_now())))
- .get_result::<Self>(conn)
- }
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
+ let is_new_community = match &form.actor_id {
+ Some(id) => Community::read_from_apub_id(pool, id).await?.is_none(),
+ None => true,
+ };
+ let conn = &mut get_conn(pool).await?;