User_::read_from_apub_id(&conn, &actor_id.into())
})
.await??;
- check_community_or_site_ban(&user, &to_community, context.pool()).await?;
+ check_community_or_site_ban(&user, to_community.id, context.pool()).await?;
let any_base = activity.clone().into_any_base()?;
let actor_url = actor.actor_id();
pub(crate) async fn check_community_or_site_ban(
user: &User_,
- community: &Community,
+ community_id: i32,
pool: &DbPool,
) -> Result<(), LemmyError> {
if user.banned {
return Err(anyhow!("User is banned from site").into());
}
let user_id = user.id;
- let community_id = community.id;
let is_banned = move |conn: &'_ _| CommunityUserBanView::get(conn, user_id, community_id).is_ok();
if blocking(pool, is_banned).await? {
return Err(anyhow!("User is banned from community").into());
use lemmy_db_queries::{Crud, DbPool};
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
- community::Community,
post::Post,
user::User_,
};
let post_id = self.post_id;
let post = blocking(pool, move |conn| Post::read(conn, post_id)).await??;
- let community_id = post.community_id;
- let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
-
// Add a vector containing some important info to the "in_reply_to" field
// [post_ap_id, Option(parent_comment_ap_id)]
let mut in_reply_to_vec = vec![post.ap_id.into_inner()];
.set_many_contexts(lemmy_context()?)
.set_id(self.ap_id.to_owned().into_inner())
.set_published(convert_datetime(self.published))
- .set_many_tos(vec![community.actor_id.into_inner(), public()])
+ .set_to(public())
.set_many_in_reply_tos(in_reply_to_vec)
.set_attributed_to(creator.actor_id.into_inner());
expected_domain: Url,
request_counter: &mut i32,
) -> Result<Comment, LemmyError> {
- check_object_for_community_or_site_ban(note, context, request_counter).await?;
-
let comment: Comment =
get_object_from_apub(note, context, expected_domain, request_counter).await?;
let post_id = comment.post_id;
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
+ check_object_for_community_or_site_ban(note, post.community_id, context, request_counter)
+ .await?;
if post.locked {
// This is not very efficient because a comment gets inserted just to be deleted right
// afterwards, but it seems to be the easiest way to implement it.
pub(in crate::objects) async fn check_object_for_community_or_site_ban<T, Kind>(
object: &T,
+ community_id: i32,
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<(), LemmyError>
.as_single_xsd_any_uri()
.context(location_info!())?;
let user = get_or_fetch_and_upsert_user(user_id, context, request_counter).await?;
- let community = get_to_community(object, context, request_counter).await?;
- check_community_or_site_ban(&user, &community, context.pool()).await
+ check_community_or_site_ban(&user, community_id, context.pool()).await
}
pub(in crate::objects) async fn get_to_community<T, Kind>(
expected_domain: Url,
request_counter: &mut i32,
) -> Result<Post, LemmyError> {
- check_object_for_community_or_site_ban(page, context, request_counter).await?;
- get_object_from_apub(page, context, expected_domain, request_counter).await
+ let post: Post = get_object_from_apub(page, context, expected_domain, request_counter).await?;
+ check_object_for_community_or_site_ban(page, post.community_id, context, request_counter)
+ .await?;
+ Ok(post)
}
}