From b10af9776b22fa35e45aa8f8fd6bce62ac52bb46 Mon Sep 17 00:00:00 2001 From: Bat Date: Thu, 3 May 2018 20:27:17 +0100 Subject: [PATCH] Send a Note too when publishing an article Fixes #3 --- src/models/posts.rs | 29 +++++++++++++++++++++++++++++ src/routes/posts.rs | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/src/models/posts.rs b/src/models/posts.rs index 2da6d002..59fa888a 100644 --- a/src/models/posts.rs +++ b/src/models/posts.rs @@ -98,3 +98,32 @@ impl Object for Post { }) } } + +/// ActivityPub Object to make it possible to view posts in Mastodon/Pleroma +/// and interact with them from there. +pub struct PostNote { + pub post: Post +} + +impl Object for PostNote { +fn compute_id(&self, conn: &PgConnection) -> String { + ap_url(format!("{}/{}/{}/note", BASE_URL.as_str(), self.post.get_blog(conn).actor_id, self.post.slug)) + } + + fn serialize(&self, conn: &PgConnection) -> serde_json::Value { + json!({ + "type": "Note", + "attributedTo": self.post.get_authors(conn).into_iter().map(|a| a.compute_id(conn)).collect::>(), + "content": format!("{} in {}", self.post.title, self.post.get_blog(conn).title), + // TODO: "image": "image", + // TODO: "preview": "preview", + // TODO: "published": "published", + // TODO: "replies": "replies", + // TODO: "summary": "summary", + "tag": [], + // TODO: "updated": "updated", + // TODO: "url": "url", + "to": [ PUBLIC_VISIBILTY ] + }) + } +} diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 5dcb8482..23d28023 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -58,5 +58,9 @@ fn create(blog_name: String, data: Form, user: User, conn: DbConn) let act = Create::new(&user, &post, &*conn); broadcast(&*conn, &user, act, user.get_followers(&*conn)); + let note_act = Create::new(&user, &PostNote { post: post }, &*conn); + broadcast(&*conn, &user, note_act, user.get_followers(&*conn)); + + Redirect::to(format!("/~/{}/{}", blog_name, slug).as_str()) }