2021-10-16 13:33:38 +00:00
|
|
|
use crate::{
|
2024-04-16 12:48:15 +00:00
|
|
|
diesel::OptionalExtension,
|
2024-02-14 09:49:55 +00:00
|
|
|
newtypes::{CommunityId, DbUrl, InstanceId, PersonId},
|
2024-03-01 18:45:06 +00:00
|
|
|
schema::{comment, community, instance, local_user, person, person_follower, post},
|
2022-11-23 23:40:47 +00:00
|
|
|
source::person::{
|
|
|
|
Person,
|
|
|
|
PersonFollower,
|
|
|
|
PersonFollowerForm,
|
|
|
|
PersonInsertForm,
|
|
|
|
PersonUpdateForm,
|
|
|
|
},
|
|
|
|
traits::{ApubActor, Crud, Followable},
|
2022-11-09 10:05:00 +00:00
|
|
|
utils::{functions::lower, get_conn, naive_now, DbPool},
|
2021-02-26 13:49:58 +00:00
|
|
|
};
|
2024-03-01 18:45:06 +00:00
|
|
|
use diesel::{dsl::insert_into, result::Error, CombineDsl, ExpressionMethods, JoinOnDsl, QueryDsl};
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel_async::RunQueryDsl;
|
2021-02-26 13:49:58 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
#[async_trait]
|
2021-08-17 18:04:58 +00:00
|
|
|
impl Crud for Person {
|
2022-10-27 09:24:07 +00:00
|
|
|
type InsertForm = PersonInsertForm;
|
|
|
|
type UpdateForm = PersonUpdateForm;
|
2021-08-17 18:04:58 +00:00
|
|
|
type IdType = PersonId;
|
2024-04-16 12:48:15 +00:00
|
|
|
|
|
|
|
// Override this, so that you don't get back deleted
|
|
|
|
async fn read(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Option<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
|
|
|
person::table
|
|
|
|
.filter(person::deleted.eq(false))
|
2021-02-26 13:49:58 +00:00
|
|
|
.find(person_id)
|
2024-04-16 12:48:15 +00:00
|
|
|
.first(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2024-04-16 12:48:15 +00:00
|
|
|
.optional()
|
2021-02-26 13:49:58 +00:00
|
|
|
}
|
2023-08-01 14:34:10 +00:00
|
|
|
|
2023-07-11 13:09:59 +00:00
|
|
|
async fn create(pool: &mut DbPool<'_>, form: &PersonInsertForm) -> 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
|
|
|
insert_into(person::table)
|
2022-10-27 09:24:07 +00:00
|
|
|
.values(form)
|
|
|
|
.get_result::<Self>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2021-02-26 13:49:58 +00:00
|
|
|
}
|
2022-11-09 10:05:00 +00:00
|
|
|
async fn update(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2022-09-26 14:09:32 +00:00
|
|
|
person_id: PersonId,
|
2022-10-27 09:24:07 +00:00
|
|
|
form: &PersonUpdateForm,
|
2022-09-26 14:09:32 +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(person::table.find(person_id))
|
2021-02-26 13:49:58 +00:00
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2021-02-26 13:49:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-16 13:33:38 +00:00
|
|
|
impl Person {
|
2023-06-21 09:26:07 +00:00
|
|
|
/// Update or insert the person.
|
|
|
|
///
|
2024-04-17 12:35:54 +00:00
|
|
|
/// This is necessary for federation, because Activitypub doesn't distinguish between these actions.
|
2023-07-11 13:09:59 +00:00
|
|
|
pub async fn upsert(pool: &mut DbPool<'_>, form: &PersonInsertForm) -> Result<Self, Error> {
|
2023-06-21 09:26:07 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
|
|
|
insert_into(person::table)
|
|
|
|
.values(form)
|
|
|
|
.on_conflict(person::actor_id)
|
|
|
|
.do_update()
|
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
.await
|
|
|
|
}
|
2023-07-11 13:09:59 +00:00
|
|
|
pub async fn delete_account(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Person, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2021-03-10 22:33:55 +00:00
|
|
|
|
|
|
|
// Set the local user info to none
|
|
|
|
diesel::update(local_user::table.filter(local_user::person_id.eq(person_id)))
|
2023-10-09 10:46:12 +00:00
|
|
|
.set(local_user::email.eq::<Option<String>>(None))
|
2022-11-09 10:05:00 +00:00
|
|
|
.execute(conn)
|
|
|
|
.await?;
|
2021-03-10 22:33:55 +00:00
|
|
|
|
2023-04-25 23:28:06 +00:00
|
|
|
diesel::update(person::table.find(person_id))
|
2021-02-26 13:49:58 +00:00
|
|
|
.set((
|
2023-04-25 23:28:06 +00:00
|
|
|
person::display_name.eq::<Option<String>>(None),
|
|
|
|
person::avatar.eq::<Option<String>>(None),
|
|
|
|
person::banner.eq::<Option<String>>(None),
|
|
|
|
person::bio.eq::<Option<String>>(None),
|
|
|
|
person::matrix_user_id.eq::<Option<String>>(None),
|
|
|
|
person::deleted.eq(true),
|
|
|
|
person::updated.eq(naive_now()),
|
2021-02-26 13:49:58 +00:00
|
|
|
))
|
|
|
|
.get_result::<Self>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2021-02-26 13:49:58 +00:00
|
|
|
}
|
2024-03-01 18:45:06 +00:00
|
|
|
|
|
|
|
/// Lists local community ids for all posts and comments for a given creator.
|
|
|
|
pub async fn list_local_community_ids(
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
for_creator_id: PersonId,
|
|
|
|
) -> Result<Vec<CommunityId>, Error> {
|
|
|
|
let conn = &mut get_conn(pool).await?;
|
|
|
|
comment::table
|
|
|
|
.inner_join(post::table)
|
|
|
|
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
|
|
|
.filter(community::local.eq(true))
|
|
|
|
.filter(comment::creator_id.eq(for_creator_id))
|
|
|
|
.select(community::id)
|
|
|
|
.union(
|
|
|
|
post::table
|
|
|
|
.inner_join(community::table)
|
|
|
|
.filter(community::local.eq(true))
|
|
|
|
.filter(post::creator_id.eq(for_creator_id))
|
|
|
|
.select(community::id),
|
|
|
|
)
|
|
|
|
.load::<CommunityId>(conn)
|
|
|
|
.await
|
|
|
|
}
|
2022-01-08 12:37:07 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 09:49:55 +00:00
|
|
|
impl PersonInsertForm {
|
|
|
|
pub fn test_form(instance_id: InstanceId, name: &str) -> Self {
|
|
|
|
Self::builder()
|
|
|
|
.name(name.to_owned())
|
|
|
|
.public_key("pubkey".to_string())
|
|
|
|
.instance_id(instance_id)
|
|
|
|
.build()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
#[async_trait]
|
2022-01-27 16:39:22 +00:00
|
|
|
impl ApubActor for Person {
|
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?;
|
2024-04-16 12:48:15 +00:00
|
|
|
person::table
|
|
|
|
.filter(person::deleted.eq(false))
|
|
|
|
.filter(person::actor_id.eq(object_id))
|
|
|
|
.first(conn)
|
|
|
|
.await
|
|
|
|
.optional()
|
2022-01-27 16:39:22 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
from_name: &str,
|
|
|
|
include_deleted: bool,
|
2024-04-16 12:48:15 +00:00
|
|
|
) -> Result<Option<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
|
|
|
let mut q = person::table
|
2022-07-05 21:40:44 +00:00
|
|
|
.into_boxed()
|
2023-04-25 23:28:06 +00:00
|
|
|
.filter(person::local.eq(true))
|
|
|
|
.filter(lower(person::name).eq(from_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(person::deleted.eq(false))
|
2022-07-05 21:40:44 +00:00
|
|
|
}
|
2024-04-16 12:48:15 +00:00
|
|
|
q.first(conn).await.optional()
|
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
|
|
|
person_name: &str,
|
2023-04-25 23:28:06 +00:00
|
|
|
for_domain: &str,
|
2024-04-16 12:48:15 +00:00
|
|
|
) -> Result<Option<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
|
|
|
|
|
|
|
person::table
|
|
|
|
.inner_join(instance::table)
|
|
|
|
.filter(lower(person::name).eq(person_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(person::all_columns)
|
2024-04-16 12:48:15 +00:00
|
|
|
.first(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2024-04-16 12:48:15 +00:00
|
|
|
.optional()
|
2022-01-27 16:39:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:40:47 +00:00
|
|
|
#[async_trait]
|
|
|
|
impl Followable for PersonFollower {
|
|
|
|
type Form = PersonFollowerForm;
|
2023-07-11 13:09:59 +00:00
|
|
|
async fn follow(pool: &mut DbPool<'_>, form: &PersonFollowerForm) -> Result<Self, Error> {
|
2022-11-23 23:40:47 +00:00
|
|
|
use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id};
|
|
|
|
let conn = &mut get_conn(pool).await?;
|
|
|
|
insert_into(person_follower)
|
|
|
|
.values(form)
|
|
|
|
.on_conflict((follower_id, person_id))
|
|
|
|
.do_update()
|
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
.await
|
|
|
|
}
|
2023-07-11 13:09:59 +00:00
|
|
|
async fn follow_accepted(_: &mut DbPool<'_>, _: CommunityId, _: PersonId) -> Result<Self, Error> {
|
2022-11-23 23:40:47 +00:00
|
|
|
unimplemented!()
|
|
|
|
}
|
2023-07-11 13:09:59 +00:00
|
|
|
async fn unfollow(pool: &mut DbPool<'_>, form: &PersonFollowerForm) -> 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::person_follower::dsl::person_follower;
|
2022-11-23 23:40:47 +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(person_follower.find((form.follower_id, form.person_id)))
|
|
|
|
.execute(conn)
|
|
|
|
.await
|
2022-11-23 23:40:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PersonFollower {
|
2023-04-25 23:28:06 +00:00
|
|
|
pub async fn list_followers(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2023-04-25 23:28:06 +00:00
|
|
|
for_person_id: PersonId,
|
|
|
|
) -> Result<Vec<Person>, Error> {
|
2022-11-23 23:40:47 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
|
|
|
person_follower::table
|
2023-04-17 19:19:51 +00:00
|
|
|
.inner_join(person::table.on(person_follower::follower_id.eq(person::id)))
|
2023-04-25 23:28:06 +00:00
|
|
|
.filter(person_follower::person_id.eq(for_person_id))
|
2022-11-23 23:40:47 +00:00
|
|
|
.select(person::all_columns)
|
|
|
|
.load(conn)
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
#[cfg(test)]
|
2024-03-26 09:17:42 +00:00
|
|
|
#[allow(clippy::unwrap_used)]
|
|
|
|
#[allow(clippy::indexing_slicing)]
|
2021-02-26 13:49:58 +00:00
|
|
|
mod tests {
|
2023-07-17 15:04:14 +00:00
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
use crate::{
|
2022-11-19 04:33:54 +00:00
|
|
|
source::{
|
|
|
|
instance::Instance,
|
2022-11-23 23:40:47 +00:00
|
|
|
person::{Person, PersonFollower, PersonFollowerForm, PersonInsertForm, PersonUpdateForm},
|
2022-11-19 04:33:54 +00:00
|
|
|
},
|
2022-11-23 23:40:47 +00:00
|
|
|
traits::{Crud, Followable},
|
2022-11-09 10:05:00 +00:00
|
|
|
utils::build_db_pool_for_tests,
|
2022-10-27 09:24:07 +00:00
|
|
|
};
|
2024-01-04 09:47:18 +00:00
|
|
|
use pretty_assertions::assert_eq;
|
2022-10-06 18:27:58 +00:00
|
|
|
use serial_test::serial;
|
2021-02-26 13:49:58 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
#[tokio::test]
|
2022-10-06 18:27:58 +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();
|
2021-02-26 13:49:58 +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("holly".into())
|
|
|
|
.public_key("nada".to_owned())
|
|
|
|
.instance_id(inserted_instance.id)
|
|
|
|
.build();
|
2021-02-26 13:49:58 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
2021-02-26 13:49:58 +00:00
|
|
|
|
|
|
|
let expected_person = Person {
|
|
|
|
id: inserted_person.id,
|
2021-03-11 16:54:03 +00:00
|
|
|
name: "holly".into(),
|
2021-04-01 17:57:45 +00:00
|
|
|
display_name: None,
|
2021-02-26 13:49:58 +00:00
|
|
|
avatar: None,
|
|
|
|
banner: None,
|
|
|
|
banned: false,
|
|
|
|
deleted: false,
|
|
|
|
published: inserted_person.published,
|
|
|
|
updated: None,
|
2022-11-19 04:33:54 +00:00
|
|
|
actor_id: inserted_person.actor_id.clone(),
|
2021-02-26 13:49:58 +00:00
|
|
|
bio: None,
|
|
|
|
local: true,
|
2021-04-21 21:41:14 +00:00
|
|
|
bot_account: false,
|
2021-02-26 13:49:58 +00:00
|
|
|
private_key: None,
|
2021-11-22 15:10:18 +00:00
|
|
|
public_key: "nada".to_owned(),
|
2021-02-26 13:49:58 +00:00
|
|
|
last_refreshed_at: inserted_person.published,
|
2022-11-19 04:33:54 +00:00
|
|
|
inbox_url: inserted_person.inbox_url.clone(),
|
2021-02-26 13:49:58 +00:00
|
|
|
shared_inbox_url: None,
|
2021-03-20 19:21:51 +00:00
|
|
|
matrix_user_id: None,
|
2022-01-08 12:37:07 +00:00
|
|
|
ban_expires: None,
|
2022-10-27 09:24:07 +00:00
|
|
|
instance_id: inserted_instance.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
};
|
|
|
|
|
2024-04-16 12:48:15 +00:00
|
|
|
let read_person = Person::read(pool, inserted_person.id)
|
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
.unwrap();
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2023-08-08 09:41:41 +00:00
|
|
|
let update_person_form = PersonUpdateForm {
|
|
|
|
actor_id: Some(inserted_person.actor_id.clone()),
|
|
|
|
..Default::default()
|
|
|
|
};
|
2022-11-09 10:05:00 +00:00
|
|
|
let updated_person = Person::update(pool, inserted_person.id, &update_person_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let num_deleted = Person::delete(pool, inserted_person.id).await.unwrap();
|
|
|
|
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
2021-02-26 13:49:58 +00:00
|
|
|
|
|
|
|
assert_eq!(expected_person, read_person);
|
|
|
|
assert_eq!(expected_person, inserted_person);
|
|
|
|
assert_eq!(expected_person, updated_person);
|
|
|
|
assert_eq!(1, num_deleted);
|
|
|
|
}
|
2022-11-23 23:40:47 +00:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
#[serial]
|
|
|
|
async fn follow() {
|
|
|
|
let pool = &build_db_pool_for_tests().await;
|
2023-07-11 13:09:59 +00:00
|
|
|
let pool = &mut pool.into();
|
2023-03-01 02:36:57 +00:00
|
|
|
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2022-11-23 23:40:47 +00:00
|
|
|
|
|
|
|
let person_form_1 = PersonInsertForm::builder()
|
|
|
|
.name("erich".into())
|
|
|
|
.public_key("pubkey".to_string())
|
|
|
|
.instance_id(inserted_instance.id)
|
|
|
|
.build();
|
|
|
|
let person_1 = Person::create(pool, &person_form_1).await.unwrap();
|
|
|
|
let person_form_2 = PersonInsertForm::builder()
|
|
|
|
.name("michele".into())
|
|
|
|
.public_key("pubkey".to_string())
|
|
|
|
.instance_id(inserted_instance.id)
|
|
|
|
.build();
|
|
|
|
let person_2 = Person::create(pool, &person_form_2).await.unwrap();
|
|
|
|
|
|
|
|
let follow_form = PersonFollowerForm {
|
|
|
|
person_id: person_1.id,
|
|
|
|
follower_id: person_2.id,
|
|
|
|
pending: false,
|
|
|
|
};
|
|
|
|
let person_follower = PersonFollower::follow(pool, &follow_form).await.unwrap();
|
|
|
|
assert_eq!(person_1.id, person_follower.person_id);
|
|
|
|
assert_eq!(person_2.id, person_follower.follower_id);
|
|
|
|
assert!(!person_follower.pending);
|
|
|
|
|
|
|
|
let followers = PersonFollower::list_followers(pool, person_1.id)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(vec![person_2], followers);
|
|
|
|
|
|
|
|
let unfollow = PersonFollower::unfollow(pool, &follow_form).await.unwrap();
|
|
|
|
assert_eq!(1, unfollow);
|
|
|
|
}
|
2021-02-26 13:49:58 +00:00
|
|
|
}
|