From 0d3bd3cf03b85ea8217ca44f96e6369c72aca0d3 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Tue, 5 Dec 2023 12:18:01 +0100 Subject: [PATCH] httpd: Add comment edits to serialized json This allows the display of any edits done to comments, replies and issue descriptions. This commit doesn't remove the body property which is the latest comment body but adds a edits property. Also adds an author property to the `Edit` struct, which allows us to see the author of an edit action. --- radicle-httpd/src/api/json.rs | 12 +++ radicle-httpd/src/api/v1/projects.rs | 137 ++++++++++++++++++++++++++- radicle-httpd/src/test.rs | 1 + 3 files changed, 149 insertions(+), 1 deletion(-) diff --git a/radicle-httpd/src/api/json.rs b/radicle-httpd/src/api/json.rs index 63f956a9a..318afba3f 100644 --- a/radicle-httpd/src/api/json.rs +++ b/radicle-httpd/src/api/json.rs @@ -242,6 +242,7 @@ struct Comment<'a> { id: CommentId, author: Value, body: &'a str, + edits: Vec, embeds: Vec>, reactions: Vec<(&'a ActorId, &'a Reaction)>, #[serde(with = "radicle::serde_ext::localtime::time")] @@ -257,6 +258,17 @@ impl<'a> Comment<'a> { id: *id, author: author(&comment_author, aliases.alias(comment_author.id())), body: comment.body(), + edits: comment + .edits() + .map(|edit| { + json!({ + "author": author(&Author::from(edit.author), aliases.alias(&edit.author)), + "body": edit.body, + "timestamp": edit.timestamp, + "embeds": edit.embeds, + }) + }) + .collect::>(), embeds: comment.embeds().to_vec(), reactions: comment.reactions().collect::>(), timestamp: comment.timestamp(), diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index e75b11d68..b1d564608 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -1995,6 +1995,16 @@ mod routes { "id": DID }, "body": "Change 'hello world' to 'hello everyone'", + "edits": [ + { + "author": { + "id": DID, + }, + "body": "Change 'hello world' to 'hello everyone'", + "timestamp": COMMENT_TIMESTAMP, + "embeds": [], + }, + ], "embeds": [], "reactions": [], "timestamp": TIMESTAMP, @@ -2070,6 +2080,21 @@ mod routes { "id": CONTRIBUTOR_DID, }, "body": "Change 'hello world' to 'hello everyone'", + "edits": [ + { + "author": { + "id": CONTRIBUTOR_DID, + }, + "body": "Change 'hello world' to 'hello everyone'", + "timestamp": COMMENT_TIMESTAMP, + "embeds": [ + { + "name": "example.html", + "content": "git:b62df2ec90365e3749cd4fa431cb844492908b84", + }, + ], + }, + ], "embeds": [ { "name": "example.html", @@ -2203,6 +2228,29 @@ mod routes { "id": CONTRIBUTOR_DID, }, "body": "EDIT: Change 'hello world' to 'hello anyone'", + "edits": [ + { + "author": { + "id": CONTRIBUTOR_DID, + }, + "body": "Change 'hello world' to 'hello everyone'", + "timestamp": COMMENT_TIMESTAMP, + "embeds": [], + }, + { + "author": { + "id": CONTRIBUTOR_DID, + }, + "body": "EDIT: Change 'hello world' to 'hello anyone'", + "timestamp": COMMENT_TIMESTAMP, + "embeds": [ + { + "name": "image.jpg", + "content": "git:94381b429d7f7fe87e1bade52d893ab348ae29cc", + }, + ], + }, + ], "embeds": [ { "name": "image.jpg", @@ -2271,11 +2319,11 @@ mod routes { "author": { "id": CONTRIBUTOR_DID, }, - "assignees": [], "title": "Issue #1", "state": { "status": "open", }, + "assignees": [], "discussion": [ { "id": ISSUE_DISCUSSION_ID, @@ -2283,6 +2331,16 @@ mod routes { "id": CONTRIBUTOR_DID, }, "body": "Change 'hello world' to 'hello everyone'", + "edits": [ + { + "author": { + "id": CONTRIBUTOR_DID, + }, + "body": "Change 'hello world' to 'hello everyone'", + "timestamp": COMMENT_TIMESTAMP, + "embeds": [], + }, + ], "embeds": [], "reactions": [], "timestamp": TIMESTAMP, @@ -2295,6 +2353,21 @@ mod routes { "id": CONTRIBUTOR_DID, }, "body": "This is a reply to the first comment", + "edits": [ + { + "author": { + "id": CONTRIBUTOR_DID, + }, + "body": "This is a reply to the first comment", + "timestamp": COMMENT_TIMESTAMP, + "embeds": [ + { + "name": "image.jpg", + "content": "git:94381b429d7f7fe87e1bade52d893ab348ae29cc", + }, + ], + }, + ], "embeds": [ { "name": "image.jpg", @@ -2931,6 +3004,34 @@ mod routes { "id": CONTRIBUTOR_DID, }, "body": "EDIT: This is a root level comment", + "edits": [ + { + "author": { + "id": CONTRIBUTOR_DID, + }, + "body": "This is a root level comment", + "timestamp": COMMENT_TIMESTAMP, + "embeds": [ + { + "name": "image.jpg", + "content": "git:94381b429d7f7fe87e1bade52d893ab348ae29cc", + }, + ], + }, + { + "author": { + "id": CONTRIBUTOR_DID, + }, + "body": "EDIT: This is a root level comment", + "timestamp": COMMENT_TIMESTAMP, + "embeds": [ + { + "name": "image.jpg", + "content": "git:94381b429d7f7fe87e1bade52d893ab348ae29cc", + }, + ], + }, + ], "embeds": [ { "name": "image.jpg", @@ -2948,6 +3049,16 @@ mod routes { "id": CONTRIBUTOR_DID, }, "body": "This is a root level comment", + "edits": [ + { + "author": { + "id": CONTRIBUTOR_DID, + }, + "body": "This is a root level comment", + "timestamp": COMMENT_TIMESTAMP, + "embeds": [], + }, + ], "embeds": [], "reactions": [], "timestamp": TIMESTAMP, @@ -3132,6 +3243,30 @@ mod routes { ], "resolved": true, "body": "EDIT: This is a comment on a review", + "edits": [ + { + "author": "z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8", + "timestamp": COMMENT_TIMESTAMP, + "body": "This is a comment on a review", + "embeds": [ + { + "name": "image.jpg", + "content": "git:94381b429d7f7fe87e1bade52d893ab348ae29cc", + }, + ], + }, + { + "author": "z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8", + "timestamp": COMMENT_TIMESTAMP, + "body": "EDIT: This is a comment on a review", + "embeds": [ + { + "name": "image.jpg", + "content": "git:94381b429d7f7fe87e1bade52d893ab348ae29cc", + }, + ], + }, + ], "embeds": [ { "name": "image.jpg", diff --git a/radicle-httpd/src/test.rs b/radicle-httpd/src/test.rs index d1431c73d..22c8a8379 100644 --- a/radicle-httpd/src/test.rs +++ b/radicle-httpd/src/test.rs @@ -37,6 +37,7 @@ pub const ISSUE_DISCUSSION_ID: &str = "d11b03464c9bf58b09460713c8e2c74f0725d3bd" pub const ISSUE_COMMENT_ID: &str = "e3aa754cb47d2299781fed49cc91c4b41e06c219"; pub const SESSION_ID: &str = "u9MGAkkfkMOv0uDDB2WeUHBT7HbsO2Dy"; pub const TIMESTAMP: u64 = 1671125284; +pub const COMMENT_TIMESTAMP: u64 = 1671125284000; pub const CONTRIBUTOR_RID: &str = "rad:z4XaCmN3jLSeiMvW15YTDpNbDHFhG"; pub const CONTRIBUTOR_DID: &str = "did:key:z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8"; pub const CONTRIBUTOR_NID: &str = "z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8";