Fix communities with broken outboxes, and use PostView. Fixes #4658

fix_community_outbox
Dessalines 1 month ago
parent cf426493e1
commit 54cd77d72c

@ -38,7 +38,7 @@ use url::Url;
impl CreateOrUpdatePage { impl CreateOrUpdatePage {
pub(crate) async fn new( pub(crate) async fn new(
post: ApubPost, post: &ApubPost,
actor: &ApubPerson, actor: &ApubPerson,
community: &ApubCommunity, community: &ApubCommunity,
kind: CreateOrUpdateType, kind: CreateOrUpdateType,
@ -51,7 +51,7 @@ impl CreateOrUpdatePage {
Ok(CreateOrUpdatePage { Ok(CreateOrUpdatePage {
actor: actor.id().into(), actor: actor.id().into(),
to: vec![public()], to: vec![public()],
object: post.into_json(context).await?, object: post.clone().into_json(context).await?,
cc: vec![community.id()], cc: vec![community.id()],
kind, kind,
id: id.clone(), id: id.clone(),
@ -66,7 +66,6 @@ impl CreateOrUpdatePage {
kind: CreateOrUpdateType, kind: CreateOrUpdateType,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> LemmyResult<()> { ) -> LemmyResult<()> {
let post = ApubPost(post);
let community_id = post.community_id; let community_id = post.community_id;
let person: ApubPerson = Person::read(&mut context.pool(), person_id) let person: ApubPerson = Person::read(&mut context.pool(), person_id)
.await? .await?
@ -78,7 +77,7 @@ impl CreateOrUpdatePage {
.into(); .into();
let create_or_update = let create_or_update =
CreateOrUpdatePage::new(post, &person, &community, kind, &context).await?; CreateOrUpdatePage::new(&post.into(), &person, &community, kind, &context).await?;
let is_mod_action = create_or_update.object.is_mod_action(&context).await?; let is_mod_action = create_or_update.object.is_mod_action(&context).await?;
let activity = AnnouncableActivities::CreateOrUpdatePost(create_or_update); let activity = AnnouncableActivities::CreateOrUpdatePost(create_or_update);
send_activity_in_community( send_activity_in_community(

@ -1,6 +1,6 @@
use crate::{ use crate::{
activity_lists::AnnouncableActivities, activity_lists::AnnouncableActivities,
objects::{community::ApubCommunity, post::ApubPost}, objects::community::ApubCommunity,
protocol::{ protocol::{
activities::{ activities::{
community::announce::AnnounceActivity, community::announce::AnnounceActivity,
@ -18,11 +18,8 @@ use activitypub_federation::{
}; };
use futures::future::join_all; use futures::future::join_all;
use lemmy_api_common::{context::LemmyContext, utils::generate_outbox_url}; use lemmy_api_common::{context::LemmyContext, utils::generate_outbox_url};
use lemmy_db_schema::{ use lemmy_db_schema::{utils::FETCH_LIMIT_MAX, SortType};
source::{person::Person, post::Post}, use lemmy_db_views::{post_view::PostQuery, structs::SiteView};
traits::Crud,
utils::FETCH_LIMIT_MAX,
};
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyResult}, error::{LemmyError, LemmyResult},
LemmyErrorType, LemmyErrorType,
@ -41,19 +38,30 @@ impl Collection for ApubCommunityOutbox {
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn read_local(owner: &Self::Owner, data: &Data<Self::DataType>) -> LemmyResult<Self::Kind> { async fn read_local(owner: &Self::Owner, data: &Data<Self::DataType>) -> LemmyResult<Self::Kind> {
let post_list: Vec<ApubPost> = Post::list_for_community(&mut data.pool(), owner.id) let site = SiteView::read_local(&mut data.pool())
.await? .await?
.into_iter() .ok_or(LemmyErrorType::LocalSiteNotSetup)?
.map(Into::into) .site;
.collect();
let post_views = PostQuery {
community_id: Some(owner.id),
sort: Some(SortType::New),
limit: Some(FETCH_LIMIT_MAX),
..Default::default()
}
.list(&site, &mut data.pool())
.await?;
let mut ordered_items = vec![]; let mut ordered_items = vec![];
for post in post_list { for post_view in post_views {
let person = Person::read(&mut data.pool(), post.creator_id) let create = CreateOrUpdatePage::new(
.await? &post_view.post.into(),
.ok_or(LemmyErrorType::CouldntFindPerson)? &post_view.creator.into(),
.into(); owner,
let create = CreateOrUpdateType::Create,
CreateOrUpdatePage::new(post, &person, owner, CreateOrUpdateType::Create, data).await?; data,
)
.await?;
let announcable = AnnouncableActivities::CreateOrUpdatePost(create); let announcable = AnnouncableActivities::CreateOrUpdatePost(create);
let announce = AnnounceActivity::new(announcable.try_into()?, owner, data)?; let announce = AnnounceActivity::new(announcable.try_into()?, owner, data)?;
ordered_items.push(announce); ordered_items.push(announce);

@ -84,22 +84,6 @@ impl Post {
.await .await
} }
pub async fn list_for_community(
pool: &mut DbPool<'_>,
the_community_id: CommunityId,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
post::table
.filter(post::community_id.eq(the_community_id))
.filter(post::deleted.eq(false))
.filter(post::removed.eq(false))
.then_order_by(post::featured_community.desc())
.then_order_by(post::published.desc())
.limit(FETCH_LIMIT_MAX)
.load::<Self>(conn)
.await
}
pub async fn list_featured_for_community( pub async fn list_featured_for_community(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
the_community_id: CommunityId, the_community_id: CommunityId,

Loading…
Cancel
Save