From: Felix Date: Sat, 29 Feb 2020 02:11:39 +0000 (+0100) Subject: Some federation improvements X-Git-Url: http://these/git/%22%7Bauthor_url%7D/README.zh.hant.md?a=commitdiff_plain;h=b854d8f3a0d484fd08bedc75e237fcc2c5eb4a67;p=lemmy.git Some federation improvements --- diff --git a/.gitignore b/.gitignore index 90972df6..3eedf03c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ ansible/inventory_dev ansible/passwords/ docker/lemmy_mine.hjson docker/dev/env_deploy.sh +docker/federation-test/volumes build/ .idea/ diff --git a/docker/federation-test/docker-compose.yml b/docker/federation-test/docker-compose.yml index 2a8b0fc3..39079d10 100644 --- a/docker/federation-test/docker-compose.yml +++ b/docker/federation-test/docker-compose.yml @@ -7,7 +7,7 @@ services: - "127.0.0.1:8540:8540" environment: - LEMMY_HOSTNAME=localhost:8540 - - LEMMY_DATABASE_URL=postgres://lemmy:password@lemmy_db_alpha:5432/lemmy + - LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_alpha:5432/lemmy - LEMMY_JWT_SECRET=changeme - LEMMY_FRONT_END_DIR=/app/dist - LEMMY_FEDERATION_ENABLED=true @@ -16,23 +16,16 @@ services: - RUST_BACKTRACE=1 restart: always depends_on: - - lemmy_db_alpha - lemmy_db_alpha: + - postgres_alpha + postgres_alpha: image: postgres:12-alpine environment: - POSTGRES_USER=lemmy - - POSTGRES_PASSWORD=${LEMMY_DATABASE_PASSWORD} + - POSTGRES_PASSWORD=password - POSTGRES_DB=lemmy volumes: - - lemmy_db_alpha:/var/lib/postgresql/data + - ./volumes/postgres_alpha:/var/lib/postgresql/data restart: always - # lemmy_pictshare_alpha: - # image: shtripok/pictshare:latest - # ports: - # - "127.0.0.1:8550:80" - # volumes: - # - lemmy_pictshare_alpha:/usr/share/nginx/html/data - # restart: always lemmy_beta: image: lemmy-federation-test:latest @@ -40,7 +33,7 @@ services: - "127.0.0.1:8541:8541" environment: - LEMMY_HOSTNAME=localhost:8541 - - LEMMY_DATABASE_URL=postgres://lemmy:password@lemmy_db_beta:5432/lemmy + - LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_beta:5432/lemmy - LEMMY_JWT_SECRET=changeme - LEMMY_FRONT_END_DIR=/app/dist - LEMMY_FEDERATION_ENABLED=true @@ -49,26 +42,13 @@ services: - RUST_BACKTRACE=1 restart: always depends_on: - - lemmy_db_beta - lemmy_db_beta: + - postgres_beta + postgres_beta: image: postgres:12-alpine environment: - POSTGRES_USER=lemmy - - POSTGRES_PASSWORD=${LEMMY_DATABASE_PASSWORD} + - POSTGRES_PASSWORD=password - POSTGRES_DB=lemmy volumes: - - lemmy_db_beta:/var/lib/postgresql/data + - ./volumes/postgres_beta:/var/lib/postgresql/data restart: always - # lemmy_pictshare_beta: - # image: shtripok/pictshare:latest - # ports: - # - "127.0.0.1:8551:80" - # volumes: - # - lemmy_pictshare_beta:/usr/share/nginx/html/data - # restart: always - -volumes: - lemmy_db_alpha: - # lemmy_pictshare_alpha: - lemmy_db_beta: - # lemmy_pictshare_beta: diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs index 32f14eeb..621d4102 100644 --- a/server/src/apub/community.rs +++ b/server/src/apub/community.rs @@ -8,6 +8,7 @@ use actix_web::body::Body; use actix_web::web::Path; use actix_web::HttpResponse; use serde::Deserialize; +use serde_json::json; impl Community { pub fn as_group(&self) -> Group { @@ -15,16 +16,18 @@ impl Community { let mut group = Group::default(); + // TODO: why the hell is this code so awkward? group.object_props.set_context_object(context()).ok(); - group.object_props.set_id_string(base_url.to_string()).ok(); + group.object_props.set_id_string(self.id.to_string()).ok(); group .object_props - .set_name_string(self.name.to_owned()) + .set_name_string(self.title.to_owned()) .ok(); group .object_props .set_published_utctime(to_datetime_utc(self.published)) .ok(); + group.object_props.attributed_to = Some(json!(self.creator_id.to_string())); if let Some(updated) = self.updated { group .object_props @@ -34,9 +37,7 @@ impl Community { if let Some(description) = &self.description { group - .object_props - .set_summary_string(description.to_string()) - .ok(); + .object_props.summary = Some(json!(description.to_string())); } group @@ -66,6 +67,7 @@ impl Community { //As we are an object, we validated that the community id was valid let community_followers = CommunityFollowerView::for_community(&connection, self.id).unwrap(); + // TODO: we definitely dont want to make our follower list public, we should only expose the count let ap_followers = community_followers .iter() .map(|follower| make_apub_endpoint("u", &follower.user_name)) diff --git a/server/src/apub/puller.rs b/server/src/apub/puller.rs index 4b899a31..b6647060 100644 --- a/server/src/apub/puller.rs +++ b/server/src/apub/puller.rs @@ -38,6 +38,7 @@ pub fn get_remote_community(identifier: String) -> Result Result().unwrap(), + name: name, + title: community.object_props.name.unwrap().as_str().unwrap().to_string(), // TODO: why does it still show !main@lemmy_beta:8541 + description: community.object_props.summary.map(|c| c.to_string()), // TODO: this has an extra quote somehow category_id: -1, - creator_id: -1, + creator_id: community.object_props.attributed_to.unwrap().as_str().unwrap().parse::().unwrap(), removed: false, - published: naive_now(), // TODO: community.object_props.published + published: naive_now(), // TODO: need to handle time conversion (or handle it in apub lib) updated: Some(naive_now()), // TODO: community.object_props.updated deleted: false, nsfw: false,