use crate::{
- functions::lower,
- naive_now,
newtypes::{CommunityId, DbUrl, PersonId},
source::community::{
Community,
CommunityPersonBanForm,
CommunitySafe,
},
- traits::{Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable},
+ traits::{ApubActor, Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable},
+ utils::{functions::lower, naive_now},
+};
+use diesel::{
+ dsl::*,
+ result::Error,
+ ExpressionMethods,
+ PgConnection,
+ QueryDsl,
+ RunQueryDsl,
+ TextExpressionMethods,
};
-use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
-use url::Url;
mod safe_type {
use crate::{schema::community::*, source::community::Community, traits::ToSafe};
local,
icon,
banner,
+ hidden,
+ posting_restricted_to_mods,
);
impl ToSafe for Community {
local,
icon,
banner,
+ hidden,
+ posting_restricted_to_mods,
)
}
}
}
impl Community {
- pub fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error> {
- use crate::schema::community::dsl::*;
- community
- .filter(local.eq(true))
- .filter(lower(name).eq(lower(community_name)))
- .first::<Self>(conn)
- }
-
pub fn update_deleted(
conn: &PgConnection,
community_id: CommunityId,
.get_result::<Self>(conn)
}
- pub fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
+ pub fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<DbUrl>, Error> {
use crate::schema::community::dsl::*;
- community.select(actor_id).distinct().load::<String>(conn)
+ community.select(actor_id).distinct().load::<DbUrl>(conn)
}
pub fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
.set(community_form)
.get_result::<Self>(conn)
}
- pub fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, Error> {
- use crate::schema::community::dsl::*;
- let object_id: DbUrl = object_id.into();
- Ok(
- community
- .filter(actor_id.eq(object_id))
- .first::<Community>(conn)
- .ok()
- .map(Into::into),
- )
- }
}
impl Joinable for CommunityModerator {
}
}
+impl ApubActor for Community {
+ fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Option<Self>, Error> {
+ use crate::schema::community::dsl::*;
+ Ok(
+ community
+ .filter(actor_id.eq(object_id))
+ .first::<Community>(conn)
+ .ok()
+ .map(Into::into),
+ )
+ }
+
+ fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error> {
+ use crate::schema::community::dsl::*;
+ community
+ .filter(local.eq(true))
+ .filter(lower(name).eq(lower(community_name)))
+ .first::<Self>(conn)
+ }
+
+ fn read_from_name_and_domain(
+ conn: &PgConnection,
+ community_name: &str,
+ protocol_domain: &str,
+ ) -> Result<Community, Error> {
+ use crate::schema::community::dsl::*;
+ community
+ .filter(lower(name).eq(lower(community_name)))
+ .filter(actor_id.like(format!("{}%", protocol_domain)))
+ .first::<Self>(conn)
+ }
+}
+
#[cfg(test)]
mod tests {
use crate::{
- establish_unpooled_connection,
source::{community::*, person::*},
traits::{Bannable, Crud, Followable, Joinable},
+ utils::establish_unpooled_connection,
};
use serial_test::serial;
followers_url: inserted_community.followers_url.to_owned(),
inbox_url: inserted_community.inbox_url.to_owned(),
shared_inbox_url: None,
+ hidden: false,
+ posting_restricted_to_mods: false,
};
let community_follower_form = CommunityFollowerForm {