mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
Merge branch 'main' into clippy_fix_2
This commit is contained in:
commit
b47a474863
5 changed files with 63 additions and 9 deletions
|
@ -24,6 +24,7 @@ use lemmy_db_schema::{
|
||||||
self,
|
self,
|
||||||
source::{
|
source::{
|
||||||
community::Community,
|
community::Community,
|
||||||
|
moderator::{ModLockPost, ModLockPostForm, ModStickyPost, ModStickyPostForm},
|
||||||
person::Person,
|
person::Person,
|
||||||
post::{Post, PostForm},
|
post::{Post, PostForm},
|
||||||
},
|
},
|
||||||
|
@ -161,8 +162,6 @@ impl ApubObject for ApubPost {
|
||||||
.await?;
|
.await?;
|
||||||
let community = page.extract_community(context, request_counter).await?;
|
let community = page.extract_community(context, request_counter).await?;
|
||||||
|
|
||||||
// TODO: write mod log if stickied or locked changed
|
|
||||||
|
|
||||||
let url = if let Some(attachment) = page.attachment.first() {
|
let url = if let Some(attachment) = page.attachment.first() {
|
||||||
Some(attachment.href.clone())
|
Some(attachment.href.clone())
|
||||||
} else {
|
} else {
|
||||||
|
@ -177,9 +176,9 @@ impl ApubObject for ApubPost {
|
||||||
let (embed_title, embed_description, embed_html) = metadata_res
|
let (embed_title, embed_description, embed_html) = metadata_res
|
||||||
.map(|u| (u.title, u.description, u.html))
|
.map(|u| (u.title, u.description, u.html))
|
||||||
.unwrap_or((None, None, None));
|
.unwrap_or((None, None, None));
|
||||||
|
|
||||||
let body_slurs_removed = read_from_string_or_source_opt(&page.content, &page.source)
|
let body_slurs_removed = read_from_string_or_source_opt(&page.content, &page.source)
|
||||||
.map(|s| remove_slurs(&s, &context.settings().slur_regex()));
|
.map(|s| remove_slurs(&s, &context.settings().slur_regex()));
|
||||||
|
|
||||||
let form = PostForm {
|
let form = PostForm {
|
||||||
name: page.name.clone(),
|
name: page.name.clone(),
|
||||||
url: url.map(Into::into),
|
url: url.map(Into::into),
|
||||||
|
@ -197,10 +196,38 @@ impl ApubObject for ApubPost {
|
||||||
embed_description,
|
embed_description,
|
||||||
embed_html,
|
embed_html,
|
||||||
thumbnail_url: pictrs_thumbnail.map(|u| u.into()),
|
thumbnail_url: pictrs_thumbnail.map(|u| u.into()),
|
||||||
ap_id: Some(page.id.into()),
|
ap_id: Some(page.id.clone().into()),
|
||||||
local: Some(false),
|
local: Some(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// read existing, local post if any (for generating mod log)
|
||||||
|
let old_post = ObjectId::<ApubPost>::new(page.id.clone())
|
||||||
|
.dereference_local(context)
|
||||||
|
.await;
|
||||||
|
|
||||||
let post = blocking(context.pool(), move |conn| Post::upsert(conn, &form)).await??;
|
let post = blocking(context.pool(), move |conn| Post::upsert(conn, &form)).await??;
|
||||||
|
|
||||||
|
// write mod log entries for sticky/lock
|
||||||
|
if Page::is_stickied_changed(&old_post, &page.stickied) {
|
||||||
|
let form = ModStickyPostForm {
|
||||||
|
mod_person_id: creator.id,
|
||||||
|
post_id: post.id,
|
||||||
|
stickied: Some(post.stickied),
|
||||||
|
};
|
||||||
|
blocking(context.pool(), move |conn| {
|
||||||
|
ModStickyPost::create(conn, &form)
|
||||||
|
})
|
||||||
|
.await??;
|
||||||
|
}
|
||||||
|
if Page::is_locked_changed(&old_post, &page.comments_enabled) {
|
||||||
|
let form = ModLockPostForm {
|
||||||
|
mod_person_id: creator.id,
|
||||||
|
post_id: post.id,
|
||||||
|
locked: Some(post.locked),
|
||||||
|
};
|
||||||
|
blocking(context.pool(), move |conn| ModLockPost::create(conn, &form)).await??;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(post.into())
|
Ok(post.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,14 +75,37 @@ impl Page {
|
||||||
.dereference_local(context)
|
.dereference_local(context)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let is_mod_action = if let Ok(old_post) = old_post {
|
let is_mod_action = Page::is_stickied_changed(&old_post, &self.stickied)
|
||||||
self.stickied != Some(old_post.stickied) || self.comments_enabled != Some(!old_post.locked)
|
|| Page::is_locked_changed(&old_post, &self.comments_enabled);
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
Ok(is_mod_action)
|
Ok(is_mod_action)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn is_stickied_changed<E>(
|
||||||
|
old_post: &Result<ApubPost, E>,
|
||||||
|
new_stickied: &Option<bool>,
|
||||||
|
) -> bool {
|
||||||
|
if let Some(new_stickied) = new_stickied {
|
||||||
|
if let Ok(old_post) = old_post {
|
||||||
|
return new_stickied != &old_post.stickied;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn is_locked_changed<E>(
|
||||||
|
old_post: &Result<ApubPost, E>,
|
||||||
|
new_comments_enabled: &Option<bool>,
|
||||||
|
) -> bool {
|
||||||
|
if let Some(new_comments_enabled) = new_comments_enabled {
|
||||||
|
if let Ok(old_post) = old_post {
|
||||||
|
return new_comments_enabled != &!old_post.locked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) async fn extract_community(
|
pub(crate) async fn extract_community(
|
||||||
&self,
|
&self,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
|
|
|
@ -7,6 +7,7 @@ set -e
|
||||||
|
|
||||||
mkdir -p volumes/pictrs
|
mkdir -p volumes/pictrs
|
||||||
sudo chown -R 991:991 volumes/pictrs
|
sudo chown -R 991:991 volumes/pictrs
|
||||||
|
sudo docker-compose down
|
||||||
sudo docker build ../../ --file ../dev/Dockerfile -t lemmy-dev:latest
|
sudo docker build ../../ --file ../dev/Dockerfile -t lemmy-dev:latest
|
||||||
sudo docker-compose pull --ignore-pull-failures || true
|
sudo docker-compose pull --ignore-pull-failures || true
|
||||||
sudo docker-compose up -d
|
sudo docker-compose up -d
|
||||||
|
|
|
@ -7,6 +7,7 @@ set -e
|
||||||
|
|
||||||
mkdir -p volumes/pictrs
|
mkdir -p volumes/pictrs
|
||||||
sudo chown -R 991:991 volumes/pictrs
|
sudo chown -R 991:991 volumes/pictrs
|
||||||
|
sudo docker-compose down
|
||||||
sudo docker build ../../ --file ../dev/volume_mount.dockerfile -t lemmy-dev:latest
|
sudo docker build ../../ --file ../dev/volume_mount.dockerfile -t lemmy-dev:latest
|
||||||
sudo docker-compose pull --ignore-pull-failures || true
|
sudo docker-compose pull --ignore-pull-failures || true
|
||||||
sudo docker-compose up
|
sudo docker-compose up
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
sudo docker-compose down
|
||||||
|
|
||||||
sudo docker build ../../ --file ../dev/volume_mount.dockerfile -t lemmy-federation:latest
|
sudo docker build ../../ --file ../dev/volume_mount.dockerfile -t lemmy-federation:latest
|
||||||
|
|
||||||
for Item in alpha beta gamma delta epsilon ; do
|
for Item in alpha beta gamma delta epsilon ; do
|
||||||
|
|
Loading…
Reference in a new issue