New protected communitites feature

This commit is contained in:
Neshura 2023-12-18 11:23:47 +01:00
parent 2069345e9e
commit 080b0bf4d8
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
3 changed files with 24 additions and 4 deletions

View file

@ -236,7 +236,8 @@ async fn handle_series(
let post_id = lemmy.post(post_data).await?; let post_id = lemmy.post(post_data).await?;
if post_series_config.pin_settings.pin_new_post_community { let read = data.read().await;
if post_series_config.pin_settings.pin_new_post_community && !read.config.protected_communities.contains(&post_series_config.name) {
let pinned_posts = lemmy.get_community_pinned(community_id).await?; let pinned_posts = lemmy.get_community_pinned(community_id).await?;
if !pinned_posts.is_empty() { if !pinned_posts.is_empty() {
let community_pinned_post = &pinned_posts[0]; let community_pinned_post = &pinned_posts[0];
@ -244,17 +245,33 @@ async fn handle_series(
} }
lemmy.pin(post_id, PostFeatureType::Community).await?; lemmy.pin(post_id, PostFeatureType::Community).await?;
} }
else if read.config.protected_communities.contains(&post_series_config.name) {
let message = Message::Warning(format!("Community '{}' for Series '{}' is protected. Is this intended?", &post_series_config.name, series.slug));
if !read.messages.contains(&message) {
drop(read);
let mut write = data.write().await;
write.messages.push(message);
};
}
let read = data.read().await;
if post_series_config.pin_settings.pin_new_post_local { if post_series_config.pin_settings.pin_new_post_local {
let pinned_posts = lemmy.get_local_pinned().await?; let pinned_posts = lemmy.get_local_pinned().await?;
if !pinned_posts.is_empty() { if !pinned_posts.is_empty() {
let community_pinned_post = &pinned_posts[0]; for pinned_post in pinned_posts {
lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Local).await?; if read.config.protected_communities.contains(&pinned_post.community.name) {
continue
}
else {
let community_pinned_post = &pinned_post;
lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Local).await?;
break
}
}
} }
lemmy.pin(post_id, PostFeatureType::Local).await?; lemmy.pin(post_id, PostFeatureType::Local).await?;
} }
let read = data.read().await;
let mut series_history = read.post_history.get_series(series.slug.as_str()); let mut series_history = read.post_history.get_series(series.slug.as_str());
let mut part_history = series_history.get_part(post_part_info.as_string().as_str()); let mut part_history = series_history.get_part(post_part_info.as_string().as_str());
drop(read); drop(read);

View file

@ -6,6 +6,7 @@ pub(crate) struct Config {
pub(crate) instance: String, pub(crate) instance: String,
pub(crate) status_post_url: Option<String>, pub(crate) status_post_url: Option<String>,
pub(crate) config_reload_seconds: u32, pub(crate) config_reload_seconds: u32,
pub(crate) protected_communities: Vec<String>,
pub(crate) series: Vec<SeriesConfig>, pub(crate) series: Vec<SeriesConfig>,
} }
@ -34,6 +35,7 @@ impl Default for Config {
instance: "".to_string(), instance: "".to_string(),
status_post_url: None, status_post_url: None,
config_reload_seconds: 21600, config_reload_seconds: 21600,
protected_communities: vec![],
series: vec![] series: vec![]
} }
} }

View file

@ -42,6 +42,7 @@ impl SharedData {
instance: "".to_string(), instance: "".to_string(),
status_post_url: None, status_post_url: None,
config_reload_seconds: 0, config_reload_seconds: 0,
protected_communities: vec![],
series: vec![], series: vec![],
}, },
post_history: SeriesHistory { post_history: SeriesHistory {