]> Untitled Git - lemmy.git/commitdiff
Some federation improvements
authorFelix <me@nutomic.com>
Sat, 29 Feb 2020 02:11:39 +0000 (03:11 +0100)
committerFelix <me@nutomic.com>
Sat, 29 Feb 2020 02:11:39 +0000 (03:11 +0100)
.gitignore
docker/federation-test/docker-compose.yml
server/src/apub/community.rs
server/src/apub/puller.rs

index 90972df6a6469a5300832d321bb4dba62703bb20..3eedf03ca9ebffb4cea499f1849411abe0e45911 100644 (file)
@@ -3,5 +3,6 @@ ansible/inventory_dev
 ansible/passwords/
 docker/lemmy_mine.hjson
 docker/dev/env_deploy.sh
+docker/federation-test/volumes
 build/
 .idea/
index 2a8b0fc3262f278c7927b0e7aef2a01ab762c3a6..39079d106857936f71a46350219b7669c8176bb6 100644 (file)
@@ -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:
index 32f14eeb28f7309b6832c9b51555f4aa7027505c..621d410215fdd0f94057df2b2ff829b681d4f4a8 100644 (file)
@@ -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))
index 4b899a319ad77f8c752980692f6a599b9b47f000..b6647060e304df6a419664f9508bf75e04922006 100644 (file)
@@ -38,6 +38,7 @@ pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse,
   let instance = x[1];
   let community_uri = format!("http://{}/federation/c/{}", instance, name);
   let community: Group = reqwest::get(&community_uri)?.json()?;
+  dbg!(&community);
 
   // TODO: looks like a bunch of data is missing from the activitypub response
   // TODO: i dont think simple numeric ids are going to work, we probably need something like uuids
@@ -46,14 +47,17 @@ pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse,
     moderators: vec![],
     admins: vec![],
     community: CommunityView {
-      id: -1,
-      name: identifier.clone(),
-      title: identifier,
-      description: community.object_props.summary.map(|c| c.to_string()),
+      // TODO: why does the stupid library have everything stored as value without working autocomplete for methods???
+      //       i want to pull that whole lib in here and treat it as part of lemmy so we can fix this shit
+      // TODO: we need to merge id and name into a single thing (stuff like @user@instance.com)
+      id: community.object_props.id.unwrap().as_str().unwrap().parse::<i32>().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::<i32>().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,