Use Post::update_activity07() instead of update_activity()
This commit is contained in:
parent
a589435f4f
commit
6cd68ab8b0
@ -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<Update> {
|
||||
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::<Id>(article.object.object_props.to_link_vec()?)?;
|
||||
act.object_props
|
||||
.set_cc_link_vec::<Id>(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<Update07> {
|
||||
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::<String>().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();
|
||||
|
@ -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)?;
|
||||
|
Loading…
Reference in New Issue
Block a user