Various federation fixes
This commit is contained in:
parent
ffb4f6e6d8
commit
6a5d806b1d
|
@ -119,7 +119,6 @@ impl Link for Id {}
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct ApSignature {
|
pub struct ApSignature {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
#[activitystreams(concrete(PublicKey), functional)]
|
#[activitystreams(concrete(PublicKey), functional)]
|
||||||
pub public_key: Option<serde_json::Value>
|
pub public_key: Option<serde_json::Value>
|
||||||
}
|
}
|
||||||
|
@ -127,15 +126,12 @@ pub struct ApSignature {
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct PublicKey {
|
pub struct PublicKey {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
#[activitystreams(concrete(String), functional)]
|
#[activitystreams(concrete(String), functional)]
|
||||||
pub id: Option<serde_json::Value>,
|
pub id: Option<serde_json::Value>,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
#[activitystreams(concrete(String), functional)]
|
#[activitystreams(concrete(String), functional)]
|
||||||
pub owner: Option<serde_json::Value>,
|
pub owner: Option<serde_json::Value>,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
#[activitystreams(concrete(String), functional)]
|
#[activitystreams(concrete(String), functional)]
|
||||||
pub public_key_pem: Option<serde_json::Value>
|
pub public_key_pem: Option<serde_json::Value>
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,12 @@ impl Follow {
|
||||||
insert!(follows, NewFollow);
|
insert!(follows, NewFollow);
|
||||||
get!(follows);
|
get!(follows);
|
||||||
|
|
||||||
|
/// from -> The one sending the follow request
|
||||||
|
/// target -> The target of the request, responding with Accept
|
||||||
pub fn accept_follow<A: Signer + IntoId + Clone, B: Clone + WithInbox + Actor>(
|
pub fn accept_follow<A: Signer + IntoId + Clone, B: Clone + WithInbox + Actor>(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
from: &A,
|
from: &B,
|
||||||
target: &B,
|
target: &A,
|
||||||
follow: FollowAct,
|
follow: FollowAct,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
target_id: i32
|
target_id: i32
|
||||||
|
@ -42,9 +44,9 @@ impl Follow {
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut accept = Accept::default();
|
let mut accept = Accept::default();
|
||||||
accept.accept_props.set_actor_link::<Id>(from.clone().into_id()).unwrap();
|
accept.accept_props.set_actor_link::<Id>(target.clone().into_id()).unwrap();
|
||||||
accept.accept_props.set_object_object(follow).unwrap();
|
accept.accept_props.set_object_object(follow).unwrap();
|
||||||
broadcast(&*from, accept, vec![target.clone()]);
|
broadcast(&*target, accept, vec![from.clone()]);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +55,7 @@ impl FromActivity<FollowAct> for Follow {
|
||||||
fn from_activity(conn: &PgConnection, follow: FollowAct, _actor: Id) -> Follow {
|
fn from_activity(conn: &PgConnection, follow: FollowAct, _actor: Id) -> Follow {
|
||||||
let from = User::from_url(conn, follow.follow_props.actor.as_str().unwrap().to_string()).unwrap();
|
let from = User::from_url(conn, follow.follow_props.actor.as_str().unwrap().to_string()).unwrap();
|
||||||
match User::from_url(conn, follow.follow_props.object.as_str().unwrap().to_string()) {
|
match User::from_url(conn, follow.follow_props.object.as_str().unwrap().to_string()) {
|
||||||
Some(u) => Follow::accept_follow(conn, &from, &u, follow, from.id, u.id),
|
Some(user) => Follow::accept_follow(conn, &from, &user, follow, from.id, user.id),
|
||||||
None => {
|
None => {
|
||||||
let blog = Blog::from_url(conn, follow.follow_props.object.as_str().unwrap().to_string()).unwrap();
|
let blog = Blog::from_url(conn, follow.follow_props.object.as_str().unwrap().to_string()).unwrap();
|
||||||
Follow::accept_follow(conn, &from, &blog, follow, from.id, blog.id)
|
Follow::accept_follow(conn, &from, &blog, follow, from.id, blog.id)
|
||||||
|
|
|
@ -122,11 +122,13 @@ impl Post {
|
||||||
.expect("Couldn't load reshares associted to post")
|
.expect("Couldn't load reshares associted to post")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_ap_url(&self, conn: &PgConnection) {
|
pub fn update_ap_url(&self, conn: &PgConnection) -> Post {
|
||||||
if self.ap_url.len() == 0 {
|
if self.ap_url.len() == 0 {
|
||||||
diesel::update(self)
|
diesel::update(self)
|
||||||
.set(posts::ap_url.eq(self.compute_id(conn)))
|
.set(posts::ap_url.eq(self.compute_id(conn)))
|
||||||
.get_result::<Post>(conn).expect("Couldn't update AP URL");
|
.get_result::<Post>(conn).expect("Couldn't update AP URL")
|
||||||
|
} else {
|
||||||
|
self.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,10 @@ impl User {
|
||||||
.send();
|
.send();
|
||||||
match req {
|
match req {
|
||||||
Ok(mut res) => {
|
Ok(mut res) => {
|
||||||
let json: CustomPerson = serde_json::from_str(&res.text().unwrap()).unwrap();
|
let text = &res.text().unwrap();
|
||||||
|
let ap_sign: ApSignature = serde_json::from_str(text).unwrap();
|
||||||
|
let mut json: CustomPerson = serde_json::from_str(text).unwrap();
|
||||||
|
json.custom_props = ap_sign; // without this workaround, publicKey is not correctly deserialized
|
||||||
Some(User::from_activity(conn, json, Url::parse(url.as_ref()).unwrap().host_str().unwrap().to_string()))
|
Some(User::from_activity(conn, json, Url::parse(url.as_ref()).unwrap().host_str().unwrap().to_string()))
|
||||||
},
|
},
|
||||||
Err(_) => None
|
Err(_) => None
|
||||||
|
@ -177,6 +180,7 @@ impl User {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
println!("User from act : {:?}", acct.custom_props);
|
||||||
User::insert(conn, NewUser {
|
User::insert(conn, NewUser {
|
||||||
username: acct.object.ap_actor_props.preferred_username_string().expect("User::from_activity: preferredUsername error"),
|
username: acct.object.ap_actor_props.preferred_username_string().expect("User::from_activity: preferredUsername error"),
|
||||||
display_name: acct.object.object_props.name_string().expect("User::from_activity: name error"),
|
display_name: acct.object.object_props.name_string().expect("User::from_activity: name error"),
|
||||||
|
@ -330,11 +334,11 @@ impl User {
|
||||||
actor.ap_actor_props.set_endpoints_endpoint(endpoints).expect("User::into_activity: endpoints error");
|
actor.ap_actor_props.set_endpoints_endpoint(endpoints).expect("User::into_activity: endpoints error");
|
||||||
|
|
||||||
let mut public_key = PublicKey::default();
|
let mut public_key = PublicKey::default();
|
||||||
public_key.set_id_string(format!("{}#main-key", self.ap_url)).expect("Blog::into_activity: publicKey.id error");
|
public_key.set_id_string(format!("{}#main-key", self.ap_url)).expect("User::into_activity: publicKey.id error");
|
||||||
public_key.set_owner_string(self.ap_url.clone()).expect("Blog::into_activity: publicKey.owner error");
|
public_key.set_owner_string(self.ap_url.clone()).expect("User::into_activity: publicKey.owner error");
|
||||||
public_key.set_public_key_pem_string(self.public_key.clone()).expect("Blog::into_activity: publicKey.publicKeyPem error");
|
public_key.set_public_key_pem_string(self.public_key.clone()).expect("User::into_activity: publicKey.publicKeyPem error");
|
||||||
let mut ap_signature = ApSignature::default();
|
let mut ap_signature = ApSignature::default();
|
||||||
ap_signature.set_public_key_publickey(public_key).expect("Blog::into_activity: publicKey error");
|
ap_signature.set_public_key_publickey(public_key).expect("User::into_activity: publicKey error");
|
||||||
|
|
||||||
CustomPerson::new(actor, ap_signature)
|
CustomPerson::new(actor, ap_signature)
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ fn create(blog_name: String, data: Form<NewPostForm>, user: User, conn: DbConn)
|
||||||
license: form.license.to_string(),
|
license: form.license.to_string(),
|
||||||
ap_url: "".to_string()
|
ap_url: "".to_string()
|
||||||
});
|
});
|
||||||
post.update_ap_url(&*conn);
|
let post = post.update_ap_url(&*conn);
|
||||||
PostAuthor::insert(&*conn, NewPostAuthor {
|
PostAuthor::insert(&*conn, NewPostAuthor {
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
author_id: user.id
|
author_id: user.id
|
||||||
|
|
Loading…
Reference in New Issue