2021-10-16 13:33:38 +00:00
|
|
|
use crate::{
|
|
|
|
newtypes::{CommunityId, DbUrl, PersonId},
|
2023-08-08 09:41:10 +00:00
|
|
|
schema::{community, community_follower, instance},
|
2022-10-06 18:27:58 +00:00
|
|
|
source::{
|
2023-03-30 15:03:13 +00:00
|
|
|
actor_language::CommunityLanguage,
|
2022-10-06 18:27:58 +00:00
|
|
|
community::{
|
|
|
|
Community,
|
|
|
|
CommunityFollower,
|
|
|
|
CommunityFollowerForm,
|
2022-10-27 09:24:07 +00:00
|
|
|
CommunityInsertForm,
|
2022-10-06 18:27:58 +00:00
|
|
|
CommunityModerator,
|
|
|
|
CommunityModeratorForm,
|
|
|
|
CommunityPersonBan,
|
|
|
|
CommunityPersonBanForm,
|
2022-10-27 09:24:07 +00:00
|
|
|
CommunityUpdateForm,
|
2022-10-06 18:27:58 +00:00
|
|
|
},
|
2024-02-26 14:45:23 +00:00
|
|
|
post::Post,
|
2020-12-21 12:28:12 +00:00
|
|
|
},
|
2023-03-01 03:46:15 +00:00
|
|
|
traits::{ApubActor, Bannable, Crud, Followable, Joinable},
|
2022-11-09 10:05:00 +00:00
|
|
|
utils::{functions::lower, get_conn, DbPool},
|
2022-06-22 12:05:41 +00:00
|
|
|
SubscribedType,
|
2022-01-27 16:39:22 +00:00
|
|
|
};
|
2023-08-08 09:41:10 +00:00
|
|
|
use diesel::{
|
|
|
|
deserialize,
|
|
|
|
dsl,
|
2024-02-16 12:24:35 +00:00
|
|
|
dsl::{exists, insert_into},
|
2023-08-08 09:41:10 +00:00
|
|
|
pg::Pg,
|
|
|
|
result::Error,
|
2024-02-16 12:24:35 +00:00
|
|
|
select,
|
2023-08-08 09:41:10 +00:00
|
|
|
sql_types,
|
2024-02-26 14:45:23 +00:00
|
|
|
update,
|
2023-08-08 09:41:10 +00:00
|
|
|
ExpressionMethods,
|
|
|
|
NullableExpressionMethods,
|
|
|
|
QueryDsl,
|
|
|
|
Queryable,
|
|
|
|
};
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel_async::RunQueryDsl;
|
2020-12-06 03:49:15 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
#[async_trait]
|
2021-08-17 18:04:58 +00:00
|
|
|
impl Crud for Community {
|
2022-10-27 09:24:07 +00:00
|
|
|
type InsertForm = CommunityInsertForm;
|
|
|
|
type UpdateForm = CommunityUpdateForm;
|
2021-08-17 18:04:58 +00:00
|
|
|
type IdType = CommunityId;
|
2019-04-16 23:04:23 +00:00
|
|
|
|
2023-07-11 13:09:59 +00:00
|
|
|
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
2023-03-30 15:03:13 +00:00
|
|
|
let is_new_community = match &form.actor_id {
|
|
|
|
Some(id) => Community::read_from_apub_id(pool, id).await?.is_none(),
|
|
|
|
None => true,
|
|
|
|
};
|
2023-07-11 13:09:59 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2023-03-30 15:03:13 +00:00
|
|
|
|
|
|
|
// Can't do separate insert/update commands because InsertForm/UpdateForm aren't convertible
|
2023-04-25 23:28:06 +00:00
|
|
|
let community_ = insert_into(community::table)
|
2022-10-27 09:24:07 +00:00
|
|
|
.values(form)
|
2023-04-25 23:28:06 +00:00
|
|
|
.on_conflict(community::actor_id)
|
2022-10-27 09:24:07 +00:00
|
|
|
.do_update()
|
|
|
|
.set(form)
|
2022-11-09 10:05:00 +00:00
|
|
|
.get_result::<Self>(conn)
|
|
|
|
.await?;
|
2022-10-06 18:27:58 +00:00
|
|
|
|
2023-03-30 15:03:13 +00:00
|
|
|
// Initialize languages for new community
|
|
|
|
if is_new_community {
|
2022-11-09 10:05:00 +00:00
|
|
|
CommunityLanguage::update(pool, vec![], community_.id).await?;
|
2022-10-06 18:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(community_)
|
2019-04-16 23:04:23 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
async fn update(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2021-03-18 20:25:21 +00:00
|
|
|
community_id: CommunityId,
|
2022-10-27 09:24:07 +00:00
|
|
|
form: &Self::UpdateForm,
|
2019-09-07 15:35:05 +00:00
|
|
|
) -> Result<Self, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2023-04-25 23:28:06 +00:00
|
|
|
diesel::update(community::table.find(community_id))
|
2022-10-27 09:24:07 +00:00
|
|
|
.set(form)
|
2022-06-13 19:15:04 +00:00
|
|
|
.get_result::<Self>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2022-06-13 19:15:04 +00:00
|
|
|
}
|
2019-04-25 21:52:18 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
#[async_trait]
|
2021-08-17 18:04:58 +00:00
|
|
|
impl Joinable for CommunityModerator {
|
|
|
|
type Form = CommunityModeratorForm;
|
2022-11-09 10:05:00 +00:00
|
|
|
async fn join(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2021-02-26 13:49:58 +00:00
|
|
|
community_moderator_form: &CommunityModeratorForm,
|
2019-09-07 15:35:05 +00:00
|
|
|
) -> Result<Self, Error> {
|
2022-11-19 04:33:54 +00:00
|
|
|
use crate::schema::community_moderator::dsl::community_moderator;
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2019-04-16 23:04:23 +00:00
|
|
|
insert_into(community_moderator)
|
2021-02-26 13:49:58 +00:00
|
|
|
.values(community_moderator_form)
|
2019-04-16 23:04:23 +00:00
|
|
|
.get_result::<Self>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2019-04-16 23:04:23 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
async fn leave(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2021-02-26 13:49:58 +00:00
|
|
|
community_moderator_form: &CommunityModeratorForm,
|
2019-09-07 15:35:05 +00:00
|
|
|
) -> Result<usize, Error> {
|
Remove id column and use different primary key on some tables (#4093)
* post_saved
* fmt
* remove unique and not null
* put person_id first in primary key and remove index
* use post_saved.find
* change captcha_answer
* remove removal of not null
* comment_aggregates
* comment_like
* comment_saved
* aggregates
* remove "\"
* deduplicate site_aggregates
* person_post_aggregates
* community_moderator
* community_block
* community_person_ban
* custom_emoji_keyword
* federation allow/block list
* federation_queue_state
* instance_block
* local_site_rate_limit, local_user_language, login_token
* person_ban, person_block, person_follower, post_like, post_read, received_activity
* community_follower, community_language, site_language
* fmt
* image_upload
* remove unused newtypes
* remove more indexes
* use .find
* merge
* fix site_aggregates_site function
* fmt
* Primary keys dess (#17)
* Also order reports by oldest first (ref #4123) (#4129)
* Support signed fetch for federation (fixes #868) (#4125)
* Support signed fetch for federation (fixes #868)
* taplo
* add federation queue state to get_federated_instances api (#4104)
* add federation queue state to get_federated_instances api
* feature gate
* move retry sleep function
* move stuff around
* Add UI setting for collapsing bot comments. Fixes #3838 (#4098)
* Add UI setting for collapsing bot comments. Fixes #3838
* Fixing clippy check.
* Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131)
* Only check auth secure on release mode. (#4127)
* Only check auth secure on release mode.
* Fixing wrong js-client.
* Adding is_debug_mode var.
* Fixing the desktop image on the README. (#4135)
* Delete dupes and add possibly missing unique constraint on person_aggregates.
* Fixing clippy lints.
---------
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
* fmt
* Update community_block.rs
* Update instance_block.rs
* Update person_block.rs
* Update person_block.rs
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
|
|
|
use crate::schema::community_moderator::dsl::community_moderator;
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
Remove id column and use different primary key on some tables (#4093)
* post_saved
* fmt
* remove unique and not null
* put person_id first in primary key and remove index
* use post_saved.find
* change captcha_answer
* remove removal of not null
* comment_aggregates
* comment_like
* comment_saved
* aggregates
* remove "\"
* deduplicate site_aggregates
* person_post_aggregates
* community_moderator
* community_block
* community_person_ban
* custom_emoji_keyword
* federation allow/block list
* federation_queue_state
* instance_block
* local_site_rate_limit, local_user_language, login_token
* person_ban, person_block, person_follower, post_like, post_read, received_activity
* community_follower, community_language, site_language
* fmt
* image_upload
* remove unused newtypes
* remove more indexes
* use .find
* merge
* fix site_aggregates_site function
* fmt
* Primary keys dess (#17)
* Also order reports by oldest first (ref #4123) (#4129)
* Support signed fetch for federation (fixes #868) (#4125)
* Support signed fetch for federation (fixes #868)
* taplo
* add federation queue state to get_federated_instances api (#4104)
* add federation queue state to get_federated_instances api
* feature gate
* move retry sleep function
* move stuff around
* Add UI setting for collapsing bot comments. Fixes #3838 (#4098)
* Add UI setting for collapsing bot comments. Fixes #3838
* Fixing clippy check.
* Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131)
* Only check auth secure on release mode. (#4127)
* Only check auth secure on release mode.
* Fixing wrong js-client.
* Adding is_debug_mode var.
* Fixing the desktop image on the README. (#4135)
* Delete dupes and add possibly missing unique constraint on person_aggregates.
* Fixing clippy lints.
---------
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
* fmt
* Update community_block.rs
* Update instance_block.rs
* Update person_block.rs
* Update person_block.rs
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
|
|
|
diesel::delete(community_moderator.find((
|
|
|
|
community_moderator_form.person_id,
|
|
|
|
community_moderator_form.community_id,
|
|
|
|
)))
|
2019-09-07 15:35:05 +00:00
|
|
|
.execute(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2019-04-16 23:04:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-18 14:50:28 +00:00
|
|
|
pub enum CollectionType {
|
|
|
|
Moderators,
|
|
|
|
Featured,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Community {
|
|
|
|
/// Get the community which has a given moderators or featured url, also return the collection type
|
|
|
|
pub async fn get_by_collection_url(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2023-02-18 14:50:28 +00:00
|
|
|
url: &DbUrl,
|
|
|
|
) -> Result<(Community, CollectionType), Error> {
|
|
|
|
use crate::schema::community::dsl::{featured_url, moderators_url};
|
|
|
|
use CollectionType::*;
|
|
|
|
let conn = &mut get_conn(pool).await?;
|
2023-04-25 23:28:06 +00:00
|
|
|
let res = community::table
|
2023-02-18 14:50:28 +00:00
|
|
|
.filter(moderators_url.eq(url))
|
|
|
|
.first::<Self>(conn)
|
|
|
|
.await;
|
|
|
|
if let Ok(c) = res {
|
|
|
|
return Ok((c, Moderators));
|
|
|
|
}
|
2023-04-25 23:28:06 +00:00
|
|
|
let res = community::table
|
2023-02-18 14:50:28 +00:00
|
|
|
.filter(featured_url.eq(url))
|
|
|
|
.first::<Self>(conn)
|
|
|
|
.await;
|
|
|
|
if let Ok(c) = res {
|
|
|
|
return Ok((c, Featured));
|
|
|
|
}
|
|
|
|
Err(diesel::NotFound)
|
|
|
|
}
|
2024-02-26 14:45:23 +00:00
|
|
|
|
|
|
|
pub async fn set_featured_posts(
|
|
|
|
community_id: CommunityId,
|
|
|
|
posts: Vec<Post>,
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
use crate::schema::post;
|
|
|
|
let conn = &mut get_conn(pool).await?;
|
|
|
|
for p in &posts {
|
|
|
|
debug_assert!(p.community_id == community_id);
|
|
|
|
}
|
|
|
|
conn
|
|
|
|
.build_transaction()
|
|
|
|
.run(|conn| {
|
|
|
|
Box::pin(async move {
|
|
|
|
update(
|
|
|
|
// first remove all existing featured posts
|
|
|
|
post::table,
|
|
|
|
)
|
|
|
|
.filter(post::dsl::community_id.eq(community_id))
|
|
|
|
.set(post::dsl::featured_community.eq(false))
|
|
|
|
.execute(conn)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// then mark the given posts as featured
|
|
|
|
let post_ids: Vec<_> = posts.iter().map(|p| p.id).collect();
|
|
|
|
update(post::table)
|
|
|
|
.filter(post::dsl::id.eq_any(post_ids))
|
|
|
|
.set(post::dsl::featured_community.eq(true))
|
|
|
|
.execute(conn)
|
|
|
|
.await?;
|
|
|
|
Ok(())
|
|
|
|
}) as _
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
}
|
2023-02-18 14:50:28 +00:00
|
|
|
}
|
|
|
|
|
2021-10-16 13:33:38 +00:00
|
|
|
impl CommunityModerator {
|
2022-11-09 10:05:00 +00:00
|
|
|
pub async fn delete_for_community(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2021-03-18 20:25:21 +00:00
|
|
|
for_community_id: CommunityId,
|
|
|
|
) -> Result<usize, Error> {
|
2022-11-19 04:33:54 +00:00
|
|
|
use crate::schema::community_moderator::dsl::{community_id, community_moderator};
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
|
|
|
|
|
|
|
diesel::delete(community_moderator.filter(community_id.eq(for_community_id)))
|
|
|
|
.execute(conn)
|
|
|
|
.await
|
2019-08-24 02:40:41 +00:00
|
|
|
}
|
2020-10-25 02:59:13 +00:00
|
|
|
|
2023-04-15 23:41:05 +00:00
|
|
|
pub async fn leave_all_communities(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2023-04-15 23:41:05 +00:00
|
|
|
for_person_id: PersonId,
|
|
|
|
) -> Result<usize, Error> {
|
|
|
|
use crate::schema::community_moderator::dsl::{community_moderator, person_id};
|
|
|
|
let conn = &mut get_conn(pool).await?;
|
|
|
|
diesel::delete(community_moderator.filter(person_id.eq(for_person_id)))
|
|
|
|
.execute(conn)
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
pub async fn get_person_moderated_communities(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2021-03-18 20:25:21 +00:00
|
|
|
for_person_id: PersonId,
|
|
|
|
) -> Result<Vec<CommunityId>, Error> {
|
2022-11-19 04:33:54 +00:00
|
|
|
use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2020-10-25 02:59:13 +00:00
|
|
|
community_moderator
|
2021-02-26 13:49:58 +00:00
|
|
|
.filter(person_id.eq(for_person_id))
|
2020-11-04 02:15:11 +00:00
|
|
|
.select(community_id)
|
2021-03-18 20:25:21 +00:00
|
|
|
.load::<CommunityId>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2020-10-25 02:59:13 +00:00
|
|
|
}
|
2019-08-24 02:40:41 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
#[async_trait]
|
2021-08-17 18:04:58 +00:00
|
|
|
impl Bannable for CommunityPersonBan {
|
|
|
|
type Form = CommunityPersonBanForm;
|
2022-11-09 10:05:00 +00:00
|
|
|
async fn ban(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2021-02-26 13:49:58 +00:00
|
|
|
community_person_ban_form: &CommunityPersonBanForm,
|
2019-09-07 15:35:05 +00:00
|
|
|
) -> Result<Self, Error> {
|
2022-11-19 04:33:54 +00:00
|
|
|
use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2021-02-26 13:49:58 +00:00
|
|
|
insert_into(community_person_ban)
|
|
|
|
.values(community_person_ban_form)
|
2022-01-08 12:37:07 +00:00
|
|
|
.on_conflict((community_id, person_id))
|
|
|
|
.do_update()
|
|
|
|
.set(community_person_ban_form)
|
2019-04-16 23:04:23 +00:00
|
|
|
.get_result::<Self>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2019-04-16 23:04:23 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
async fn unban(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2021-02-26 13:49:58 +00:00
|
|
|
community_person_ban_form: &CommunityPersonBanForm,
|
2019-09-07 15:35:05 +00:00
|
|
|
) -> Result<usize, Error> {
|
Remove id column and use different primary key on some tables (#4093)
* post_saved
* fmt
* remove unique and not null
* put person_id first in primary key and remove index
* use post_saved.find
* change captcha_answer
* remove removal of not null
* comment_aggregates
* comment_like
* comment_saved
* aggregates
* remove "\"
* deduplicate site_aggregates
* person_post_aggregates
* community_moderator
* community_block
* community_person_ban
* custom_emoji_keyword
* federation allow/block list
* federation_queue_state
* instance_block
* local_site_rate_limit, local_user_language, login_token
* person_ban, person_block, person_follower, post_like, post_read, received_activity
* community_follower, community_language, site_language
* fmt
* image_upload
* remove unused newtypes
* remove more indexes
* use .find
* merge
* fix site_aggregates_site function
* fmt
* Primary keys dess (#17)
* Also order reports by oldest first (ref #4123) (#4129)
* Support signed fetch for federation (fixes #868) (#4125)
* Support signed fetch for federation (fixes #868)
* taplo
* add federation queue state to get_federated_instances api (#4104)
* add federation queue state to get_federated_instances api
* feature gate
* move retry sleep function
* move stuff around
* Add UI setting for collapsing bot comments. Fixes #3838 (#4098)
* Add UI setting for collapsing bot comments. Fixes #3838
* Fixing clippy check.
* Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131)
* Only check auth secure on release mode. (#4127)
* Only check auth secure on release mode.
* Fixing wrong js-client.
* Adding is_debug_mode var.
* Fixing the desktop image on the README. (#4135)
* Delete dupes and add possibly missing unique constraint on person_aggregates.
* Fixing clippy lints.
---------
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
* fmt
* Update community_block.rs
* Update instance_block.rs
* Update person_block.rs
* Update person_block.rs
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
|
|
|
use crate::schema::community_person_ban::dsl::community_person_ban;
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
Remove id column and use different primary key on some tables (#4093)
* post_saved
* fmt
* remove unique and not null
* put person_id first in primary key and remove index
* use post_saved.find
* change captcha_answer
* remove removal of not null
* comment_aggregates
* comment_like
* comment_saved
* aggregates
* remove "\"
* deduplicate site_aggregates
* person_post_aggregates
* community_moderator
* community_block
* community_person_ban
* custom_emoji_keyword
* federation allow/block list
* federation_queue_state
* instance_block
* local_site_rate_limit, local_user_language, login_token
* person_ban, person_block, person_follower, post_like, post_read, received_activity
* community_follower, community_language, site_language
* fmt
* image_upload
* remove unused newtypes
* remove more indexes
* use .find
* merge
* fix site_aggregates_site function
* fmt
* Primary keys dess (#17)
* Also order reports by oldest first (ref #4123) (#4129)
* Support signed fetch for federation (fixes #868) (#4125)
* Support signed fetch for federation (fixes #868)
* taplo
* add federation queue state to get_federated_instances api (#4104)
* add federation queue state to get_federated_instances api
* feature gate
* move retry sleep function
* move stuff around
* Add UI setting for collapsing bot comments. Fixes #3838 (#4098)
* Add UI setting for collapsing bot comments. Fixes #3838
* Fixing clippy check.
* Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131)
* Only check auth secure on release mode. (#4127)
* Only check auth secure on release mode.
* Fixing wrong js-client.
* Adding is_debug_mode var.
* Fixing the desktop image on the README. (#4135)
* Delete dupes and add possibly missing unique constraint on person_aggregates.
* Fixing clippy lints.
---------
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
* fmt
* Update community_block.rs
* Update instance_block.rs
* Update person_block.rs
* Update person_block.rs
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
|
|
|
diesel::delete(community_person_ban.find((
|
|
|
|
community_person_ban_form.person_id,
|
|
|
|
community_person_ban_form.community_id,
|
|
|
|
)))
|
2019-09-07 15:35:05 +00:00
|
|
|
.execute(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2019-04-16 23:04:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-22 12:05:41 +00:00
|
|
|
impl CommunityFollower {
|
|
|
|
pub fn to_subscribed_type(follower: &Option<Self>) -> SubscribedType {
|
|
|
|
match follower {
|
|
|
|
Some(f) => {
|
2022-11-23 23:40:47 +00:00
|
|
|
if f.pending {
|
2022-06-22 12:05:41 +00:00
|
|
|
SubscribedType::Pending
|
|
|
|
} else {
|
|
|
|
SubscribedType::Subscribed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If the row doesn't exist, the person isn't a follower.
|
|
|
|
None => SubscribedType::NotSubscribed,
|
|
|
|
}
|
|
|
|
}
|
2023-08-08 09:41:10 +00:00
|
|
|
|
|
|
|
pub fn select_subscribed_type() -> dsl::Nullable<community_follower::pending> {
|
|
|
|
community_follower::pending.nullable()
|
|
|
|
}
|
2023-10-16 10:03:49 +00:00
|
|
|
|
|
|
|
/// Check if a remote instance has any followers on local instance. For this it is enough to check
|
|
|
|
/// if any follow relation is stored. Dont use this for local community.
|
|
|
|
pub async fn has_local_followers(
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
remote_community_id: CommunityId,
|
|
|
|
) -> Result<bool, Error> {
|
|
|
|
use crate::schema::community_follower::dsl::{community_follower, community_id};
|
|
|
|
let conn = &mut get_conn(pool).await?;
|
|
|
|
select(exists(
|
|
|
|
community_follower.filter(community_id.eq(remote_community_id)),
|
|
|
|
))
|
|
|
|
.get_result(conn)
|
|
|
|
.await
|
|
|
|
}
|
2023-08-08 09:41:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Queryable<sql_types::Nullable<sql_types::Bool>, Pg> for SubscribedType {
|
|
|
|
type Row = Option<bool>;
|
|
|
|
fn build(row: Self::Row) -> deserialize::Result<Self> {
|
|
|
|
Ok(match row {
|
|
|
|
Some(true) => SubscribedType::Pending,
|
|
|
|
Some(false) => SubscribedType::Subscribed,
|
|
|
|
None => SubscribedType::NotSubscribed,
|
|
|
|
})
|
|
|
|
}
|
2022-06-22 12:05:41 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
#[async_trait]
|
2021-08-17 18:04:58 +00:00
|
|
|
impl Followable for CommunityFollower {
|
|
|
|
type Form = CommunityFollowerForm;
|
2023-07-11 13:09:59 +00:00
|
|
|
async fn follow(pool: &mut DbPool<'_>, form: &CommunityFollowerForm) -> Result<Self, Error> {
|
2022-11-19 04:33:54 +00:00
|
|
|
use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2019-03-04 16:39:07 +00:00
|
|
|
insert_into(community_follower)
|
2022-11-23 23:40:47 +00:00
|
|
|
.values(form)
|
2021-03-10 22:33:55 +00:00
|
|
|
.on_conflict((community_id, person_id))
|
2020-12-16 14:42:57 +00:00
|
|
|
.do_update()
|
2022-11-23 23:40:47 +00:00
|
|
|
.set(form)
|
2019-03-23 01:42:57 +00:00
|
|
|
.get_result::<Self>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2019-03-04 16:39:07 +00:00
|
|
|
}
|
2022-11-09 10:05:00 +00:00
|
|
|
async fn follow_accepted(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
Remove id column and use different primary key on some tables (#4093)
* post_saved
* fmt
* remove unique and not null
* put person_id first in primary key and remove index
* use post_saved.find
* change captcha_answer
* remove removal of not null
* comment_aggregates
* comment_like
* comment_saved
* aggregates
* remove "\"
* deduplicate site_aggregates
* person_post_aggregates
* community_moderator
* community_block
* community_person_ban
* custom_emoji_keyword
* federation allow/block list
* federation_queue_state
* instance_block
* local_site_rate_limit, local_user_language, login_token
* person_ban, person_block, person_follower, post_like, post_read, received_activity
* community_follower, community_language, site_language
* fmt
* image_upload
* remove unused newtypes
* remove more indexes
* use .find
* merge
* fix site_aggregates_site function
* fmt
* Primary keys dess (#17)
* Also order reports by oldest first (ref #4123) (#4129)
* Support signed fetch for federation (fixes #868) (#4125)
* Support signed fetch for federation (fixes #868)
* taplo
* add federation queue state to get_federated_instances api (#4104)
* add federation queue state to get_federated_instances api
* feature gate
* move retry sleep function
* move stuff around
* Add UI setting for collapsing bot comments. Fixes #3838 (#4098)
* Add UI setting for collapsing bot comments. Fixes #3838
* Fixing clippy check.
* Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131)
* Only check auth secure on release mode. (#4127)
* Only check auth secure on release mode.
* Fixing wrong js-client.
* Adding is_debug_mode var.
* Fixing the desktop image on the README. (#4135)
* Delete dupes and add possibly missing unique constraint on person_aggregates.
* Fixing clippy lints.
---------
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
* fmt
* Update community_block.rs
* Update instance_block.rs
* Update person_block.rs
* Update person_block.rs
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
|
|
|
community_id: CommunityId,
|
|
|
|
person_id: PersonId,
|
2022-11-09 10:05:00 +00:00
|
|
|
) -> Result<Self, Error> {
|
Remove id column and use different primary key on some tables (#4093)
* post_saved
* fmt
* remove unique and not null
* put person_id first in primary key and remove index
* use post_saved.find
* change captcha_answer
* remove removal of not null
* comment_aggregates
* comment_like
* comment_saved
* aggregates
* remove "\"
* deduplicate site_aggregates
* person_post_aggregates
* community_moderator
* community_block
* community_person_ban
* custom_emoji_keyword
* federation allow/block list
* federation_queue_state
* instance_block
* local_site_rate_limit, local_user_language, login_token
* person_ban, person_block, person_follower, post_like, post_read, received_activity
* community_follower, community_language, site_language
* fmt
* image_upload
* remove unused newtypes
* remove more indexes
* use .find
* merge
* fix site_aggregates_site function
* fmt
* Primary keys dess (#17)
* Also order reports by oldest first (ref #4123) (#4129)
* Support signed fetch for federation (fixes #868) (#4125)
* Support signed fetch for federation (fixes #868)
* taplo
* add federation queue state to get_federated_instances api (#4104)
* add federation queue state to get_federated_instances api
* feature gate
* move retry sleep function
* move stuff around
* Add UI setting for collapsing bot comments. Fixes #3838 (#4098)
* Add UI setting for collapsing bot comments. Fixes #3838
* Fixing clippy check.
* Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131)
* Only check auth secure on release mode. (#4127)
* Only check auth secure on release mode.
* Fixing wrong js-client.
* Adding is_debug_mode var.
* Fixing the desktop image on the README. (#4135)
* Delete dupes and add possibly missing unique constraint on person_aggregates.
* Fixing clippy lints.
---------
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
* fmt
* Update community_block.rs
* Update instance_block.rs
* Update person_block.rs
* Update person_block.rs
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
|
|
|
use crate::schema::community_follower::dsl::{community_follower, pending};
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
Remove id column and use different primary key on some tables (#4093)
* post_saved
* fmt
* remove unique and not null
* put person_id first in primary key and remove index
* use post_saved.find
* change captcha_answer
* remove removal of not null
* comment_aggregates
* comment_like
* comment_saved
* aggregates
* remove "\"
* deduplicate site_aggregates
* person_post_aggregates
* community_moderator
* community_block
* community_person_ban
* custom_emoji_keyword
* federation allow/block list
* federation_queue_state
* instance_block
* local_site_rate_limit, local_user_language, login_token
* person_ban, person_block, person_follower, post_like, post_read, received_activity
* community_follower, community_language, site_language
* fmt
* image_upload
* remove unused newtypes
* remove more indexes
* use .find
* merge
* fix site_aggregates_site function
* fmt
* Primary keys dess (#17)
* Also order reports by oldest first (ref #4123) (#4129)
* Support signed fetch for federation (fixes #868) (#4125)
* Support signed fetch for federation (fixes #868)
* taplo
* add federation queue state to get_federated_instances api (#4104)
* add federation queue state to get_federated_instances api
* feature gate
* move retry sleep function
* move stuff around
* Add UI setting for collapsing bot comments. Fixes #3838 (#4098)
* Add UI setting for collapsing bot comments. Fixes #3838
* Fixing clippy check.
* Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131)
* Only check auth secure on release mode. (#4127)
* Only check auth secure on release mode.
* Fixing wrong js-client.
* Adding is_debug_mode var.
* Fixing the desktop image on the README. (#4135)
* Delete dupes and add possibly missing unique constraint on person_aggregates.
* Fixing clippy lints.
---------
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
* fmt
* Update community_block.rs
* Update instance_block.rs
* Update person_block.rs
* Update person_block.rs
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
|
|
|
diesel::update(community_follower.find((person_id, community_id)))
|
|
|
|
.set(pending.eq(false))
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
.await
|
2020-11-10 15:45:10 +00:00
|
|
|
}
|
2023-07-11 13:09:59 +00:00
|
|
|
async fn unfollow(pool: &mut DbPool<'_>, form: &CommunityFollowerForm) -> Result<usize, Error> {
|
Remove id column and use different primary key on some tables (#4093)
* post_saved
* fmt
* remove unique and not null
* put person_id first in primary key and remove index
* use post_saved.find
* change captcha_answer
* remove removal of not null
* comment_aggregates
* comment_like
* comment_saved
* aggregates
* remove "\"
* deduplicate site_aggregates
* person_post_aggregates
* community_moderator
* community_block
* community_person_ban
* custom_emoji_keyword
* federation allow/block list
* federation_queue_state
* instance_block
* local_site_rate_limit, local_user_language, login_token
* person_ban, person_block, person_follower, post_like, post_read, received_activity
* community_follower, community_language, site_language
* fmt
* image_upload
* remove unused newtypes
* remove more indexes
* use .find
* merge
* fix site_aggregates_site function
* fmt
* Primary keys dess (#17)
* Also order reports by oldest first (ref #4123) (#4129)
* Support signed fetch for federation (fixes #868) (#4125)
* Support signed fetch for federation (fixes #868)
* taplo
* add federation queue state to get_federated_instances api (#4104)
* add federation queue state to get_federated_instances api
* feature gate
* move retry sleep function
* move stuff around
* Add UI setting for collapsing bot comments. Fixes #3838 (#4098)
* Add UI setting for collapsing bot comments. Fixes #3838
* Fixing clippy check.
* Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131)
* Only check auth secure on release mode. (#4127)
* Only check auth secure on release mode.
* Fixing wrong js-client.
* Adding is_debug_mode var.
* Fixing the desktop image on the README. (#4135)
* Delete dupes and add possibly missing unique constraint on person_aggregates.
* Fixing clippy lints.
---------
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
* fmt
* Update community_block.rs
* Update instance_block.rs
* Update person_block.rs
* Update person_block.rs
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
|
|
|
use crate::schema::community_follower::dsl::community_follower;
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
Remove id column and use different primary key on some tables (#4093)
* post_saved
* fmt
* remove unique and not null
* put person_id first in primary key and remove index
* use post_saved.find
* change captcha_answer
* remove removal of not null
* comment_aggregates
* comment_like
* comment_saved
* aggregates
* remove "\"
* deduplicate site_aggregates
* person_post_aggregates
* community_moderator
* community_block
* community_person_ban
* custom_emoji_keyword
* federation allow/block list
* federation_queue_state
* instance_block
* local_site_rate_limit, local_user_language, login_token
* person_ban, person_block, person_follower, post_like, post_read, received_activity
* community_follower, community_language, site_language
* fmt
* image_upload
* remove unused newtypes
* remove more indexes
* use .find
* merge
* fix site_aggregates_site function
* fmt
* Primary keys dess (#17)
* Also order reports by oldest first (ref #4123) (#4129)
* Support signed fetch for federation (fixes #868) (#4125)
* Support signed fetch for federation (fixes #868)
* taplo
* add federation queue state to get_federated_instances api (#4104)
* add federation queue state to get_federated_instances api
* feature gate
* move retry sleep function
* move stuff around
* Add UI setting for collapsing bot comments. Fixes #3838 (#4098)
* Add UI setting for collapsing bot comments. Fixes #3838
* Fixing clippy check.
* Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131)
* Only check auth secure on release mode. (#4127)
* Only check auth secure on release mode.
* Fixing wrong js-client.
* Adding is_debug_mode var.
* Fixing the desktop image on the README. (#4135)
* Delete dupes and add possibly missing unique constraint on person_aggregates.
* Fixing clippy lints.
---------
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
* fmt
* Update community_block.rs
* Update instance_block.rs
* Update person_block.rs
* Update person_block.rs
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
|
|
|
diesel::delete(community_follower.find((form.person_id, form.community_id)))
|
|
|
|
.execute(conn)
|
|
|
|
.await
|
2019-03-04 16:39:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
#[async_trait]
|
2022-01-27 16:39:22 +00:00
|
|
|
impl ApubActor for Community {
|
2023-07-11 13:09:59 +00:00
|
|
|
async fn read_from_apub_id(
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
object_id: &DbUrl,
|
|
|
|
) -> Result<Option<Self>, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2022-01-27 16:39:22 +00:00
|
|
|
Ok(
|
2023-04-25 23:28:06 +00:00
|
|
|
community::table
|
|
|
|
.filter(community::actor_id.eq(object_id))
|
2022-01-27 16:39:22 +00:00
|
|
|
.first::<Community>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2022-01-27 16:39:22 +00:00
|
|
|
.ok()
|
|
|
|
.map(Into::into),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
async fn read_from_name(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2022-07-05 21:40:44 +00:00
|
|
|
community_name: &str,
|
|
|
|
include_deleted: bool,
|
|
|
|
) -> Result<Community, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2023-04-25 23:28:06 +00:00
|
|
|
let mut q = community::table
|
2022-07-05 21:40:44 +00:00
|
|
|
.into_boxed()
|
2023-04-25 23:28:06 +00:00
|
|
|
.filter(community::local.eq(true))
|
|
|
|
.filter(lower(community::name).eq(community_name.to_lowercase()));
|
2022-07-05 21:40:44 +00:00
|
|
|
if !include_deleted {
|
2023-04-25 23:28:06 +00:00
|
|
|
q = q
|
|
|
|
.filter(community::deleted.eq(false))
|
|
|
|
.filter(community::removed.eq(false));
|
2022-07-05 21:40:44 +00:00
|
|
|
}
|
2022-11-09 10:05:00 +00:00
|
|
|
q.first::<Self>(conn).await
|
2022-01-27 16:39:22 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
async fn read_from_name_and_domain(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2022-01-27 16:39:22 +00:00
|
|
|
community_name: &str,
|
2023-04-25 23:28:06 +00:00
|
|
|
for_domain: &str,
|
2022-01-27 16:39:22 +00:00
|
|
|
) -> Result<Community, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2023-04-25 23:28:06 +00:00
|
|
|
community::table
|
|
|
|
.inner_join(instance::table)
|
|
|
|
.filter(lower(community::name).eq(community_name.to_lowercase()))
|
2023-08-22 15:10:21 +00:00
|
|
|
.filter(lower(instance::domain).eq(for_domain.to_lowercase()))
|
2023-04-25 23:28:06 +00:00
|
|
|
.select(community::all_columns)
|
2022-01-27 16:39:22 +00:00
|
|
|
.first::<Self>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2022-01-27 16:39:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 16:39:07 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2023-07-17 15:04:14 +00:00
|
|
|
#![allow(clippy::unwrap_used)]
|
|
|
|
#![allow(clippy::indexing_slicing)]
|
|
|
|
|
2021-10-16 13:33:38 +00:00
|
|
|
use crate::{
|
2022-11-19 04:33:54 +00:00
|
|
|
source::{
|
|
|
|
community::{
|
|
|
|
Community,
|
|
|
|
CommunityFollower,
|
|
|
|
CommunityFollowerForm,
|
|
|
|
CommunityInsertForm,
|
|
|
|
CommunityModerator,
|
|
|
|
CommunityModeratorForm,
|
|
|
|
CommunityPersonBan,
|
|
|
|
CommunityPersonBanForm,
|
|
|
|
CommunityUpdateForm,
|
|
|
|
},
|
|
|
|
instance::Instance,
|
|
|
|
person::{Person, PersonInsertForm},
|
|
|
|
},
|
2021-10-16 13:33:38 +00:00
|
|
|
traits::{Bannable, Crud, Followable, Joinable},
|
2022-11-09 10:05:00 +00:00
|
|
|
utils::build_db_pool_for_tests,
|
2024-01-25 16:04:25 +00:00
|
|
|
CommunityVisibility,
|
2021-10-16 13:33:38 +00:00
|
|
|
};
|
2024-01-04 09:47:18 +00:00
|
|
|
use pretty_assertions::assert_eq;
|
2021-02-25 19:43:39 +00:00
|
|
|
use serial_test::serial;
|
2020-05-16 14:04:08 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
#[tokio::test]
|
2021-02-25 19:43:39 +00:00
|
|
|
#[serial]
|
2022-11-09 10:05:00 +00:00
|
|
|
async fn test_crud() {
|
|
|
|
let pool = &build_db_pool_for_tests().await;
|
2023-07-11 13:09:59 +00:00
|
|
|
let pool = &mut pool.into();
|
2019-04-03 06:49:32 +00:00
|
|
|
|
2023-03-01 02:36:57 +00:00
|
|
|
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2022-10-27 09:24:07 +00:00
|
|
|
|
|
|
|
let new_person = PersonInsertForm::builder()
|
|
|
|
.name("bobbee".into())
|
|
|
|
.public_key("pubkey".to_string())
|
|
|
|
.instance_id(inserted_instance.id)
|
|
|
|
.build();
|
2019-04-03 06:49:32 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
2019-04-03 06:49:32 +00:00
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
let new_community = CommunityInsertForm::builder()
|
|
|
|
.name("TIL".into())
|
|
|
|
.title("nada".to_owned())
|
|
|
|
.public_key("pubkey".to_string())
|
|
|
|
.instance_id(inserted_instance.id)
|
|
|
|
.build();
|
2019-03-04 16:39:07 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
2019-03-04 16:39:07 +00:00
|
|
|
|
|
|
|
let expected_community = Community {
|
|
|
|
id: inserted_community.id,
|
|
|
|
name: "TIL".into(),
|
2019-04-03 20:59:37 +00:00
|
|
|
title: "nada".to_owned(),
|
|
|
|
description: None,
|
2019-08-14 02:52:43 +00:00
|
|
|
nsfw: false,
|
2019-04-20 04:06:25 +00:00
|
|
|
removed: false,
|
2019-04-29 19:14:54 +00:00
|
|
|
deleted: false,
|
2019-03-05 03:52:09 +00:00
|
|
|
published: inserted_community.published,
|
2019-09-07 15:35:05 +00:00
|
|
|
updated: None,
|
2022-11-19 04:33:54 +00:00
|
|
|
actor_id: inserted_community.actor_id.clone(),
|
2020-04-03 04:12:05 +00:00
|
|
|
local: true,
|
|
|
|
private_key: None,
|
2022-07-11 18:25:33 +00:00
|
|
|
public_key: "pubkey".to_owned(),
|
2020-04-03 04:12:05 +00:00
|
|
|
last_refreshed_at: inserted_community.published,
|
2020-08-05 16:03:46 +00:00
|
|
|
icon: None,
|
|
|
|
banner: None,
|
2022-11-19 04:33:54 +00:00
|
|
|
followers_url: inserted_community.followers_url.clone(),
|
|
|
|
inbox_url: inserted_community.inbox_url.clone(),
|
2021-02-04 16:34:58 +00:00
|
|
|
shared_inbox_url: None,
|
2023-02-18 14:50:28 +00:00
|
|
|
moderators_url: None,
|
|
|
|
featured_url: None,
|
2022-02-18 02:30:47 +00:00
|
|
|
hidden: false,
|
2022-04-28 20:32:32 +00:00
|
|
|
posting_restricted_to_mods: false,
|
2022-10-27 09:24:07 +00:00
|
|
|
instance_id: inserted_instance.id,
|
2024-01-25 16:04:25 +00:00
|
|
|
visibility: CommunityVisibility::Public,
|
2019-03-04 16:39:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let community_follower_form = CommunityFollowerForm {
|
2019-03-23 01:42:57 +00:00
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
person_id: inserted_person.id,
|
2022-05-17 18:02:48 +00:00
|
|
|
pending: false,
|
2019-03-04 16:39:07 +00:00
|
|
|
};
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let inserted_community_follower = CommunityFollower::follow(pool, &community_follower_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2019-04-15 23:12:06 +00:00
|
|
|
|
2019-03-04 16:39:07 +00:00
|
|
|
let expected_community_follower = CommunityFollower {
|
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
person_id: inserted_person.id,
|
2022-11-23 23:40:47 +00:00
|
|
|
pending: false,
|
2019-09-07 15:35:05 +00:00
|
|
|
published: inserted_community_follower.published,
|
2019-03-04 16:39:07 +00:00
|
|
|
};
|
2019-09-07 15:35:05 +00:00
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let community_moderator_form = CommunityModeratorForm {
|
2019-03-23 01:42:57 +00:00
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
person_id: inserted_person.id,
|
2019-03-04 16:39:07 +00:00
|
|
|
};
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let inserted_community_moderator = CommunityModerator::join(pool, &community_moderator_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2019-03-04 16:39:07 +00:00
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let expected_community_moderator = CommunityModerator {
|
2019-03-04 16:39:07 +00:00
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
person_id: inserted_person.id,
|
|
|
|
published: inserted_community_moderator.published,
|
2019-03-04 16:39:07 +00:00
|
|
|
};
|
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let community_person_ban_form = CommunityPersonBanForm {
|
2019-04-15 23:12:06 +00:00
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
person_id: inserted_person.id,
|
2022-01-08 12:37:07 +00:00
|
|
|
expires: None,
|
2019-04-15 23:12:06 +00:00
|
|
|
};
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let inserted_community_person_ban = CommunityPersonBan::ban(pool, &community_person_ban_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2019-04-15 23:12:06 +00:00
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let expected_community_person_ban = CommunityPersonBan {
|
2019-04-15 23:12:06 +00:00
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
person_id: inserted_person.id,
|
|
|
|
published: inserted_community_person_ban.published,
|
2022-01-08 12:37:07 +00:00
|
|
|
expires: None,
|
2019-04-15 23:12:06 +00:00
|
|
|
};
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let read_community = Community::read(pool, inserted_community.id).await.unwrap();
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2023-08-08 09:41:41 +00:00
|
|
|
let update_community_form = CommunityUpdateForm {
|
|
|
|
title: Some("nada".to_owned()),
|
|
|
|
..Default::default()
|
|
|
|
};
|
2022-11-09 10:05:00 +00:00
|
|
|
let updated_community = Community::update(pool, inserted_community.id, &update_community_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let ignored_community = CommunityFollower::unfollow(pool, &community_follower_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
let left_community = CommunityModerator::leave(pool, &community_moderator_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
let unban = CommunityPersonBan::unban(pool, &community_person_ban_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
let num_deleted = Community::delete(pool, inserted_community.id)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
Person::delete(pool, inserted_person.id).await.unwrap();
|
|
|
|
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
2019-03-04 16:39:07 +00:00
|
|
|
|
|
|
|
assert_eq!(expected_community, read_community);
|
|
|
|
assert_eq!(expected_community, inserted_community);
|
|
|
|
assert_eq!(expected_community, updated_community);
|
|
|
|
assert_eq!(expected_community_follower, inserted_community_follower);
|
2021-02-26 13:49:58 +00:00
|
|
|
assert_eq!(expected_community_moderator, inserted_community_moderator);
|
|
|
|
assert_eq!(expected_community_person_ban, inserted_community_person_ban);
|
2019-03-04 16:39:07 +00:00
|
|
|
assert_eq!(1, ignored_community);
|
|
|
|
assert_eq!(1, left_community);
|
2019-04-15 23:12:06 +00:00
|
|
|
assert_eq!(1, unban);
|
2019-04-03 06:49:32 +00:00
|
|
|
// assert_eq!(2, loaded_count);
|
2019-03-04 16:39:07 +00:00
|
|
|
assert_eq!(1, num_deleted);
|
|
|
|
}
|
|
|
|
}
|