~vpzom/lotide

ce8fe3941265fb086a7899518bc630718e257d10 — Colin Reeder 11 months ago 69ba9f1
Add source property to posts
5 files changed, 31 insertions(+), 13 deletions(-)

M src/apub_util.rs
M src/main.rs
M src/routes/api/comments.rs
M src/routes/api/mod.rs
M src/routes/api/posts.rs
M src/apub_util.rs => src/apub_util.rs +18 -4
@@ 981,14 981,24 @@ pub fn post_to_ap(
        K,
        O: activitystreams::object::ObjectExt<K> + activitystreams::base::BaseExt<K>,
    >(
        props: &mut O,
        props: &mut activitystreams::object::ApObject<O>,
        post: &crate::PostInfo,
    ) {
    ) -> Result<(), crate::Error> {
        if let Some(html) = post.content_html {
            props.set_content(html).set_media_type(mime::TEXT_HTML);

            if let Some(md) = post.content_markdown {
                let mut src = activitystreams::object::Object::<()>::new();
                src.set_content(md)
                    .set_media_type("text/markdown".parse().unwrap())
                    .delete_kind();
                props.set_source(src.into_any_base()?);
            }
        } else if let Some(text) = post.content_text {
            props.set_content(text).set_media_type(mime::TEXT_PLAIN);
        }

        Ok(())
    };

    match post.href {


@@ 1008,7 1018,9 @@ pub fn post_to_ap(
                .set_to(community_ap_id)
                .set_cc(activitystreams::public());

            apply_content(&mut post_ap, post);
            let mut post_ap = activitystreams::object::ApObject::new(post_ap);

            apply_content(&mut post_ap, post)?;

            Ok(post_ap.into_any_base()?)
        }


@@ 1027,7 1039,9 @@ pub fn post_to_ap(
                .set_to(community_ap_id)
                .set_cc(activitystreams::public());

            apply_content(&mut post_ap, post);
            let mut post_ap = activitystreams::object::ApObject::new(post_ap);

            apply_content(&mut post_ap, post)?;

            Ok(post_ap.into_any_base()?)
        }

M src/main.rs => src/main.rs +3 -0
@@ 86,6 86,9 @@ impl Into<activitystreams::primitives::OneOrMany<activitystreams::base::AnyBase>
    }
}

#[derive(Serialize, Default)]
pub struct Empty {}

pub type DbPool = deadpool_postgres::Pool;
pub type HttpClient = hyper::Client<hyper_tls::HttpsConnector<hyper::client::HttpConnector>>;


M src/routes/api/comments.rs => src/routes/api/comments.rs +1 -1
@@ 50,7 50,7 @@ async fn route_unstable_comments_get(
                    &[&comment_id, &user],
                ).await?;

                Some(row.map(|_| super::Empty {}))
                Some(row.map(|_| crate::Empty {}))
            } else {
                None
            })

M src/routes/api/mod.rs => src/routes/api/mod.rs +6 -5
@@ 35,9 35,6 @@ impl SortType {
}

#[derive(Serialize)]
struct Empty {}

#[derive(Serialize)]
struct JustID<T: serde::Serialize> {
    pub id: T,
}


@@ 122,7 119,7 @@ struct RespPostCommentInfo<'a> {
    replies: Option<Vec<RespPostCommentInfo<'a>>>,
    has_replies: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    your_vote: Option<Option<Empty>>,
    your_vote: Option<Option<crate::Empty>>,
}

#[derive(Serialize)]


@@ 642,7 639,11 @@ async fn get_comments_replies<'a>(
                    has_replies: false,
                    your_vote: match include_your_for {
                        None => None,
                        Some(_) => Some(if row.get(10) { Some(Empty {}) } else { None }),
                        Some(_) => Some(if row.get(10) {
                            Some(crate::Empty {})
                        } else {
                            None
                        }),
                    },
                },
            ))

M src/routes/api/posts.rs => src/routes/api/posts.rs +3 -3
@@ 76,7 76,7 @@ async fn get_post_comments<'a>(
                    your_vote: match include_your_for {
                        None => None,
                        Some(_) => Some(if row.get(9) {
                            Some(super::Empty {})
                            Some(crate::Empty {})
                        } else {
                            None
                        }),


@@ 260,7 260,7 @@ async fn route_unstable_posts_get(
        score: i64,
        comments: Vec<RespPostCommentInfo<'a>>,
        #[serde(skip_serializing_if = "Option::is_none")]
        your_vote: Option<Option<super::Empty>>,
        your_vote: Option<Option<crate::Empty>>,
    }

    let (post_id,) = params;


@@ 276,7 276,7 @@ async fn route_unstable_posts_get(
            if let Some(user) = include_your_for {
                let row = db.query_opt("SELECT 1 FROM post_like WHERE post=$1 AND person=$2", &[&post_id, &user]).await?;
                if row.is_some() {
                    Ok(Some(Some(super::Empty {})))
                    Ok(Some(Some(crate::Empty {})))
                } else {
                    Ok(Some(None))
                }