Some federation improvements

pull/722/head
Felix 2020-02-29 03:11:39 +01:00
parent f9443dfbd3
commit b854d8f3a0
4 changed files with 28 additions and 41 deletions

1
.gitignore vendored
View 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/

View 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:

View 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))

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