Federate follower count, use string id for community

pull/722/head
Felix 2020-03-12 03:35:32 +01:00
parent 54172bd322
commit 27c07f1f84
3 changed files with 17 additions and 17 deletions

View File

@ -6,7 +6,7 @@ services:
ports: ports:
- "127.0.0.1:8540:8540" - "127.0.0.1:8540:8540"
environment: environment:
- LEMMY_HOSTNAME=localhost:8540 - LEMMY_HOSTNAME=lemmy_alpha:8540
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_alpha:5432/lemmy - LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_alpha:5432/lemmy
- LEMMY_JWT_SECRET=changeme - LEMMY_JWT_SECRET=changeme
- LEMMY_FRONT_END_DIR=/app/dist - LEMMY_FRONT_END_DIR=/app/dist
@ -32,7 +32,7 @@ services:
ports: ports:
- "127.0.0.1:8541:8541" - "127.0.0.1:8541:8541"
environment: environment:
- LEMMY_HOSTNAME=localhost:8541 - LEMMY_HOSTNAME=lemmy_beta:8541
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_beta:5432/lemmy - LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_beta:5432/lemmy
- LEMMY_JWT_SECRET=changeme - LEMMY_JWT_SECRET=changeme
- LEMMY_FRONT_END_DIR=/app/dist - LEMMY_FRONT_END_DIR=/app/dist

View File

@ -15,7 +15,7 @@ use serde::Deserialize;
impl Community { impl Community {
pub fn as_group(&self) -> Result<Group, Error> { pub fn as_group(&self) -> Result<Group, Error> {
let base_url = make_apub_endpoint("c", &self.id); let base_url = make_apub_endpoint("c", &self.name);
let mut group = Group::default(); let mut group = Group::default();
let oprops: &mut ObjectProperties = group.as_mut(); let oprops: &mut ObjectProperties = group.as_mut();

View File

@ -2,10 +2,10 @@ extern crate reqwest;
use crate::api::community::{GetCommunityResponse, ListCommunitiesResponse}; use crate::api::community::{GetCommunityResponse, ListCommunitiesResponse};
use crate::api::post::GetPosts; use crate::api::post::GetPosts;
use crate::apub::parse_apub_endpoint;
use crate::db::community_view::CommunityView; use crate::db::community_view::CommunityView;
use crate::settings::Settings; use crate::settings::Settings;
use activitystreams::actor::apub::Group; use activitystreams::actor::apub::Group;
use activitystreams::collection::apub::UnorderedCollection;
use failure::Error; use failure::Error;
// TODO: right now all of the data is requested on demand, for production we will need to store // TODO: right now all of the data is requested on demand, for production we will need to store
@ -38,6 +38,12 @@ pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse,
let instance = x[1]; let instance = x[1];
let community_uri = format!("http://{}/federation/c/{}", instance, name); let community_uri = format!("http://{}/federation/c/{}", instance, name);
let community: Group = reqwest::get(&community_uri)?.json()?; let community: Group = reqwest::get(&community_uri)?.json()?;
let followers_uri = &community
.ap_actor_props
.get_followers()
.unwrap()
.to_string();
let followers: UnorderedCollection = reqwest::get(followers_uri)?.json()?;
// TODO: looks like a bunch of data is missing from the activitypub response // 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 // TODO: i dont think simple numeric ids are going to work, we probably need something like uuids
@ -46,9 +52,7 @@ pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse,
admins: vec![], admins: vec![],
community: CommunityView { community: CommunityView {
// TODO: we need to merge id and name into a single thing (stuff like @user@instance.com) // TODO: we need to merge id and name into a single thing (stuff like @user@instance.com)
id: parse_apub_endpoint(&community.object_props.get_id().unwrap().to_string())? id: -1, //community.object_props.get_id()
.1
.parse::<i32>()?,
name, name,
title: community title: community
.object_props .object_props
@ -60,15 +64,7 @@ pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse,
.get_summary_xsd_string() .get_summary_xsd_string()
.map(|s| s.to_string()), .map(|s| s.to_string()),
category_id: -1, category_id: -1,
creator_id: parse_apub_endpoint( creator_id: -1, //community.object_props.get_attributed_to_xsd_any_uri()
&community
.object_props
.get_attributed_to_xsd_any_uri()
.unwrap()
.to_string(),
)?
.1
.parse::<i32>()?,
removed: false, removed: false,
published: community published: community
.object_props .object_props
@ -86,7 +82,11 @@ pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse,
creator_name: "".to_string(), creator_name: "".to_string(),
creator_avatar: None, creator_avatar: None,
category_name: "".to_string(), category_name: "".to_string(),
number_of_subscribers: -1, number_of_subscribers: *followers
.collection_props
.get_total_items()
.unwrap()
.as_ref() as i64, // TODO: need to use the same type
number_of_posts: -1, number_of_posts: -1,
number_of_comments: -1, number_of_comments: -1,
hot_rank: -1, hot_rank: -1,