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:
+49
-36
@@ -24,7 +24,7 @@ use serde_json;
|
||||
use std::io::Read;
|
||||
|
||||
use plume_common::activity_pub::{
|
||||
inbox::{Deletable, FromActivity, InboxError},
|
||||
inbox::{Deletable, FromActivity, InboxError, Notify},
|
||||
Id,request::Digest,
|
||||
};
|
||||
use plume_models::{
|
||||
@@ -68,7 +68,7 @@ pub trait Inbox {
|
||||
Ok(())
|
||||
}
|
||||
"Follow" => {
|
||||
Follow::from_activity(conn, serde_json::from_value(act.clone())?, actor_id);
|
||||
Follow::from_activity(conn, serde_json::from_value(act.clone())?, actor_id).notify(conn);
|
||||
Ok(())
|
||||
}
|
||||
"Like" => {
|
||||
@@ -81,44 +81,57 @@ pub trait Inbox {
|
||||
}
|
||||
"Undo" => {
|
||||
let act: Undo = serde_json::from_value(act.clone())?;
|
||||
match act.undo_props.object["type"]
|
||||
.as_str()
|
||||
.expect("Inbox::received: undo without original type error")
|
||||
{
|
||||
"Like" => {
|
||||
likes::Like::delete_id(
|
||||
&act.undo_props
|
||||
.object_object::<Like>()?
|
||||
.object_props
|
||||
.id_string()?,
|
||||
actor_id.as_ref(),
|
||||
conn,
|
||||
);
|
||||
Ok(())
|
||||
if let Some(t) = act.undo_props.object["type"].as_str() {
|
||||
match t {
|
||||
"Like" => {
|
||||
likes::Like::delete_id(
|
||||
&act.undo_props
|
||||
.object_object::<Like>()?
|
||||
.object_props
|
||||
.id_string()?,
|
||||
actor_id.as_ref(),
|
||||
conn,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
"Announce" => {
|
||||
Reshare::delete_id(
|
||||
&act.undo_props
|
||||
.object_object::<Announce>()?
|
||||
.object_props
|
||||
.id_string()?,
|
||||
actor_id.as_ref(),
|
||||
conn,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
"Follow" => {
|
||||
Follow::delete_id(
|
||||
&act.undo_props
|
||||
.object_object::<FollowAct>()?
|
||||
.object_props
|
||||
.id_string()?,
|
||||
actor_id.as_ref(),
|
||||
conn,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(InboxError::CantUndo)?,
|
||||
}
|
||||
"Announce" => {
|
||||
Reshare::delete_id(
|
||||
&act.undo_props
|
||||
.object_object::<Announce>()?
|
||||
.object_props
|
||||
.id_string()?,
|
||||
actor_id.as_ref(),
|
||||
conn,
|
||||
);
|
||||
} else {
|
||||
let link = act.undo_props.object.as_str().expect("Inbox::received: undo don't contain type and isn't Link");
|
||||
if let Some(like) = likes::Like::find_by_ap_url(conn, link) {
|
||||
likes::Like::delete_id(&like.ap_url, actor_id.as_ref(), conn);
|
||||
Ok(())
|
||||
}
|
||||
"Follow" => {
|
||||
Follow::delete_id(
|
||||
&act.undo_props
|
||||
.object_object::<FollowAct>()?
|
||||
.object_props
|
||||
.id_string()?,
|
||||
actor_id.as_ref(),
|
||||
conn,
|
||||
);
|
||||
} else if let Some(reshare) = Reshare::find_by_ap_url(conn, link) {
|
||||
Reshare::delete_id(&reshare.ap_url, actor_id.as_ref(), conn);
|
||||
Ok(())
|
||||
} else if let Some(follow) = Follow::find_by_ap_url(conn, link) {
|
||||
Follow::delete_id(&follow.ap_url, actor_id.as_ref(), conn);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(InboxError::NoType)?
|
||||
}
|
||||
_ => Err(InboxError::CantUndo)?,
|
||||
}
|
||||
}
|
||||
"Update" => {
|
||||
|
||||
@@ -12,6 +12,7 @@ use plume_models::{
|
||||
blogs::Blog,
|
||||
comments::*,
|
||||
db_conn::DbConn,
|
||||
instance::Instance,
|
||||
mentions::Mention,
|
||||
posts::Post,
|
||||
safe_string::SafeString,
|
||||
@@ -35,7 +36,7 @@ pub fn create(blog_name: String, slug: String, form: LenientForm<NewCommentForm>
|
||||
let post = Post::find_by_slug(&*conn, &slug, blog.id).ok_or(None)?;
|
||||
form.validate()
|
||||
.map(|_| {
|
||||
let (html, mentions, _hashtags) = utils::md_to_html(form.content.as_ref());
|
||||
let (html, mentions, _hashtags) = utils::md_to_html(form.content.as_ref(), &Instance::get_local(&conn).expect("comments::create: Error getting local instance").public_domain);
|
||||
let comm = Comment::insert(&*conn, NewComment {
|
||||
content: SafeString::new(html.as_ref()),
|
||||
in_response_to_id: form.responding_to,
|
||||
@@ -64,7 +65,7 @@ pub fn create(blog_name: String, slug: String, form: LenientForm<NewCommentForm>
|
||||
let comments = Comment::list_by_post(&*conn, post.id);
|
||||
|
||||
let previous = form.responding_to.map(|r| Comment::get(&*conn, r)
|
||||
.expect("posts::details_reponse: Error retrieving previous comment"));
|
||||
.expect("comments::create: Error retrieving previous comment"));
|
||||
|
||||
Some(render!(posts::details(
|
||||
&(&*conn, &intl.catalog, Some(user.clone())),
|
||||
|
||||
+2
-2
@@ -201,7 +201,7 @@ pub fn update(blog: String, slug: String, user: User, conn: DbConn, form: Lenien
|
||||
// actually it's not "Ok"…
|
||||
Ok(Redirect::to(uri!(super::blogs::details: name = blog, page = _)))
|
||||
} else {
|
||||
let (content, mentions, hashtags) = utils::md_to_html(form.content.to_string().as_ref());
|
||||
let (content, mentions, hashtags) = utils::md_to_html(form.content.to_string().as_ref(), &Instance::get_local(&conn).expect("posts::update: Error getting local instance").public_domain);
|
||||
|
||||
// update publication date if when this article is no longer a draft
|
||||
let newly_published = if !post.published && !form.draft {
|
||||
@@ -309,7 +309,7 @@ pub fn create(blog_name: String, form: LenientForm<NewPostForm>, user: User, con
|
||||
// actually it's not "Ok"…
|
||||
Ok(Redirect::to(uri!(super::blogs::details: name = blog_name, page = _)))
|
||||
} else {
|
||||
let (content, mentions, hashtags) = utils::md_to_html(form.content.to_string().as_ref());
|
||||
let (content, mentions, hashtags) = utils::md_to_html(form.content.to_string().as_ref(), &Instance::get_local(&conn).expect("posts::create: Error getting l ocal instance").public_domain);
|
||||
|
||||
let post = Post::insert(&*conn, NewPost {
|
||||
blog_id: blog.id,
|
||||
|
||||
+2
-2
@@ -164,7 +164,7 @@ pub fn follow_auth(name: String, i18n: I18n) -> Flash<Redirect> {
|
||||
)
|
||||
}
|
||||
|
||||
#[get("/@/<name>/followers?<page>")]
|
||||
#[get("/@/<name>/followers?<page>", rank = 2)]
|
||||
pub fn followers(name: String, conn: DbConn, account: Option<User>, page: Option<Page>, intl: I18n) -> Result<Ructe, Ructe> {
|
||||
let page = page.unwrap_or_default();
|
||||
let user = User::find_by_fqn(&*conn, &name).ok_or_else(|| render!(errors::not_found(&(&*conn, &intl.catalog, account.clone()))))?;
|
||||
@@ -387,7 +387,7 @@ pub fn inbox(
|
||||
})
|
||||
}
|
||||
|
||||
#[get("/@/<name>/followers")]
|
||||
#[get("/@/<name>/followers", rank = 1)]
|
||||
pub fn ap_followers(
|
||||
name: String,
|
||||
conn: DbConn,
|
||||
|
||||
Reference in New Issue
Block a user