Fix some federation issues (#357)

* Fix some follow issues

Fix not receiving notifications when followed by remote users
Fix imposibility to be unfollowed by Mastodon/Pleroma users (tested only against Pleroma)

* Fix notification on every post

* Fix issues with federation

Send Link instead of Object when emiting Follow request
Receive both Link and Object for Follow request
Don't panic when fetching user with no followers or posts from Pleroma
Reorder follower routes so Activity Pub one is reachable

* Generate absolute urls for mentions and tags

* Verify author when undoing activity by Link
This commit is contained in:
fdb-hiroshima
2018-12-23 11:12:15 +01:00
committed by GitHub
parent ab2998e214
commit 0ea1d57e48
10 changed files with 85 additions and 64 deletions
+4 -1
View File
@@ -91,7 +91,10 @@ impl Comment {
}
pub fn to_activity(&self, conn: &Connection) -> Note {
let (html, mentions, _hashtags) = utils::md_to_html(self.content.get().as_ref());
let (html, mentions, _hashtags) = utils::md_to_html(self.content.get().as_ref(),
&Instance::get_local(conn)
.expect("Comment::to_activity: instance error")
.public_domain);
let author = User::get(conn, self.author_id).expect("Comment::to_activity: author error");
let mut note = Note::default();
+11 -7
View File
@@ -58,13 +58,13 @@ impl Follow {
.set_actor_link::<Id>(user.clone().into_id())
.expect("Follow::to_activity: actor error");
act.follow_props
.set_object_object(user.to_activity(&*conn))
.set_object_link::<Id>(target.clone().into_id())
.expect("Follow::to_activity: object error");
act.object_props
.set_id_string(self.ap_url.clone())
.expect("Follow::to_activity: id error");
act.object_props
.set_to_link(target.clone().into_id())
.set_to_link(target.into_id())
.expect("Follow::to_activity: target error");
act.object_props
.set_cc_link_vec::<Id>(vec![])
@@ -82,14 +82,12 @@ impl Follow {
from_id: i32,
target_id: i32,
) -> Follow {
let from_url: String = from.clone().into_id().into();
let target_url: String = target.clone().into_id().into();
let res = Follow::insert(
conn,
NewFollow {
follower_id: from_id,
following_id: target_id,
ap_url: format!("{}/follow/{}", from_url, target_url),
ap_url: follow.object_props.id_string().expect("Follow::accept_follow: get id error"),
},
);
@@ -98,7 +96,7 @@ impl Follow {
accept
.object_props
.set_id_string(accept_id)
.expect("Follow::accept_follow: id error");
.expect("Follow::accept_follow: set id error");
accept
.object_props
.set_to_link(from.clone().into_id())
@@ -199,7 +197,7 @@ impl Deletable<Connection, Undo> for Follow {
.set_id_string(format!("{}/undo", self.ap_url))
.expect("Follow::delete: id error");
undo.undo_props
.set_object_object(self.to_activity(conn))
.set_object_link::<Id>(self.clone().into_id())
.expect("Follow::delete: object error");
undo
}
@@ -214,3 +212,9 @@ impl Deletable<Connection, Undo> for Follow {
}
}
}
impl IntoId for Follow {
fn into_id(self) -> Id {
Id::new(self.ap_url)
}
}
+2 -2
View File
@@ -139,8 +139,8 @@ impl Instance {
short_description: SafeString,
long_description: SafeString,
) {
let (sd, _, _) = md_to_html(short_description.as_ref());
let (ld, _, _) = md_to_html(long_description.as_ref());
let (sd, _, _) = md_to_html(short_description.as_ref(), &self.public_domain);
let (ld, _, _) = md_to_html(long_description.as_ref(), &self.public_domain);
diesel::update(self)
.set((
instances::name.eq(name),
+5 -5
View File
@@ -431,8 +431,8 @@ impl Post {
}
pub fn to_activity(&self, conn: &Connection) -> LicensedArticle {
let mut to = self.get_receivers_urls(conn);
to.push(PUBLIC_VISIBILTY.to_string());
let cc = self.get_receivers_urls(conn);
let to = vec![PUBLIC_VISIBILTY.to_string()];
let mut mentions_json = Mention::list_for_post(conn, self.id)
.into_iter()
@@ -526,7 +526,7 @@ impl Post {
.expect("Post::to_activity: to error");
article
.object_props
.set_cc_link_vec::<Id>(vec![])
.set_cc_link_vec::<Id>(cc.into_iter().map(Id::new).collect())
.expect("Post::to_activity: cc error");
let mut license = Licensed::default();
license.set_license_string(self.license.clone()).expect("Post::to_activity: license error");
@@ -627,7 +627,7 @@ impl Post {
post.license = license;
}
let mut txt_hashtags = md_to_html(&post.source)
let mut txt_hashtags = md_to_html(&post.source, "")
.2
.into_iter()
.map(|s| s.to_camel_case())
@@ -889,7 +889,7 @@ impl<'a> FromActivity<LicensedArticle, (&'a Connection, &'a Searcher)> for Post
}
// save mentions and tags
let mut hashtags = md_to_html(&post.source)
let mut hashtags = md_to_html(&post.source, "")
.2
.into_iter()
.map(|s| s.to_camel_case())
+2 -2
View File
@@ -555,7 +555,7 @@ impl User {
serde_json::from_str(text).expect("User::fetch_outbox: parsing error");
json["items"]
.as_array()
.expect("Outbox.items is not an array")
.unwrap_or(&vec![])
.into_iter()
.filter_map(|j| serde_json::from_value(j.clone()).ok())
.collect::<Vec<T>>()
@@ -587,7 +587,7 @@ impl User {
serde_json::from_str(text).expect("User::fetch_followers_ids: parsing error");
json["items"]
.as_array()
.expect("User::fetch_followers_ids: not an array error")
.unwrap_or(&vec![])
.into_iter()
.filter_map(|j| serde_json::from_value(j.clone()).ok())
.collect::<Vec<String>>()