mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-10 20:15:56 +00:00
Include instance blocks in settings export (#4173)
This commit is contained in:
parent
25450ea090
commit
f786df151f
2 changed files with 30 additions and 0 deletions
|
@ -14,6 +14,8 @@ use lemmy_db_schema::{
|
||||||
comment::{CommentSaved, CommentSavedForm},
|
comment::{CommentSaved, CommentSavedForm},
|
||||||
community::{CommunityFollower, CommunityFollowerForm},
|
community::{CommunityFollower, CommunityFollowerForm},
|
||||||
community_block::{CommunityBlock, CommunityBlockForm},
|
community_block::{CommunityBlock, CommunityBlockForm},
|
||||||
|
instance::Instance,
|
||||||
|
instance_block::{InstanceBlock, InstanceBlockForm},
|
||||||
local_user::{LocalUser, LocalUserUpdateForm},
|
local_user::{LocalUser, LocalUserUpdateForm},
|
||||||
person::{Person, PersonUpdateForm},
|
person::{Person, PersonUpdateForm},
|
||||||
person_block::{PersonBlock, PersonBlockForm},
|
person_block::{PersonBlock, PersonBlockForm},
|
||||||
|
@ -58,6 +60,8 @@ pub struct UserSettingsBackup {
|
||||||
pub blocked_communities: Vec<ObjectId<ApubCommunity>>,
|
pub blocked_communities: Vec<ObjectId<ApubCommunity>>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub blocked_users: Vec<ObjectId<ApubPerson>>,
|
pub blocked_users: Vec<ObjectId<ApubPerson>>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub blocked_instances: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
|
@ -78,6 +82,7 @@ pub async fn export_settings(
|
||||||
settings: Some(local_user_view.local_user),
|
settings: Some(local_user_view.local_user),
|
||||||
followed_communities: vec_into(lists.followed_communities),
|
followed_communities: vec_into(lists.followed_communities),
|
||||||
blocked_communities: vec_into(lists.blocked_communities),
|
blocked_communities: vec_into(lists.blocked_communities),
|
||||||
|
blocked_instances: lists.blocked_instances,
|
||||||
blocked_users: lists.blocked_users.into_iter().map(Into::into).collect(),
|
blocked_users: lists.blocked_users.into_iter().map(Into::into).collect(),
|
||||||
saved_posts: lists.saved_posts.into_iter().map(Into::into).collect(),
|
saved_posts: lists.saved_posts.into_iter().map(Into::into).collect(),
|
||||||
saved_comments: lists.saved_comments.into_iter().map(Into::into).collect(),
|
saved_comments: lists.saved_comments.into_iter().map(Into::into).collect(),
|
||||||
|
@ -130,6 +135,7 @@ pub async fn import_settings(
|
||||||
let url_count = data.followed_communities.len()
|
let url_count = data.followed_communities.len()
|
||||||
+ data.blocked_communities.len()
|
+ data.blocked_communities.len()
|
||||||
+ data.blocked_users.len()
|
+ data.blocked_users.len()
|
||||||
|
+ data.blocked_instances.len()
|
||||||
+ data.saved_posts.len()
|
+ data.saved_posts.len()
|
||||||
+ data.saved_comments.len();
|
+ data.saved_comments.len();
|
||||||
if url_count > MAX_API_PARAM_ELEMENTS {
|
if url_count > MAX_API_PARAM_ELEMENTS {
|
||||||
|
@ -269,6 +275,19 @@ pub async fn import_settings(
|
||||||
LemmyResult::Ok(())
|
LemmyResult::Ok(())
|
||||||
}))
|
}))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
try_join_all(data.blocked_instances.iter().map(|domain| async {
|
||||||
|
// dont fetch unknown blocked objects from home server
|
||||||
|
let instance = Instance::read_or_create(&mut context.pool(), domain.clone()).await?;
|
||||||
|
let form = InstanceBlockForm {
|
||||||
|
person_id,
|
||||||
|
instance_id: instance.id,
|
||||||
|
};
|
||||||
|
InstanceBlock::block(&mut context.pool(), &form).await?;
|
||||||
|
LemmyResult::Ok(())
|
||||||
|
}))
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,8 @@ impl LocalUser {
|
||||||
community,
|
community,
|
||||||
community_block,
|
community_block,
|
||||||
community_follower,
|
community_follower,
|
||||||
|
instance,
|
||||||
|
instance_block,
|
||||||
person,
|
person,
|
||||||
person_block,
|
person_block,
|
||||||
post,
|
post,
|
||||||
|
@ -118,6 +120,13 @@ impl LocalUser {
|
||||||
.get_results(conn)
|
.get_results(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let blocked_instances = instance_block::dsl::instance_block
|
||||||
|
.filter(instance_block::person_id.eq(person_id_))
|
||||||
|
.inner_join(instance::table)
|
||||||
|
.select(instance::domain)
|
||||||
|
.get_results(conn)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// TODO: use join for parallel queries?
|
// TODO: use join for parallel queries?
|
||||||
|
|
||||||
Ok(UserBackupLists {
|
Ok(UserBackupLists {
|
||||||
|
@ -126,6 +135,7 @@ impl LocalUser {
|
||||||
saved_comments,
|
saved_comments,
|
||||||
blocked_communities,
|
blocked_communities,
|
||||||
blocked_users,
|
blocked_users,
|
||||||
|
blocked_instances,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,6 +146,7 @@ pub struct UserBackupLists {
|
||||||
pub saved_comments: Vec<DbUrl>,
|
pub saved_comments: Vec<DbUrl>,
|
||||||
pub blocked_communities: Vec<DbUrl>,
|
pub blocked_communities: Vec<DbUrl>,
|
||||||
pub blocked_users: Vec<DbUrl>,
|
pub blocked_users: Vec<DbUrl>,
|
||||||
|
pub blocked_instances: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
|
Loading…
Reference in a new issue