Use Comment::create_activity07() instead of create_activity()
This commit is contained in:
parent
f365041a45
commit
6cc43c2420
@ -12,7 +12,7 @@ use crate::{
|
||||
Connection, Error, Result, CONFIG,
|
||||
};
|
||||
use activitypub::{
|
||||
activity::{Create, Delete},
|
||||
activity::Delete,
|
||||
link,
|
||||
object::{Note, Tombstone},
|
||||
};
|
||||
@ -189,24 +189,6 @@ impl Comment {
|
||||
Ok(note)
|
||||
}
|
||||
|
||||
pub fn create_activity(&self, conn: &DbConn) -> Result<Create> {
|
||||
let author = User::get(conn, self.author_id)?;
|
||||
|
||||
let note = self.to_activity(conn)?;
|
||||
let mut act = Create::default();
|
||||
act.create_props.set_actor_link(author.into_id())?;
|
||||
act.create_props.set_object_object(note.clone())?;
|
||||
act.object_props.set_id_string(format!(
|
||||
"{}/activity",
|
||||
self.ap_url.clone().ok_or(Error::MissingApProperty)?,
|
||||
))?;
|
||||
act.object_props
|
||||
.set_to_link_vec(note.object_props.to_link_vec::<Id>()?)?;
|
||||
act.object_props
|
||||
.set_cc_link_vec(vec![Id::new(self.get_author(conn)?.followers_endpoint)])?;
|
||||
Ok(act)
|
||||
}
|
||||
|
||||
pub fn create_activity07(&self, conn: &DbConn) -> Result<Create07> {
|
||||
let author = User::get(conn, self.author_id)?;
|
||||
|
||||
@ -528,98 +510,6 @@ mod tests {
|
||||
(comment, posts, users, blogs)
|
||||
}
|
||||
|
||||
// creates a post, get it's Create activity, delete the post,
|
||||
// "send" the Create to the inbox, and check it works
|
||||
#[test]
|
||||
fn self_federation() {
|
||||
let conn = &db();
|
||||
conn.test_transaction::<_, (), _>(|| {
|
||||
let (original_comm, posts, users, _blogs) = prepare_activity(&conn);
|
||||
let act = original_comm.create_activity(&conn).unwrap();
|
||||
|
||||
assert_json_eq!(to_value(&act).unwrap(), json!({
|
||||
"actor": "https://plu.me/@/admin/",
|
||||
"cc": ["https://plu.me/@/admin/followers"],
|
||||
"id": format!("https://plu.me/~/BlogName/testing/comment/{}/activity", original_comm.id),
|
||||
"object": {
|
||||
"attributedTo": "https://plu.me/@/admin/",
|
||||
"content": r###"<p dir="auto">My comment, mentioning to <a href="https://plu.me/@/user/" title="user">@user</a></p>
|
||||
"###,
|
||||
"id": format!("https://plu.me/~/BlogName/testing/comment/{}", original_comm.id),
|
||||
"inReplyTo": "https://plu.me/~/BlogName/testing",
|
||||
"published": format_datetime(&original_comm.creation_date),
|
||||
"summary": "My CW",
|
||||
"tag": [
|
||||
{
|
||||
"href": "https://plu.me/@/user/",
|
||||
"name": "@user",
|
||||
"type": "Mention"
|
||||
}
|
||||
],
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Note"
|
||||
},
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Create",
|
||||
}));
|
||||
|
||||
let reply = Comment::insert(
|
||||
conn,
|
||||
NewComment {
|
||||
content: SafeString::new(""),
|
||||
in_response_to_id: Some(original_comm.id),
|
||||
post_id: posts[0].id,
|
||||
author_id: users[1].id,
|
||||
ap_url: None,
|
||||
sensitive: false,
|
||||
spoiler_text: "".into(),
|
||||
public_visibility: true,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let reply_act = reply.create_activity(&conn).unwrap();
|
||||
|
||||
assert_json_eq!(to_value(&reply_act).unwrap(), json!({
|
||||
"actor": "https://plu.me/@/user/",
|
||||
"cc": ["https://plu.me/@/user/followers"],
|
||||
"id": format!("https://plu.me/~/BlogName/testing/comment/{}/activity", reply.id),
|
||||
"object": {
|
||||
"attributedTo": "https://plu.me/@/user/",
|
||||
"content": "",
|
||||
"id": format!("https://plu.me/~/BlogName/testing/comment/{}", reply.id),
|
||||
"inReplyTo": format!("https://plu.me/~/BlogName/testing/comment/{}", original_comm.id),
|
||||
"published": format_datetime(&reply.creation_date),
|
||||
"summary": "",
|
||||
"tag": [],
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Note"
|
||||
},
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Create"
|
||||
}));
|
||||
|
||||
inbox(
|
||||
&conn,
|
||||
serde_json::to_value(original_comm.build_delete(&conn).unwrap()).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
match inbox(&conn, to_value(act).unwrap()).unwrap() {
|
||||
InboxResult::Commented(c) => {
|
||||
// TODO: one is HTML, the other markdown: assert_eq!(c.content, original_comm.content);
|
||||
assert_eq!(c.in_response_to_id, original_comm.in_response_to_id);
|
||||
assert_eq!(c.post_id, original_comm.post_id);
|
||||
assert_eq!(c.author_id, original_comm.author_id);
|
||||
assert_eq!(c.ap_url, original_comm.ap_url);
|
||||
assert_eq!(c.spoiler_text, original_comm.spoiler_text);
|
||||
assert_eq!(c.public_visibility, original_comm.public_visibility);
|
||||
}
|
||||
_ => panic!("Unexpected result"),
|
||||
};
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
// creates a post, get it's Create activity, delete the post,
|
||||
// "send" the Create to the inbox, and check it works
|
||||
#[test]
|
||||
|
@ -11,7 +11,7 @@ use std::time::Duration;
|
||||
use crate::routes::errors::ErrorPage;
|
||||
use crate::template_utils::IntoContext;
|
||||
use plume_common::{
|
||||
activity_pub::{broadcast, ActivityStream, ApRequest},
|
||||
activity_pub::{broadcast, broadcast07, ActivityStream, ApRequest},
|
||||
utils,
|
||||
};
|
||||
use plume_models::{
|
||||
@ -66,7 +66,7 @@ pub fn create(
|
||||
)
|
||||
.expect("comments::create: insert error");
|
||||
let new_comment = comm
|
||||
.create_activity(&conn)
|
||||
.create_activity07(&conn)
|
||||
.expect("comments::create: activity error");
|
||||
|
||||
// save mentions
|
||||
@ -88,7 +88,7 @@ pub fn create(
|
||||
let dest = User::one_by_instance(&conn).expect("comments::create: dest error");
|
||||
let user_clone = user.clone();
|
||||
rockets.worker.execute(move || {
|
||||
broadcast(&user_clone, new_comment, dest, CONFIG.proxy().cloned())
|
||||
broadcast07(&user_clone, new_comment, dest, CONFIG.proxy().cloned())
|
||||
});
|
||||
|
||||
Flash::success(
|
||||
|
Loading…
Reference in New Issue
Block a user