Add a source property to posts
To store the Markdown
This commit is contained in:
parent
b99e34f624
commit
7152d714ae
2
migrations/2018-09-06-182637_posts_add_source/down.sql
Normal file
2
migrations/2018-09-06-182637_posts_add_source/down.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
-- This file should undo anything in `up.sql`
|
||||||
|
ALTER TABLE posts DROP COLUMN source;
|
2
migrations/2018-09-06-182637_posts_add_source/up.sql
Normal file
2
migrations/2018-09-06-182637_posts_add_source/up.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
-- Your SQL goes here
|
||||||
|
ALTER TABLE posts ADD COLUMN source TEXT NOT NULL DEFAULT '';
|
@ -175,3 +175,13 @@ pub struct Hashtag {
|
|||||||
#[activitystreams(concrete(String), functional)]
|
#[activitystreams(concrete(String), functional)]
|
||||||
pub name: Option<serde_json::Value>,
|
pub name: Option<serde_json::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct Source {
|
||||||
|
pub media_type: String,
|
||||||
|
|
||||||
|
pub content: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Object for Source {}
|
||||||
|
@ -9,7 +9,7 @@ use heck::KebabCase;
|
|||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
use plume_common::activity_pub::{
|
use plume_common::activity_pub::{
|
||||||
Hashtag,
|
Hashtag, Source,
|
||||||
PUBLIC_VISIBILTY, Id, IntoId,
|
PUBLIC_VISIBILTY, Id, IntoId,
|
||||||
inbox::{Deletable, FromActivity}
|
inbox::{Deletable, FromActivity}
|
||||||
};
|
};
|
||||||
@ -37,6 +37,7 @@ pub struct Post {
|
|||||||
pub creation_date: NaiveDateTime,
|
pub creation_date: NaiveDateTime,
|
||||||
pub ap_url: String,
|
pub ap_url: String,
|
||||||
pub subtitle: String,
|
pub subtitle: String,
|
||||||
|
pub source: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable)]
|
#[derive(Insertable)]
|
||||||
@ -51,6 +52,7 @@ pub struct NewPost {
|
|||||||
pub creation_date: Option<NaiveDateTime>,
|
pub creation_date: Option<NaiveDateTime>,
|
||||||
pub ap_url: String,
|
pub ap_url: String,
|
||||||
pub subtitle: String,
|
pub subtitle: String,
|
||||||
|
pub source: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Post {
|
impl Post {
|
||||||
@ -239,6 +241,10 @@ impl Post {
|
|||||||
authors.push(self.get_blog(conn).into_id()); // add the blog URL here too
|
authors.push(self.get_blog(conn).into_id()); // add the blog URL here too
|
||||||
article.object_props.set_attributed_to_link_vec::<Id>(authors).expect("Article::into_activity: attributedTo error");
|
article.object_props.set_attributed_to_link_vec::<Id>(authors).expect("Article::into_activity: attributedTo error");
|
||||||
article.object_props.set_content_string(self.content.get().clone()).expect("Article::into_activity: content error");
|
article.object_props.set_content_string(self.content.get().clone()).expect("Article::into_activity: content error");
|
||||||
|
article.ap_object_props.set_source_object(Source {
|
||||||
|
content: self.source.clone(),
|
||||||
|
media_type: String::from("text/markdown"),
|
||||||
|
}).expect("Article::into_activity: source error");
|
||||||
article.object_props.set_published_utctime(Utc.from_utc_datetime(&self.creation_date)).expect("Article::into_activity: published error");
|
article.object_props.set_published_utctime(Utc.from_utc_datetime(&self.creation_date)).expect("Article::into_activity: published error");
|
||||||
article.object_props.set_summary_string(self.subtitle.clone()).expect("Article::into_activity: summary error");
|
article.object_props.set_summary_string(self.subtitle.clone()).expect("Article::into_activity: summary error");
|
||||||
article.object_props.tag = Some(json!(mentions_json.append(&mut tags_json)));
|
article.object_props.tag = Some(json!(mentions_json.append(&mut tags_json)));
|
||||||
@ -308,7 +314,8 @@ impl FromActivity<Article, PgConnection> for Post {
|
|||||||
// FIXME: This is wrong: with this logic, we may use the display URL as the AP ID. We need two different fields
|
// FIXME: This is wrong: with this logic, we may use the display URL as the AP ID. We need two different fields
|
||||||
ap_url: article.object_props.url_string().unwrap_or(article.object_props.id_string().expect("Post::from_activity: url + id error")),
|
ap_url: article.object_props.url_string().unwrap_or(article.object_props.id_string().expect("Post::from_activity: url + id error")),
|
||||||
creation_date: Some(article.object_props.published_utctime().expect("Post::from_activity: published error").naive_utc()),
|
creation_date: Some(article.object_props.published_utctime().expect("Post::from_activity: published error").naive_utc()),
|
||||||
subtitle: article.object_props.summary_string().expect("Post::from_activity: summary error")
|
subtitle: article.object_props.summary_string().expect("Post::from_activity: summary error"),
|
||||||
|
source: article.ap_object_props.source_object::<Source>().expect("Post::from_activity: source error").content
|
||||||
});
|
});
|
||||||
|
|
||||||
for author in authors.into_iter() {
|
for author in authors.into_iter() {
|
||||||
|
@ -126,6 +126,7 @@ table! {
|
|||||||
creation_date -> Timestamp,
|
creation_date -> Timestamp,
|
||||||
ap_url -> Varchar,
|
ap_url -> Varchar,
|
||||||
subtitle -> Text,
|
subtitle -> Text,
|
||||||
|
source -> Text,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,8 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
|
|||||||
},
|
},
|
||||||
ap_url: "".to_string(),
|
ap_url: "".to_string(),
|
||||||
creation_date: None,
|
creation_date: None,
|
||||||
subtitle: form.subtitle.clone()
|
subtitle: form.subtitle.clone(),
|
||||||
|
source: form.content.clone(),
|
||||||
});
|
});
|
||||||
let post = post.update_ap_url(&*conn);
|
let post = post.update_ap_url(&*conn);
|
||||||
PostAuthor::insert(&*conn, NewPostAuthor {
|
PostAuthor::insert(&*conn, NewPostAuthor {
|
||||||
|
Loading…
Reference in New Issue
Block a user