feat: add in_reply_to_url field to FeedRow and ThoughtRow, update related queries and handlers
This commit is contained in:
@@ -29,6 +29,7 @@ struct FeedRow {
|
||||
t_user_id: uuid::Uuid,
|
||||
content: String,
|
||||
in_reply_to_id: Option<uuid::Uuid>,
|
||||
in_reply_to_url: Option<String>,
|
||||
visibility: String,
|
||||
content_warning: Option<String>,
|
||||
sensitive: bool,
|
||||
@@ -57,7 +58,7 @@ fn feed_select(viewer: Option<uuid::Uuid>) -> String {
|
||||
format!(
|
||||
"\n SELECT\n\
|
||||
t.id AS thought_id, t.user_id AS t_user_id, t.content,\n\
|
||||
t.in_reply_to_id,\n\
|
||||
t.in_reply_to_id, t.in_reply_to_url,\n\
|
||||
t.visibility, t.content_warning, t.sensitive, t.local AS t_local,\n\
|
||||
t.created_at AS thought_created_at, t.updated_at AS thought_updated_at, t.note_extensions, t.mood,\n\
|
||||
u.id, u.username, u.email, u.password_hash,\n\
|
||||
@@ -78,6 +79,7 @@ fn row_to_entry(r: FeedRow, viewer: Option<uuid::Uuid>) -> Result<FeedEntry, Dom
|
||||
user_id: UserId::from_uuid(r.t_user_id),
|
||||
content: Content::new_remote(r.content),
|
||||
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||
in_reply_to_url: r.in_reply_to_url,
|
||||
visibility: Visibility::from_db_str(&r.visibility)?,
|
||||
content_warning: r.content_warning,
|
||||
sensitive: r.sensitive,
|
||||
|
||||
@@ -34,6 +34,7 @@ impl OutboxRow {
|
||||
user_id: UserId::from_uuid(self.user_id),
|
||||
content: Content::new_remote(self.content),
|
||||
in_reply_to_id: self.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||
in_reply_to_url: None,
|
||||
visibility: Visibility::Public,
|
||||
content_warning: self.content_warning,
|
||||
sensitive: self.sensitive,
|
||||
|
||||
@@ -29,6 +29,7 @@ struct FeedRow {
|
||||
t_user_id: uuid::Uuid,
|
||||
content: String,
|
||||
in_reply_to_id: Option<uuid::Uuid>,
|
||||
in_reply_to_url: Option<String>,
|
||||
visibility: String,
|
||||
content_warning: Option<String>,
|
||||
sensitive: bool,
|
||||
@@ -52,6 +53,7 @@ fn row_to_entry(r: FeedRow, viewer: Option<uuid::Uuid>) -> Result<FeedEntry, Dom
|
||||
user_id: UserId::from_uuid(r.t_user_id),
|
||||
content: Content::new_remote(r.content),
|
||||
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||
in_reply_to_url: r.in_reply_to_url,
|
||||
visibility: Visibility::from_db_str(&r.visibility)?,
|
||||
content_warning: r.content_warning,
|
||||
sensitive: r.sensitive,
|
||||
@@ -111,7 +113,7 @@ impl<'a> FeedSqlBuilder<'a> {
|
||||
"
|
||||
SELECT
|
||||
t.id AS thought_id, t.user_id AS t_user_id, t.content,
|
||||
t.in_reply_to_id,
|
||||
t.in_reply_to_id, t.in_reply_to_url,
|
||||
t.visibility, t.content_warning, t.sensitive, t.local AS t_local,
|
||||
t.created_at AS thought_created_at, t.updated_at AS thought_updated_at,
|
||||
t.note_extensions, t.mood,
|
||||
|
||||
@@ -28,6 +28,7 @@ pub(crate) struct ThoughtRow {
|
||||
pub user_id: uuid::Uuid,
|
||||
pub content: String,
|
||||
pub in_reply_to_id: Option<uuid::Uuid>,
|
||||
pub in_reply_to_url: Option<String>,
|
||||
pub visibility: String,
|
||||
pub content_warning: Option<String>,
|
||||
pub sensitive: bool,
|
||||
@@ -46,6 +47,7 @@ impl TryFrom<ThoughtRow> for Thought {
|
||||
user_id: UserId::from_uuid(r.user_id),
|
||||
content: Content::new_remote(r.content),
|
||||
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||
in_reply_to_url: r.in_reply_to_url,
|
||||
visibility: Visibility::from_db_str(&r.visibility)?,
|
||||
content_warning: r.content_warning,
|
||||
sensitive: r.sensitive,
|
||||
@@ -59,7 +61,7 @@ impl TryFrom<ThoughtRow> for Thought {
|
||||
}
|
||||
|
||||
const THOUGHT_SELECT: &str =
|
||||
"SELECT id,user_id,content,in_reply_to_id,visibility,content_warning,sensitive,local,created_at,updated_at,note_extensions,mood FROM thoughts";
|
||||
"SELECT id,user_id,content,in_reply_to_id,in_reply_to_url,visibility,content_warning,sensitive,local,created_at,updated_at,note_extensions,mood FROM thoughts";
|
||||
|
||||
#[async_trait]
|
||||
impl ThoughtRepository for PgThoughtRepository {
|
||||
@@ -121,11 +123,11 @@ impl ThoughtRepository for PgThoughtRepository {
|
||||
// Recursive CTE: fetches the root thought and all nested replies at any depth.
|
||||
sqlx::query_as::<_, ThoughtRow>(
|
||||
"WITH RECURSIVE thread AS (
|
||||
SELECT id,user_id,content,in_reply_to_id,
|
||||
SELECT id,user_id,content,in_reply_to_id,in_reply_to_url,
|
||||
visibility,content_warning,sensitive,local,created_at,updated_at,note_extensions,mood
|
||||
FROM thoughts WHERE id = $1
|
||||
UNION ALL
|
||||
SELECT t.id,t.user_id,t.content,t.in_reply_to_id,
|
||||
SELECT t.id,t.user_id,t.content,t.in_reply_to_id,t.in_reply_to_url,
|
||||
t.visibility,t.content_warning,t.sensitive,t.local,t.created_at,t.updated_at,t.note_extensions,t.mood
|
||||
FROM thoughts t JOIN thread ON t.in_reply_to_id = thread.id
|
||||
)
|
||||
|
||||
@@ -15,6 +15,7 @@ pub struct Thought {
|
||||
pub user_id: UserId,
|
||||
pub content: Content,
|
||||
pub in_reply_to_id: Option<ThoughtId>,
|
||||
pub in_reply_to_url: Option<String>,
|
||||
pub visibility: Visibility,
|
||||
pub content_warning: Option<String>,
|
||||
pub sensitive: bool,
|
||||
@@ -66,6 +67,7 @@ impl Thought {
|
||||
user_id: p.user_id,
|
||||
content: p.content,
|
||||
in_reply_to_id: p.in_reply_to_id,
|
||||
in_reply_to_url: None,
|
||||
visibility: p.visibility,
|
||||
content_warning: p.content_warning,
|
||||
sensitive: p.sensitive,
|
||||
|
||||
@@ -97,7 +97,7 @@ pub fn to_thought_response(e: &domain::models::feed::FeedEntry) -> ThoughtRespon
|
||||
content: e.thought.content.as_str().to_string(),
|
||||
author: to_user_response(&e.author),
|
||||
in_reply_to_id: e.thought.in_reply_to_id.as_ref().map(|id| id.as_uuid()),
|
||||
in_reply_to_url: None,
|
||||
in_reply_to_url: e.thought.in_reply_to_url.clone(),
|
||||
visibility: e.thought.visibility.as_str().to_string(),
|
||||
content_warning: e.thought.content_warning.clone(),
|
||||
sensitive: e.thought.sensitive,
|
||||
|
||||
Reference in New Issue
Block a user