~vpzom/lotide

878a4ccb1acb7967da444fe6244eddd33502c41c — Colin Reeder 10 days ago 41930ed
Add `in_your_follows` as filter for posts list
1 files changed, 15 insertions(+), 0 deletions(-)

M src/routes/api/posts.rs
M src/routes/api/posts.rs => src/routes/api/posts.rs +15 -0
@@ 228,6 228,7 @@ async fn route_unstable_posts_list(
    #[derive(Deserialize)]
    struct PostsListQuery<'a> {
        in_any_local_community: Option<bool>,
        in_your_follows: Option<bool>,
        search: Option<Cow<'a, str>>,
        #[serde(default)]
        use_aggregate_filters: bool,


@@ 309,6 310,20 @@ async fn route_unstable_posts_list(
        )
        .unwrap();
    }
    if let Some(value) = query.in_your_follows {
        if let Some(include_your_idx) = include_your_idx {
            write!(
                sql,
                " AND {}(community.id IN (SELECT community FROM community_follow WHERE accepted AND follower=${}) AND post.approved)",
                if value { "" } else { "NOT " },
                include_your_idx,
            ).unwrap();
        } else {
            return Err(crate::Error::InternalStrStatic(
                "in_your_follows can only be used with include_your=true",
            ));
        }
    }
    if let Some(value) = &query.community {
        values.push(value);
        write!(sql, " AND community.id=${} AND post.approved", values.len(),).unwrap();