Various minor federation improvements

This commit is contained in:
Felix 2020-02-29 18:38:47 +01:00
parent 7cdf167e4b
commit 1f29e91796
4 changed files with 33 additions and 39 deletions

View file

@ -1,14 +1,15 @@
FROM ekidd/rust-musl-builder:1.38.0-openssl11
USER root
RUN mkdir /app/dist/documentation/ -p \
&& addgroup --gid 1001 lemmy \
&& adduser --disabled-password --shell /bin/sh -u 1001 --ingroup lemmy lemmy
# Copy resources
COPY server/config/defaults.hjson /app/config/defaults.hjson
COPY server/target/debug/lemmy_server /app/lemmy
COPY ui/dist /app/dist
COPY server/target/debug/lemmy_server /app/lemmy
USER root
RUN mkdir /app/dist/documentation/
RUN addgroup --gid 1001 lemmy
RUN adduser --disabled-password --shell /bin/sh -u 1001 --ingroup lemmy lemmy
RUN chown lemmy:lemmy /app/ -R
USER lemmy
EXPOSE 8536

View file

@ -18,6 +18,7 @@ impl Community {
// TODO: why the hell is this code so awkward?
group.object_props.set_context_object(context()).ok();
// TODO: id really needs to be a url
group.object_props.set_id_string(self.id.to_string()).ok();
group
.object_props
@ -64,17 +65,12 @@ impl Community {
let connection = establish_unpooled_connection();
//As we are an object, we validated that the community id was valid
// TODO: add a method that only returns count for better performance
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))
.collect();
collection
.collection_props
.set_items_string_vec(ap_followers)
.set_total_items_u64(community_followers.len() as u64)
.unwrap();
collection
}

View file

@ -96,9 +96,14 @@ mod tests {
pub fn make_apub_endpoint<S: Display, T: Display>(point: S, value: T) -> String {
format!(
"https://{}/federation/{}/{}",
"{}://{}/federation/{}/{}",
get_apub_protocol_string(),
Settings::get().hostname,
point,
value
)
}
pub fn get_apub_protocol_string() -> &'static str {
"http"
}

View file

@ -7,6 +7,7 @@ use crate::api::post::GetPosts;
use crate::db::community_view::CommunityView;
use crate::naive_now;
use crate::settings::Settings;
use serde_json::Value;
// TODO: right now all of the data is requested on demand, for production we will need to store
// things in the local database to not ruin the performance
@ -32,7 +33,7 @@ pub fn get_remote_community_posts(name: String) -> Result<GetPosts, Error> {
unimplemented!()
}
pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse, Error> {
pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse, failure::Error> {
let x: Vec<&str> = identifier.split('@').collect();
let name = x[0].replace("!", "");
let instance = x[1];
@ -48,34 +49,13 @@ pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse,
admins: vec![],
community: CommunityView {
// 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(),
id: get_string_value(community.object_props.id).parse::<i32>()?,
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
title: get_string_value(community.object_props.name),
description: get_string_value_opt(community.object_props.summary),
category_id: -1,
creator_id: community
.object_props
.attributed_to
.unwrap()
.as_str()
.unwrap()
.parse::<i32>()
.unwrap(),
creator_id: get_string_value(community.object_props.attributed_to).parse::<i32>()?,
removed: false,
published: naive_now(), // TODO: need to handle time conversion (or handle it in apub lib)
updated: Some(naive_now()), // TODO: community.object_props.updated
@ -95,6 +75,18 @@ pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse,
})
}
fn get_string_value_opt(value: Option<Value>) -> Option<String> {
value
.as_ref()
.map(Value::as_str)
.flatten()
.map(str::to_string)
}
fn get_string_value(value: Option<Value>) -> String {
get_string_value_opt(value).unwrap()
}
pub fn get_following_instances() -> Result<Vec<String>, Error> {
let instance_list = match Settings::get().federated_instance.clone() {
Some(f) => vec![f, Settings::get().hostname.clone()],