diff --git a/src/models/post/thread.rs b/src/models/post/thread.rs deleted file mode 100644 index ab712c80..00000000 --- a/src/models/post/thread.rs +++ /dev/null @@ -1,76 +0,0 @@ -use super::PostView; -use crate::db::connectors::neo4j::get_neo4j_graph; -use crate::queries; -use crate::routes::v0::post::ThreadQuery; -use crate::types::DynError; -use neo4rs::BoltMap; -use serde::{Deserialize, Serialize}; -use utoipa::ToSchema; - -/// Represents a thread of posts, starting from the root post and including all replies. -#[derive(Serialize, Deserialize, ToSchema, Debug)] -pub struct PostThread { - pub root_post: PostView, - pub replies: Vec, -} - -impl PostThread { - /// Retrieves the thread by author ID and post ID with pagination. - pub async fn get_by_id( - author_id: &str, - post_id: &str, - endpoint_query: ThreadQuery, - ) -> Result, DynError> { - // Set the default params - let skip = endpoint_query.pagination.skip.unwrap_or(0); - let limit = endpoint_query.pagination.limit.unwrap_or(6).min(20); - let depth = endpoint_query.depth.unwrap_or(1).min(3); - let viewer_id = endpoint_query.viewer_id.as_deref(); - - // Fetch the root post view - let root_post_view = PostView::get_by_id(author_id, post_id, viewer_id, None, None).await?; - - let root_post_view = match root_post_view { - None => return Ok(None), - Some(root_post_view) => root_post_view, - }; - - // Fetch the root post and its replies from Neo4j. - let mut result; - { - let graph = get_neo4j_graph()?; - let query = queries::get::get_thread(author_id, post_id, depth, skip, limit); - let graph = graph.lock().await; - result = graph.execute(query).await?; - } - - let replies = match result.next().await? { - Some(row) => { - let replies: Vec = row.get("replies").unwrap_or(Vec::new()); - - let mut replies_view = Vec::with_capacity(replies.len()); - - for reply in replies { - let reply_id: String = reply.get("reply_id").unwrap_or(String::new()); - let reply_author_id: String = reply.get("author_id").unwrap_or(String::new()); - - // Make sure we have both variables - if !reply_id.is_empty() && !reply_author_id.is_empty() { - let reply_view = - PostView::get_by_id(&reply_author_id, &reply_id, viewer_id, None, None) - .await? - .unwrap_or_default(); - replies_view.push(reply_view); - } - } - replies_view - } - None => Vec::new(), - }; - - Ok(Some(PostThread { - root_post: root_post_view, - replies, - })) - } -} diff --git a/src/routes/v0/endpoints.rs b/src/routes/v0/endpoints.rs index edd4d8d3..706c550b 100644 --- a/src/routes/v0/endpoints.rs +++ b/src/routes/v0/endpoints.rs @@ -30,10 +30,6 @@ pub const POST_DETAILS_ROUTE: &str = concatcp!(POST_ROUTE, "/details"); pub const POST_TAGS_ROUTE: &str = concatcp!(POST_ROUTE, "/tags"); pub const POST_TAGGERS_ROUTE: &str = concatcp!(POST_ROUTE, "/taggers/{label}"); -// -- THREAD endpoints -- -const THREAD_PREFIX: &str = concatcp!(VERSION_ROUTE, "/thread"); -pub const THREAD_ROUTE: &str = concatcp!(THREAD_PREFIX, "/{author_id}/{post_id}"); - // -- STREAM endpoints -- const STREAM_PREFIX: &str = concatcp!(VERSION_ROUTE, "/stream"); // STREAM of UserView objects diff --git a/tests/watcher/posts/reply.rs b/tests/watcher/posts/reply.rs index 2f621568..6b4c95fb 100644 --- a/tests/watcher/posts/reply.rs +++ b/tests/watcher/posts/reply.rs @@ -174,17 +174,6 @@ async fn test_homeserver_post_reply() -> Result<()> { ); test.cleanup_post(&user_id, &reply_id).await?; - // let result_post = PostView::get_by_id(&user_id, &post_id, None, None, None) - // .await - // .unwrap(); - - // assert!(result_post.is_none(), "The post should have been deleted"); - - // After deletion, fetch the post thread again and confirm the reply is gone - // let thread_after_deletion = PostThread::get_by_id(&user_id, &parent_id, None, 0, 10) - // .await - // .expect("Failed to fetch post thread after deletion") - // .expect("The post thread should exist after deletion"); // Cleanup test.cleanup_user(&user_id).await?; diff --git a/tests/watcher/posts/reply_notification.rs b/tests/watcher/posts/reply_notification.rs index 4c376198..c6e57ea9 100644 --- a/tests/watcher/posts/reply_notification.rs +++ b/tests/watcher/posts/reply_notification.rs @@ -117,20 +117,9 @@ async fn test_homeserver_post_reply_notification() -> Result<()> { panic!("Expected a REPLY notification, found something else"); } - // // TODO: Impl DEL post. Assert the reply does not exist in Nexus + // DEL post. test.cleanup_post(&alice_id, &alice_reply_id).await?; test.cleanup_post(&bob_id, &bob_reply_id).await?; - // let result_post = PostView::get_by_id(&user_id, &post_id, None, None, None) - // .await - // .unwrap(); - - // assert!(result_post.is_none(), "The post should have been deleted"); - - // After deletion, fetch the post thread again and confirm the reply is gone - // let thread_after_deletion = PostThread::get_by_id(&user_id, &parent_id, None, 0, 10) - // .await - // .expect("Failed to fetch post thread after deletion") - // .expect("The post thread should exist after deletion"); // Cleanup test.cleanup_user(&alice_id).await?; diff --git a/tests/watcher/posts/repost_notification.rs b/tests/watcher/posts/repost_notification.rs index d447f2f6..491f64e6 100644 --- a/tests/watcher/posts/repost_notification.rs +++ b/tests/watcher/posts/repost_notification.rs @@ -126,17 +126,6 @@ async fn test_homeserver_post_repost_notification() -> Result<()> { // // TODO: Impl DEL post. Assert the reply does not exist in Nexus test.cleanup_post(&alice_id, &alice_reply_id).await?; test.cleanup_post(&bob_id, &bob_reply_id).await?; - // let result_post = PostView::get_by_id(&user_id, &post_id, None, None, None) - // .await - // .unwrap(); - - // assert!(result_post.is_none(), "The post should have been deleted"); - - // After deletion, fetch the post thread again and confirm the reply is gone - // let thread_after_deletion = PostThread::get_by_id(&user_id, &parent_id, None, 0, 10) - // .await - // .expect("Failed to fetch post thread after deletion") - // .expect("The post thread should exist after deletion"); // Cleanup test.cleanup_user(&alice_id).await?;