Get rid of a lot of pointless mut form initializations. (#5037)
* Get rid of a lot of pointless mut form initializations. - Fixes #5036 * Fix clippy.
This commit is contained in:
parent
25df9d255b
commit
458bb60144
14 changed files with 214 additions and 165 deletions
|
@ -63,11 +63,13 @@ async fn create_test_site(context: &Data<LemmyContext>) -> LemmyResult<(Instance
|
||||||
|
|
||||||
// Create a local site, since this is necessary for determining if email verification is
|
// Create a local site, since this is necessary for determining if email verification is
|
||||||
// required
|
// required
|
||||||
let mut local_site_form = LocalSiteInsertForm::new(site.id);
|
let local_site_form = LocalSiteInsertForm {
|
||||||
local_site_form.require_email_verification = Some(true);
|
require_email_verification: Some(true),
|
||||||
local_site_form.application_question = Some(".".to_string());
|
application_question: Some(".".to_string()),
|
||||||
local_site_form.registration_mode = Some(RegistrationMode::RequireApplication);
|
registration_mode: Some(RegistrationMode::RequireApplication),
|
||||||
local_site_form.site_setup = Some(true);
|
site_setup: Some(true),
|
||||||
|
..LocalSiteInsertForm::new(site.id)
|
||||||
|
};
|
||||||
let local_site = LocalSite::create(pool, &local_site_form).await.unwrap();
|
let local_site = LocalSite::create(pool, &local_site_form).await.unwrap();
|
||||||
|
|
||||||
// Required to have a working local SiteView when updating the site to change email verification
|
// Required to have a working local SiteView when updating the site to change email verification
|
||||||
|
|
|
@ -111,9 +111,10 @@ pub async fn create_comment(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut comment_form =
|
let comment_form = CommentInsertForm {
|
||||||
CommentInsertForm::new(local_user_view.person.id, data.post_id, content.clone());
|
language_id,
|
||||||
comment_form.language_id = language_id;
|
..CommentInsertForm::new(local_user_view.person.id, data.post_id, content.clone())
|
||||||
|
};
|
||||||
|
|
||||||
// Create the comment
|
// Create the comment
|
||||||
let parent_path = parent_opt.clone().map(|t| t.path);
|
let parent_path = parent_opt.clone().map(|t| t.path);
|
||||||
|
|
|
@ -88,23 +88,25 @@ pub async fn create_community(
|
||||||
// When you create a community, make sure the user becomes a moderator and a follower
|
// When you create a community, make sure the user becomes a moderator and a follower
|
||||||
let keypair = generate_actor_keypair()?;
|
let keypair = generate_actor_keypair()?;
|
||||||
|
|
||||||
let mut community_form = CommunityInsertForm::new(
|
let community_form = CommunityInsertForm {
|
||||||
|
description,
|
||||||
|
icon,
|
||||||
|
banner,
|
||||||
|
nsfw: data.nsfw,
|
||||||
|
actor_id: Some(community_actor_id.clone()),
|
||||||
|
private_key: Some(keypair.private_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(context.settings())?),
|
||||||
|
posting_restricted_to_mods: data.posting_restricted_to_mods,
|
||||||
|
visibility: data.visibility,
|
||||||
|
..CommunityInsertForm::new(
|
||||||
site_view.site.instance_id,
|
site_view.site.instance_id,
|
||||||
data.name.clone(),
|
data.name.clone(),
|
||||||
data.title.clone(),
|
data.title.clone(),
|
||||||
keypair.public_key,
|
keypair.public_key,
|
||||||
);
|
)
|
||||||
community_form.description = description;
|
};
|
||||||
community_form.icon = icon;
|
|
||||||
community_form.banner = banner;
|
|
||||||
community_form.nsfw = data.nsfw;
|
|
||||||
community_form.actor_id = Some(community_actor_id.clone());
|
|
||||||
community_form.private_key = Some(keypair.private_key);
|
|
||||||
community_form.followers_url = Some(generate_followers_url(&community_actor_id)?);
|
|
||||||
community_form.inbox_url = Some(generate_inbox_url(&community_actor_id)?);
|
|
||||||
community_form.shared_inbox_url = Some(generate_shared_inbox_url(context.settings())?);
|
|
||||||
community_form.posting_restricted_to_mods = data.posting_restricted_to_mods;
|
|
||||||
community_form.visibility = data.visibility;
|
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut context.pool(), &community_form)
|
let inserted_community = Community::create(&mut context.pool(), &community_form)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -130,16 +130,18 @@ pub async fn create_post(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut post_form = PostInsertForm::new(
|
let post_form = PostInsertForm {
|
||||||
|
url: url.map(Into::into),
|
||||||
|
body,
|
||||||
|
alt_text: data.alt_text.clone(),
|
||||||
|
nsfw: data.nsfw,
|
||||||
|
language_id,
|
||||||
|
..PostInsertForm::new(
|
||||||
data.name.trim().to_string(),
|
data.name.trim().to_string(),
|
||||||
local_user_view.person.id,
|
local_user_view.person.id,
|
||||||
data.community_id,
|
data.community_id,
|
||||||
);
|
)
|
||||||
post_form.url = url.map(Into::into);
|
};
|
||||||
post_form.body = body;
|
|
||||||
post_form.alt_text = data.alt_text.clone();
|
|
||||||
post_form.nsfw = data.nsfw;
|
|
||||||
post_form.language_id = language_id;
|
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut context.pool(), &post_form)
|
let inserted_post = Post::create(&mut context.pool(), &post_form)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -151,14 +151,16 @@ pub(crate) mod tests {
|
||||||
Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string()).await?;
|
Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string()).await?;
|
||||||
create_local_site(context, instance.id).await?;
|
create_local_site(context, instance.id).await?;
|
||||||
|
|
||||||
let mut community_form = CommunityInsertForm::new(
|
let community_form = CommunityInsertForm {
|
||||||
|
deleted: Some(deleted),
|
||||||
|
visibility: Some(visibility),
|
||||||
|
..CommunityInsertForm::new(
|
||||||
instance.id,
|
instance.id,
|
||||||
"testcom6".to_string(),
|
"testcom6".to_string(),
|
||||||
"nada".to_owned(),
|
"nada".to_owned(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
)
|
||||||
community_form.deleted = Some(deleted);
|
};
|
||||||
community_form.visibility = Some(visibility);
|
|
||||||
let community = Community::create(&mut context.pool(), &community_form).await?;
|
let community = Community::create(&mut context.pool(), &community_form).await?;
|
||||||
Ok((instance, community))
|
Ok((instance, community))
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,28 +151,30 @@ impl Object for ApubCommunity {
|
||||||
let icon = proxy_image_link_opt_apub(group.icon.map(|i| i.url), context).await?;
|
let icon = proxy_image_link_opt_apub(group.icon.map(|i| i.url), context).await?;
|
||||||
let banner = proxy_image_link_opt_apub(group.image.map(|i| i.url), context).await?;
|
let banner = proxy_image_link_opt_apub(group.image.map(|i| i.url), context).await?;
|
||||||
|
|
||||||
let mut form = CommunityInsertForm::new(
|
let form = CommunityInsertForm {
|
||||||
|
published: group.published,
|
||||||
|
updated: group.updated,
|
||||||
|
deleted: Some(false),
|
||||||
|
nsfw: Some(group.sensitive.unwrap_or(false)),
|
||||||
|
actor_id: Some(group.id.into()),
|
||||||
|
local: Some(false),
|
||||||
|
last_refreshed_at: Some(naive_now()),
|
||||||
|
icon,
|
||||||
|
banner,
|
||||||
|
description,
|
||||||
|
followers_url: group.followers.clone().map(Into::into),
|
||||||
|
inbox_url: Some(group.inbox.into()),
|
||||||
|
shared_inbox_url: group.endpoints.map(|e| e.shared_inbox.into()),
|
||||||
|
moderators_url: group.attributed_to.clone().map(Into::into),
|
||||||
|
posting_restricted_to_mods: group.posting_restricted_to_mods,
|
||||||
|
featured_url: group.featured.clone().map(Into::into),
|
||||||
|
..CommunityInsertForm::new(
|
||||||
instance_id,
|
instance_id,
|
||||||
group.preferred_username.clone(),
|
group.preferred_username.clone(),
|
||||||
group.name.unwrap_or(group.preferred_username.clone()),
|
group.name.unwrap_or(group.preferred_username.clone()),
|
||||||
group.public_key.public_key_pem,
|
group.public_key.public_key_pem,
|
||||||
);
|
)
|
||||||
form.published = group.published;
|
};
|
||||||
form.updated = group.updated;
|
|
||||||
form.deleted = Some(false);
|
|
||||||
form.nsfw = Some(group.sensitive.unwrap_or(false));
|
|
||||||
form.actor_id = Some(group.id.into());
|
|
||||||
form.local = Some(false);
|
|
||||||
form.last_refreshed_at = Some(naive_now());
|
|
||||||
form.icon = icon;
|
|
||||||
form.banner = banner;
|
|
||||||
form.description = description;
|
|
||||||
form.followers_url = group.followers.clone().map(Into::into);
|
|
||||||
form.inbox_url = Some(group.inbox.into());
|
|
||||||
form.shared_inbox_url = group.endpoints.map(|e| e.shared_inbox.into());
|
|
||||||
form.moderators_url = group.attributed_to.clone().map(Into::into);
|
|
||||||
form.posting_restricted_to_mods = group.posting_restricted_to_mods;
|
|
||||||
form.featured_url = group.featured.clone().map(Into::into);
|
|
||||||
let languages =
|
let languages =
|
||||||
LanguageTag::to_language_id_multiple(group.language, &mut context.pool()).await?;
|
LanguageTag::to_language_id_multiple(group.language, &mut context.pool()).await?;
|
||||||
|
|
||||||
|
|
|
@ -247,17 +247,19 @@ impl Object for ApubPost {
|
||||||
let language_id =
|
let language_id =
|
||||||
LanguageTag::to_language_id_single(page.language, &mut context.pool()).await?;
|
LanguageTag::to_language_id_single(page.language, &mut context.pool()).await?;
|
||||||
|
|
||||||
let mut form = PostInsertForm::new(name, creator.id, community.id);
|
let form = PostInsertForm {
|
||||||
form.url = url.map(Into::into);
|
url: url.map(Into::into),
|
||||||
form.body = body;
|
body,
|
||||||
form.alt_text = alt_text;
|
alt_text,
|
||||||
form.published = page.published.map(Into::into);
|
published: page.published.map(Into::into),
|
||||||
form.updated = page.updated.map(Into::into);
|
updated: page.updated.map(Into::into),
|
||||||
form.deleted = Some(false);
|
deleted: Some(false),
|
||||||
form.nsfw = page.sensitive;
|
nsfw: page.sensitive,
|
||||||
form.ap_id = Some(page.id.clone().into());
|
ap_id: Some(page.id.clone().into()),
|
||||||
form.local = Some(false);
|
local: Some(false),
|
||||||
form.language_id = language_id;
|
language_id,
|
||||||
|
..PostInsertForm::new(name, creator.id, community.id)
|
||||||
|
};
|
||||||
|
|
||||||
let timestamp = page.updated.or(page.published).unwrap_or_else(naive_now);
|
let timestamp = page.updated.or(page.published).unwrap_or_else(naive_now);
|
||||||
let post = Post::insert_apub(&mut context.pool(), timestamp, &form).await?;
|
let post = Post::insert_apub(&mut context.pool(), timestamp, &form).await?;
|
||||||
|
|
|
@ -51,8 +51,10 @@ impl Instance {
|
||||||
Some(i) => Ok(i),
|
Some(i) => Ok(i),
|
||||||
None => {
|
None => {
|
||||||
// Instance not in database yet, insert it
|
// Instance not in database yet, insert it
|
||||||
let mut form = InstanceForm::new(domain_);
|
let form = InstanceForm {
|
||||||
form.updated = Some(naive_now());
|
updated: Some(naive_now()),
|
||||||
|
..InstanceForm::new(domain_)
|
||||||
|
};
|
||||||
insert_into(instance::table)
|
insert_into(instance::table)
|
||||||
.values(&form)
|
.values(&form)
|
||||||
// Necessary because this method may be called concurrently for the same domain. This
|
// Necessary because this method may be called concurrently for the same domain. This
|
||||||
|
|
|
@ -515,53 +515,63 @@ mod tests {
|
||||||
// 3 4
|
// 3 4
|
||||||
// \
|
// \
|
||||||
// 5
|
// 5
|
||||||
let mut comment_form_0 = CommentInsertForm::new(
|
let comment_form_0 = CommentInsertForm {
|
||||||
|
language_id: english_id,
|
||||||
|
..CommentInsertForm::new(
|
||||||
inserted_timmy_person.id,
|
inserted_timmy_person.id,
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
"Comment 0".into(),
|
"Comment 0".into(),
|
||||||
);
|
)
|
||||||
comment_form_0.language_id = english_id;
|
};
|
||||||
|
|
||||||
let inserted_comment_0 = Comment::create(pool, &comment_form_0, None).await?;
|
let inserted_comment_0 = Comment::create(pool, &comment_form_0, None).await?;
|
||||||
|
|
||||||
let mut comment_form_1 = CommentInsertForm::new(
|
let comment_form_1 = CommentInsertForm {
|
||||||
|
language_id: english_id,
|
||||||
|
..CommentInsertForm::new(
|
||||||
inserted_sara_person.id,
|
inserted_sara_person.id,
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
"Comment 1, A test blocked comment".into(),
|
"Comment 1, A test blocked comment".into(),
|
||||||
);
|
)
|
||||||
comment_form_1.language_id = english_id;
|
};
|
||||||
let inserted_comment_1 =
|
let inserted_comment_1 =
|
||||||
Comment::create(pool, &comment_form_1, Some(&inserted_comment_0.path)).await?;
|
Comment::create(pool, &comment_form_1, Some(&inserted_comment_0.path)).await?;
|
||||||
|
|
||||||
let finnish_id = Language::read_id_from_code(pool, Some("fi")).await?;
|
let finnish_id = Language::read_id_from_code(pool, Some("fi")).await?;
|
||||||
let mut comment_form_2 = CommentInsertForm::new(
|
let comment_form_2 = CommentInsertForm {
|
||||||
|
language_id: finnish_id,
|
||||||
|
..CommentInsertForm::new(
|
||||||
inserted_timmy_person.id,
|
inserted_timmy_person.id,
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
"Comment 2".into(),
|
"Comment 2".into(),
|
||||||
);
|
)
|
||||||
comment_form_2.language_id = finnish_id;
|
};
|
||||||
|
|
||||||
let inserted_comment_2 =
|
let inserted_comment_2 =
|
||||||
Comment::create(pool, &comment_form_2, Some(&inserted_comment_0.path)).await?;
|
Comment::create(pool, &comment_form_2, Some(&inserted_comment_0.path)).await?;
|
||||||
|
|
||||||
let mut comment_form_3 = CommentInsertForm::new(
|
let comment_form_3 = CommentInsertForm {
|
||||||
|
language_id: english_id,
|
||||||
|
..CommentInsertForm::new(
|
||||||
inserted_timmy_person.id,
|
inserted_timmy_person.id,
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
"Comment 3".into(),
|
"Comment 3".into(),
|
||||||
);
|
)
|
||||||
comment_form_3.language_id = english_id;
|
};
|
||||||
let _inserted_comment_3 =
|
let _inserted_comment_3 =
|
||||||
Comment::create(pool, &comment_form_3, Some(&inserted_comment_1.path)).await?;
|
Comment::create(pool, &comment_form_3, Some(&inserted_comment_1.path)).await?;
|
||||||
|
|
||||||
let polish_id = Language::read_id_from_code(pool, Some("pl"))
|
let polish_id = Language::read_id_from_code(pool, Some("pl"))
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::LanguageNotAllowed)?;
|
.ok_or(LemmyErrorType::LanguageNotAllowed)?;
|
||||||
let mut comment_form_4 = CommentInsertForm::new(
|
let comment_form_4 = CommentInsertForm {
|
||||||
|
language_id: Some(polish_id),
|
||||||
|
..CommentInsertForm::new(
|
||||||
inserted_timmy_person.id,
|
inserted_timmy_person.id,
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
"Comment 4".into(),
|
"Comment 4".into(),
|
||||||
);
|
)
|
||||||
comment_form_4.language_id = Some(polish_id);
|
};
|
||||||
|
|
||||||
let inserted_comment_4 =
|
let inserted_comment_4 =
|
||||||
Comment::create(pool, &comment_form_4, Some(&inserted_comment_1.path)).await?;
|
Comment::create(pool, &comment_form_4, Some(&inserted_comment_1.path)).await?;
|
||||||
|
|
|
@ -850,12 +850,14 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut post_from_blocked_person = PostInsertForm::new(
|
let post_from_blocked_person = PostInsertForm {
|
||||||
|
language_id: Some(LanguageId(1)),
|
||||||
|
..PostInsertForm::new(
|
||||||
POST_BY_BLOCKED_PERSON.to_string(),
|
POST_BY_BLOCKED_PERSON.to_string(),
|
||||||
inserted_blocked_person.id,
|
inserted_blocked_person.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
)
|
||||||
post_from_blocked_person.language_id = Some(LanguageId(1));
|
};
|
||||||
Post::create(pool, &post_from_blocked_person).await?;
|
Post::create(pool, &post_from_blocked_person).await?;
|
||||||
|
|
||||||
// block that person
|
// block that person
|
||||||
|
@ -867,9 +869,10 @@ mod tests {
|
||||||
PersonBlock::block(pool, &person_block).await?;
|
PersonBlock::block(pool, &person_block).await?;
|
||||||
|
|
||||||
// A sample post
|
// A sample post
|
||||||
let mut new_post =
|
let new_post = PostInsertForm {
|
||||||
PostInsertForm::new(POST.to_string(), inserted_person.id, inserted_community.id);
|
language_id: Some(LanguageId(47)),
|
||||||
new_post.language_id = Some(LanguageId(47));
|
..PostInsertForm::new(POST.to_string(), inserted_person.id, inserted_community.id)
|
||||||
|
};
|
||||||
let inserted_post = Post::create(pool, &new_post).await?;
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
let new_bot_post = PostInsertForm::new(
|
let new_bot_post = PostInsertForm::new(
|
||||||
|
@ -1031,13 +1034,15 @@ mod tests {
|
||||||
let data = init_data(pool).await?;
|
let data = init_data(pool).await?;
|
||||||
|
|
||||||
// A post which contains the search them 'Post' not in the title (but in the body)
|
// A post which contains the search them 'Post' not in the title (but in the body)
|
||||||
let mut new_post = PostInsertForm::new(
|
let new_post = PostInsertForm {
|
||||||
|
language_id: Some(LanguageId(47)),
|
||||||
|
body: Some("Post".to_string()),
|
||||||
|
..PostInsertForm::new(
|
||||||
POST_WITH_ANOTHER_TITLE.to_string(),
|
POST_WITH_ANOTHER_TITLE.to_string(),
|
||||||
data.local_user_view.person.id,
|
data.local_user_view.person.id,
|
||||||
data.inserted_community.id,
|
data.inserted_community.id,
|
||||||
);
|
)
|
||||||
new_post.language_id = Some(LanguageId(47));
|
};
|
||||||
new_post.body = Some("Post".to_string());
|
|
||||||
|
|
||||||
let inserted_post = Post::create(pool, &new_post).await?;
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
|
@ -1267,12 +1272,14 @@ mod tests {
|
||||||
.await?
|
.await?
|
||||||
.expect("french should exist");
|
.expect("french should exist");
|
||||||
|
|
||||||
let mut post_spanish = PostInsertForm::new(
|
let post_spanish = PostInsertForm {
|
||||||
|
language_id: Some(spanish_id),
|
||||||
|
..PostInsertForm::new(
|
||||||
EL_POSTO.to_string(),
|
EL_POSTO.to_string(),
|
||||||
data.local_user_view.person.id,
|
data.local_user_view.person.id,
|
||||||
data.inserted_community.id,
|
data.inserted_community.id,
|
||||||
);
|
)
|
||||||
post_spanish.language_id = Some(spanish_id);
|
};
|
||||||
Post::create(pool, &post_spanish).await?;
|
Post::create(pool, &post_spanish).await?;
|
||||||
|
|
||||||
let post_listings_all = data.default_post_query().list(&data.site, pool).await?;
|
let post_listings_all = data.default_post_query().list(&data.site, pool).await?;
|
||||||
|
@ -1408,12 +1415,14 @@ mod tests {
|
||||||
);
|
);
|
||||||
let inserted_community = Community::create(pool, &community_form).await?;
|
let inserted_community = Community::create(pool, &community_form).await?;
|
||||||
|
|
||||||
let mut post_form = PostInsertForm::new(
|
let post_form = PostInsertForm {
|
||||||
|
language_id: Some(LanguageId(1)),
|
||||||
|
..PostInsertForm::new(
|
||||||
POST_FROM_BLOCKED_INSTANCE.to_string(),
|
POST_FROM_BLOCKED_INSTANCE.to_string(),
|
||||||
data.inserted_bot.id,
|
data.inserted_bot.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
)
|
||||||
post_form.language_id = Some(LanguageId(1));
|
};
|
||||||
let post_from_blocked_instance = Post::create(pool, &post_form).await?;
|
let post_from_blocked_instance = Post::create(pool, &post_form).await?;
|
||||||
|
|
||||||
// no instance block, should return all posts
|
// no instance block, should return all posts
|
||||||
|
@ -1471,14 +1480,16 @@ mod tests {
|
||||||
// and featured
|
// and featured
|
||||||
for comments in 0..10 {
|
for comments in 0..10 {
|
||||||
for _ in 0..15 {
|
for _ in 0..15 {
|
||||||
let mut post_form = PostInsertForm::new(
|
let post_form = PostInsertForm {
|
||||||
|
featured_local: Some((comments % 2) == 0),
|
||||||
|
featured_community: Some((comments % 2) == 0),
|
||||||
|
published: Some(Utc::now() - Duration::from_secs(comments % 3)),
|
||||||
|
..PostInsertForm::new(
|
||||||
"keep Christ in Christmas".to_owned(),
|
"keep Christ in Christmas".to_owned(),
|
||||||
data.local_user_view.person.id,
|
data.local_user_view.person.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
)
|
||||||
post_form.featured_local = Some((comments % 2) == 0);
|
};
|
||||||
post_form.featured_community = Some((comments % 2) == 0);
|
|
||||||
post_form.published = Some(Utc::now() - Duration::from_secs(comments % 3));
|
|
||||||
let inserted_post = Post::create(pool, &post_form).await?;
|
let inserted_post = Post::create(pool, &post_form).await?;
|
||||||
inserted_post_ids.push(inserted_post.id);
|
inserted_post_ids.push(inserted_post.id);
|
||||||
|
|
||||||
|
|
|
@ -354,8 +354,10 @@ mod test {
|
||||||
let mut data = TestData::init(1, 1).await?;
|
let mut data = TestData::init(1, 1).await?;
|
||||||
|
|
||||||
let instance = &data.instances[0];
|
let instance = &data.instances[0];
|
||||||
let mut form = InstanceForm::new(instance.domain.clone());
|
let form = InstanceForm {
|
||||||
form.updated = DateTime::from_timestamp(0, 0);
|
updated: DateTime::from_timestamp(0, 0),
|
||||||
|
..InstanceForm::new(instance.domain.clone())
|
||||||
|
};
|
||||||
Instance::update(&mut data.context.pool(), instance.id, form).await?;
|
Instance::update(&mut data.context.pool(), instance.id, form).await?;
|
||||||
|
|
||||||
data.run().await?;
|
data.run().await?;
|
||||||
|
|
|
@ -290,8 +290,10 @@ impl InstanceWorker {
|
||||||
if updated.add(Days::new(1)) < Utc::now() {
|
if updated.add(Days::new(1)) < Utc::now() {
|
||||||
self.instance.updated = Some(Utc::now());
|
self.instance.updated = Some(Utc::now());
|
||||||
|
|
||||||
let mut form = InstanceForm::new(self.instance.domain.clone());
|
let form = InstanceForm {
|
||||||
form.updated = Some(naive_now());
|
updated: Some(naive_now()),
|
||||||
|
..InstanceForm::new(self.instance.domain.clone())
|
||||||
|
};
|
||||||
Instance::update(&mut self.pool(), self.instance.id, form).await?;
|
Instance::update(&mut self.pool(), self.instance.id, form).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -485,31 +485,38 @@ async fn initialize_local_site_2022_10_10(
|
||||||
.clone()
|
.clone()
|
||||||
.map(|s| s.site_name)
|
.map(|s| s.site_name)
|
||||||
.unwrap_or_else(|| "New Site".to_string());
|
.unwrap_or_else(|| "New Site".to_string());
|
||||||
let mut site_form = SiteInsertForm::new(name, instance.id);
|
let site_form = SiteInsertForm {
|
||||||
site_form.actor_id = Some(site_actor_id.clone().into());
|
actor_id: Some(site_actor_id.clone().into()),
|
||||||
site_form.last_refreshed_at = Some(naive_now());
|
last_refreshed_at: Some(naive_now()),
|
||||||
site_form.inbox_url = Some(generate_shared_inbox_url(settings)?);
|
inbox_url: Some(generate_shared_inbox_url(settings)?),
|
||||||
site_form.private_key = Some(site_key_pair.private_key);
|
private_key: Some(site_key_pair.private_key),
|
||||||
site_form.public_key = Some(site_key_pair.public_key);
|
public_key: Some(site_key_pair.public_key),
|
||||||
|
|
||||||
|
..SiteInsertForm::new(name, instance.id)
|
||||||
|
};
|
||||||
let site = Site::create(pool, &site_form).await?;
|
let site = Site::create(pool, &site_form).await?;
|
||||||
|
|
||||||
// Finally create the local_site row
|
// Finally create the local_site row
|
||||||
let mut local_site_form = LocalSiteInsertForm::new(site.id);
|
let local_site_form = LocalSiteInsertForm {
|
||||||
local_site_form.site_setup = Some(settings.setup.is_some());
|
site_setup: Some(settings.setup.is_some()),
|
||||||
|
..LocalSiteInsertForm::new(site.id)
|
||||||
|
};
|
||||||
let local_site = LocalSite::create(pool, &local_site_form).await?;
|
let local_site = LocalSite::create(pool, &local_site_form).await?;
|
||||||
|
|
||||||
// Create the rate limit table
|
// Create the rate limit table
|
||||||
let mut local_site_rate_limit_form = LocalSiteRateLimitInsertForm::new(local_site.id);
|
let local_site_rate_limit_form = LocalSiteRateLimitInsertForm {
|
||||||
|
message: Some(999),
|
||||||
|
post: Some(999),
|
||||||
|
register: Some(999),
|
||||||
|
image: Some(999),
|
||||||
|
comment: Some(999),
|
||||||
|
search: Some(999),
|
||||||
|
..LocalSiteRateLimitInsertForm::new(local_site.id)
|
||||||
|
};
|
||||||
// TODO these have to be set, because the database defaults are too low for the federation
|
// TODO these have to be set, because the database defaults are too low for the federation
|
||||||
// tests to pass, and there's no way to live update the rate limits without restarting the
|
// tests to pass, and there's no way to live update the rate limits without restarting the
|
||||||
// server.
|
// server.
|
||||||
// This can be removed once live rate limits are enabled.
|
// This can be removed once live rate limits are enabled.
|
||||||
local_site_rate_limit_form.message = Some(999);
|
|
||||||
local_site_rate_limit_form.post = Some(999);
|
|
||||||
local_site_rate_limit_form.register = Some(999);
|
|
||||||
local_site_rate_limit_form.image = Some(999);
|
|
||||||
local_site_rate_limit_form.comment = Some(999);
|
|
||||||
local_site_rate_limit_form.search = Some(999);
|
|
||||||
LocalSiteRateLimit::create(pool, &local_site_rate_limit_form).await?;
|
LocalSiteRateLimit::create(pool, &local_site_rate_limit_form).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -493,8 +493,10 @@ async fn build_update_instance_form(
|
||||||
// not every Fediverse instance has a valid Nodeinfo endpoint (its not required for
|
// not every Fediverse instance has a valid Nodeinfo endpoint (its not required for
|
||||||
// Activitypub). That's why we always need to mark instances as updated if they are
|
// Activitypub). That's why we always need to mark instances as updated if they are
|
||||||
// alive.
|
// alive.
|
||||||
let mut instance_form = InstanceForm::new(domain.to_string());
|
let mut instance_form = InstanceForm {
|
||||||
instance_form.updated = Some(naive_now());
|
updated: Some(naive_now()),
|
||||||
|
..InstanceForm::new(domain.to_string())
|
||||||
|
};
|
||||||
|
|
||||||
// First, fetch their /.well-known/nodeinfo, then extract the correct nodeinfo link from it
|
// First, fetch their /.well-known/nodeinfo, then extract the correct nodeinfo link from it
|
||||||
let well_known_url = format!("https://{}/.well-known/nodeinfo", domain);
|
let well_known_url = format!("https://{}/.well-known/nodeinfo", domain);
|
||||||
|
|
Loading…
Reference in a new issue