From 6cd68ab8b062d8591af6b18b0f041253029c10f7 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Mon, 2 May 2022 22:23:12 +0900 Subject: [PATCH] Use Post::update_activity07() instead of update_activity() --- plume-models/src/posts.rs | 86 +-------------------------------------- src/api/posts.rs | 6 +-- 2 files changed, 4 insertions(+), 88 deletions(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 3ffec9b1..57f40df5 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -4,7 +4,7 @@ use crate::{ Connection, Error, PostEvent::*, Result, CONFIG, POST_CHAN, }; use activitypub::{ - activity::{Delete, Update}, + activity::Delete, object::{Article, Image, Tombstone}, CustomObject, }; @@ -510,24 +510,6 @@ impl Post { Ok(act) } - pub fn update_activity(&self, conn: &Connection) -> Result { - let article = self.to_activity(conn)?; - let mut act = Update::default(); - act.object_props.set_id_string(format!( - "{}/update-{}", - self.ap_url, - Utc::now().timestamp() - ))?; - act.object_props - .set_to_link_vec::(article.object.object_props.to_link_vec()?)?; - act.object_props - .set_cc_link_vec::(article.object.object_props.cc_link_vec()?)?; - act.update_props - .set_actor_link(Id::new(self.get_authors(conn)?[0].clone().ap_url))?; - act.update_props.set_object_object(article)?; - Ok(act) - } - pub fn update_activity07(&self, conn: &Connection) -> Result { let article = self.to_activity07(conn)?; let to = article.to().ok_or(Error::MissingApProperty)?.clone(); @@ -1435,72 +1417,6 @@ mod tests { }); } - #[test] - fn update_activity() { - let conn = db(); - conn.test_transaction::<_, Error, _>(|| { - let (post, _mention, _posts, _users, _blogs) = prepare_activity(&conn); - let act = post.update_activity(&conn)?; - - let expected = json!({ - "actor": "https://plu.me/@/admin/", - "cc": [], - "id": "https://plu.me/~/BlogName/testing/update-", - "object": { - "attributedTo": ["https://plu.me/@/admin/", "https://plu.me/~/BlogName/"], - "cc": [], - "content": "Hello", - "id": "https://plu.me/~/BlogName/testing", - "license": "WTFPL", - "name": "Testing", - "published": format_datetime(&post.creation_date), - "source": { - "content": "Hello", - "mediaType": "text/markdown" - }, - "summary": "Bye", - "tag": [ - { - "href": "https://plu.me/@/user/", - "name": "@user", - "type": "Mention" - } - ], - "to": ["https://www.w3.org/ns/activitystreams#Public"], - "type": "Article", - "url": "https://plu.me/~/BlogName/testing" - }, - "to": ["https://www.w3.org/ns/activitystreams#Public"], - "type": "Update" - }); - let actual = to_value(act)?; - - let id = actual["id"].to_string(); - let (id_pre, id_post) = id.rsplit_once("-").unwrap(); - assert_eq!(post.ap_url, "https://plu.me/~/BlogName/testing"); - assert_eq!( - id_pre, - to_value("\"https://plu.me/~/BlogName/testing/update") - .unwrap() - .as_str() - .unwrap() - ); - assert_eq!(id_post.len(), 11); - assert_eq!( - id_post.matches(char::is_numeric).collect::().len(), - 10 - ); - for (key, value) in actual.as_object().unwrap().into_iter() { - if key == "id" { - continue; - } - assert_json_eq!(value, expected.get(key).unwrap()); - } - - Ok(()) - }); - } - #[test] fn update_activity07() { let conn = db(); diff --git a/src/api/posts.rs b/src/api/posts.rs index 56c80da9..a1dcb639 100644 --- a/src/api/posts.rs +++ b/src/api/posts.rs @@ -3,7 +3,7 @@ use rocket_contrib::json::Json; use crate::api::{authorization::*, Api, ApiError}; use plume_api::posts::*; -use plume_common::{activity_pub::broadcast, utils::md_to_html}; +use plume_common::{activity_pub::broadcast07, utils::md_to_html}; use plume_models::{ blogs::Blog, db_conn::DbConn, instance::Instance, medias::Media, mentions::*, post_authors::*, posts::*, safe_string::SafeString, tags::*, timeline::*, users::User, Error, PlumeRocket, @@ -200,9 +200,9 @@ pub fn create( )?; } - let act = post.create_activity(&conn)?; + let act = post.create_activity07(&conn)?; let dest = User::one_by_instance(&conn)?; - worker.execute(move || broadcast(&author, act, dest, CONFIG.proxy().cloned())); + worker.execute(move || broadcast07(&author, act, dest, CONFIG.proxy().cloned())); } Timeline::add_to_all_timelines(&conn, &post, Kind::Original)?;