New protected communitites feature
This commit is contained in:
parent
2069345e9e
commit
080b0bf4d8
3 changed files with 24 additions and 4 deletions
|
@ -236,7 +236,8 @@ async fn handle_series(
|
|||
|
||||
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?;
|
||||
if !pinned_posts.is_empty() {
|
||||
let community_pinned_post = &pinned_posts[0];
|
||||
|
@ -244,17 +245,33 @@ async fn handle_series(
|
|||
}
|
||||
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 {
|
||||
let pinned_posts = lemmy.get_local_pinned().await?;
|
||||
if !pinned_posts.is_empty() {
|
||||
let community_pinned_post = &pinned_posts[0];
|
||||
lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Local).await?;
|
||||
for pinned_post in pinned_posts {
|
||||
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?;
|
||||
}
|
||||
|
||||
let read = data.read().await;
|
||||
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());
|
||||
drop(read);
|
||||
|
|
|
@ -6,6 +6,7 @@ pub(crate) struct Config {
|
|||
pub(crate) instance: String,
|
||||
pub(crate) status_post_url: Option<String>,
|
||||
pub(crate) config_reload_seconds: u32,
|
||||
pub(crate) protected_communities: Vec<String>,
|
||||
pub(crate) series: Vec<SeriesConfig>,
|
||||
}
|
||||
|
||||
|
@ -34,6 +35,7 @@ impl Default for Config {
|
|||
instance: "".to_string(),
|
||||
status_post_url: None,
|
||||
config_reload_seconds: 21600,
|
||||
protected_communities: vec![],
|
||||
series: vec![]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ impl SharedData {
|
|||
instance: "".to_string(),
|
||||
status_post_url: None,
|
||||
config_reload_seconds: 0,
|
||||
protected_communities: vec![],
|
||||
series: vec![],
|
||||
},
|
||||
post_history: SeriesHistory {
|
||||
|
|
Loading…
Reference in a new issue