Compare commits

...

4 commits

Author SHA1 Message Date
Dessalines a3e2858791
Merge 6b4b56b0eb into b459949f57 2024-04-26 12:10:35 +00:00
Dessalines b459949f57 Version 0.19.4-beta.5 2024-04-25 19:59:24 -04:00
Dessalines 6b4b56b0eb Fixing tests. 2024-04-25 14:10:15 -04:00
Dessalines 54cd77d72c Fix communities with broken outboxes, and use PostView. Fixes #4658 2024-04-25 12:36:41 -04:00
7 changed files with 87 additions and 66 deletions

26
Cargo.lock generated
View file

@ -2582,7 +2582,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "lemmy_api" name = "lemmy_api"
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"actix-web", "actix-web",
@ -2611,7 +2611,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_api_common" name = "lemmy_api_common"
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"actix-web", "actix-web",
@ -2649,7 +2649,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_api_crud" name = "lemmy_api_crud"
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
dependencies = [ dependencies = [
"accept-language", "accept-language",
"activitypub_federation", "activitypub_federation",
@ -2672,7 +2672,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_apub" name = "lemmy_apub"
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"actix-web", "actix-web",
@ -2710,7 +2710,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_db_perf" name = "lemmy_db_perf"
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
@ -2725,7 +2725,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_db_schema" name = "lemmy_db_schema"
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"anyhow", "anyhow",
@ -2765,7 +2765,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_db_views" name = "lemmy_db_views"
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"chrono", "chrono",
@ -2787,7 +2787,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_db_views_actor" name = "lemmy_db_views_actor"
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
dependencies = [ dependencies = [
"chrono", "chrono",
"diesel", "diesel",
@ -2807,7 +2807,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_db_views_moderator" name = "lemmy_db_views_moderator"
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
dependencies = [ dependencies = [
"diesel", "diesel",
"diesel-async", "diesel-async",
@ -2819,7 +2819,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_federate" name = "lemmy_federate"
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"anyhow", "anyhow",
@ -2842,7 +2842,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_routes" name = "lemmy_routes"
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"actix-web", "actix-web",
@ -2867,7 +2867,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_server" name = "lemmy_server"
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"actix-cors", "actix-cors",
@ -2910,7 +2910,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_utils" name = "lemmy_utils"
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"anyhow", "anyhow",

View file

@ -1,5 +1,5 @@
[workspace.package] [workspace.package]
version = "0.19.4-beta.4" version = "0.19.4-beta.5"
edition = "2021" edition = "2021"
description = "A link aggregator for the fediverse" description = "A link aggregator for the fediverse"
license = "AGPL-3.0" license = "AGPL-3.0"
@ -88,17 +88,17 @@ unused_self = "deny"
unwrap_used = "deny" unwrap_used = "deny"
[workspace.dependencies] [workspace.dependencies]
lemmy_api = { version = "=0.19.4-beta.4", path = "./crates/api" } lemmy_api = { version = "=0.19.4-beta.5", path = "./crates/api" }
lemmy_api_crud = { version = "=0.19.4-beta.4", path = "./crates/api_crud" } lemmy_api_crud = { version = "=0.19.4-beta.5", path = "./crates/api_crud" }
lemmy_apub = { version = "=0.19.4-beta.4", path = "./crates/apub" } lemmy_apub = { version = "=0.19.4-beta.5", path = "./crates/apub" }
lemmy_utils = { version = "=0.19.4-beta.4", path = "./crates/utils", default-features = false } lemmy_utils = { version = "=0.19.4-beta.5", path = "./crates/utils", default-features = false }
lemmy_db_schema = { version = "=0.19.4-beta.4", path = "./crates/db_schema" } lemmy_db_schema = { version = "=0.19.4-beta.5", path = "./crates/db_schema" }
lemmy_api_common = { version = "=0.19.4-beta.4", path = "./crates/api_common" } lemmy_api_common = { version = "=0.19.4-beta.5", path = "./crates/api_common" }
lemmy_routes = { version = "=0.19.4-beta.4", path = "./crates/routes" } lemmy_routes = { version = "=0.19.4-beta.5", path = "./crates/routes" }
lemmy_db_views = { version = "=0.19.4-beta.4", path = "./crates/db_views" } lemmy_db_views = { version = "=0.19.4-beta.5", path = "./crates/db_views" }
lemmy_db_views_actor = { version = "=0.19.4-beta.4", path = "./crates/db_views_actor" } lemmy_db_views_actor = { version = "=0.19.4-beta.5", path = "./crates/db_views_actor" }
lemmy_db_views_moderator = { version = "=0.19.4-beta.4", path = "./crates/db_views_moderator" } lemmy_db_views_moderator = { version = "=0.19.4-beta.5", path = "./crates/db_views_moderator" }
lemmy_federate = { version = "=0.19.4-beta.4", path = "./crates/federate" } lemmy_federate = { version = "=0.19.4-beta.5", path = "./crates/federate" }
activitypub_federation = { version = "0.5.4", default-features = false, features = [ activitypub_federation = { version = "0.5.4", default-features = false, features = [
"actix-web", "actix-web",
] } ] }

View file

@ -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(

View file

@ -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);

View file

@ -128,7 +128,14 @@ pub(crate) mod tests {
use crate::protocol::objects::{group::Group, tombstone::Tombstone}; use crate::protocol::objects::{group::Group, tombstone::Tombstone};
use actix_web::body::to_bytes; use actix_web::body::to_bytes;
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{community::CommunityInsertForm, instance::Instance}, newtypes::InstanceId,
source::{
community::CommunityInsertForm,
instance::Instance,
local_site::{LocalSite, LocalSiteInsertForm},
local_site_rate_limit::{LocalSiteRateLimit, LocalSiteRateLimitInsertForm},
site::{Site, SiteInsertForm},
},
traits::Crud, traits::Crud,
CommunityVisibility, CommunityVisibility,
}; };
@ -142,6 +149,8 @@ pub(crate) mod tests {
) -> LemmyResult<(Instance, Community)> { ) -> LemmyResult<(Instance, Community)> {
let instance = let instance =
Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string()).await?; Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string()).await?;
create_local_site(context, instance.id).await?;
let community_form = CommunityInsertForm::builder() let community_form = CommunityInsertForm::builder()
.name("testcom6".to_string()) .name("testcom6".to_string())
.title("nada".to_owned()) .title("nada".to_owned())
@ -154,6 +163,28 @@ pub(crate) mod tests {
Ok((instance, community)) Ok((instance, community))
} }
/// Necessary for the community outbox fetching
async fn create_local_site(
context: &Data<LemmyContext>,
instance_id: InstanceId,
) -> LemmyResult<()> {
// Create a local site, since this is necessary for community fetching.
let site_form = SiteInsertForm::builder()
.name("test site".to_string())
.instance_id(instance_id)
.build();
let site = Site::create(&mut context.pool(), &site_form).await?;
let local_site_form = LocalSiteInsertForm::builder().site_id(site.id).build();
let local_site = LocalSite::create(&mut context.pool(), &local_site_form).await?;
let local_site_rate_limit_form = LocalSiteRateLimitInsertForm::builder()
.local_site_id(local_site.id)
.build();
LocalSiteRateLimit::create(&mut context.pool(), &local_site_rate_limit_form).await?;
Ok(())
}
async fn decode_response<T: DeserializeOwned>(res: HttpResponse) -> LemmyResult<T> { async fn decode_response<T: DeserializeOwned>(res: HttpResponse) -> LemmyResult<T> {
let body = to_bytes(res.into_body()).await.unwrap(); let body = to_bytes(res.into_body()).await.unwrap();
let body = std::str::from_utf8(&body)?; let body = std::str::from_utf8(&body)?;
@ -164,6 +195,7 @@ pub(crate) mod tests {
#[serial] #[serial]
async fn test_get_community() -> LemmyResult<()> { async fn test_get_community() -> LemmyResult<()> {
let context = LemmyContext::init_test_context().await; let context = LemmyContext::init_test_context().await;
let (instance, community) = init(false, CommunityVisibility::Public, &context).await?;
// fetch invalid community // fetch invalid community
let query = CommunityQuery { let query = CommunityQuery {
@ -172,8 +204,6 @@ pub(crate) mod tests {
let res = get_apub_community_http(query.into(), context.reset_request_count()).await; let res = get_apub_community_http(query.into(), context.reset_request_count()).await;
assert!(res.is_err()); assert!(res.is_err());
let (instance, community) = init(false, CommunityVisibility::Public, &context).await?;
// fetch valid community // fetch valid community
let query = CommunityQuery { let query = CommunityQuery {
community_name: community.name.clone(), community_name: community.name.clone(),

View file

@ -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,

@ -1 +1 @@
Subproject commit c88dd1e3b36ee1617f1b86acf94c1b7946e97cd4 Subproject commit 866e4056656755f7b31e20094b46391e6931e3e7