From 079ac091ebbeb2e3e1f91fba6c93b3e11e1c5fd6 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 25 Apr 2020 11:49:15 -0400 Subject: [PATCH] Adding back in post fetching. --- server/src/apub/fetcher.rs | 22 +++++++++++++--------- server/src/apub/mod.rs | 1 + 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/server/src/apub/fetcher.rs b/server/src/apub/fetcher.rs index b8aaeaaf..e07e410b 100644 --- a/server/src/apub/fetcher.rs +++ b/server/src/apub/fetcher.rs @@ -39,6 +39,7 @@ where pub enum SearchAcceptedObjects { Person(Box), Group(Box), + Page(Box), } /// Attempt to parse the query as URL, and fetch an ActivityPub object from it. @@ -69,6 +70,10 @@ pub fn search_by_apub_id(query: &str, conn: &PgConnection) -> Result { + let p = upsert_post(&PostForm::from_apub(&p, conn)?, conn)?; + response.posts = vec![PostView::read(conn, p.id, None)?]; + } } Ok(response) } @@ -137,15 +142,14 @@ pub fn get_or_fetch_and_upsert_remote_community( } } -// TODO Maybe add post, comment searching / caching at a later time -// fn upsert_post(post_form: &PostForm, conn: &PgConnection) -> Result { -// let existing = Post::read_from_apub_id(conn, &post_form.ap_id); -// match existing { -// Err(NotFound {}) => Ok(Post::create(conn, &post_form)?), -// Ok(p) => Ok(Post::update(conn, p.id, &post_form)?), -// Err(e) => Err(Error::from(e)), -// } -// } +fn upsert_post(post_form: &PostForm, conn: &PgConnection) -> Result { + let existing = Post::read_from_apub_id(conn, &post_form.ap_id); + match existing { + Err(NotFound {}) => Ok(Post::create(conn, &post_form)?), + Ok(p) => Ok(Post::update(conn, p.id, &post_form)?), + Err(e) => Err(Error::from(e)), + } +} // TODO It should not be fetching data from a community outbox. // All posts, comments, comment likes, etc should be posts to our community_inbox diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index 9c02d107..671f8c5a 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -39,6 +39,7 @@ use crate::api::site::SearchResponse; use crate::db::community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm}; use crate::db::community_view::{CommunityFollowerView, CommunityView}; use crate::db::post::{Post, PostForm}; +use crate::db::post_view::PostView; use crate::db::user::{UserForm, User_}; use crate::db::user_view::UserView; use crate::db::{Crud, Followable, SearchType}; -- 2.44.1