Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
cob: improve Comment generics
Sebastian Martinez committed 2 years ago
commit 1a63024a58463c7206b954a49b01c4c7c3d5f83e
parent 5bd4e171e4ac486e16ac597a928d8c3fed8b62ed
2 files changed +33 -4
modified radicle-httpd/src/api/json.rs
@@ -103,7 +103,7 @@ pub(crate) fn issue(id: IssueId, issue: Issue, aliases: &impl AliasStore) -> Val
        "title": issue.title(),
        "state": issue.state(),
        "assignees": issue.assignees().collect::<Vec<_>>(),
-
        "discussion": issue.comments().map(|(id, c)| comment(id, c, aliases)).collect::<Vec<_>>(),
+
        "discussion": issue.comments().map(|(id, c)| issue_comment(id, c, aliases)).collect::<Vec<_>>(),
        "labels": issue.labels().collect::<Vec<_>>(),
    })
}
@@ -132,7 +132,7 @@ pub(crate) fn patch(
                "base": rev.base(),
                "oid": rev.head(),
                "refs": get_refs(repo, patch.author().id(), &rev.head()).unwrap_or_default(),
-
                "discussions": rev.discussion().comments().map(|(id, c)| comment(id, c,  aliases)).collect::<Vec<_>>(),
+
                "discussions": rev.discussion().comments().map(|(id, c)| patch_comment(id, c,  aliases)).collect::<Vec<_>>(),
                "timestamp": rev.timestamp().as_secs(),
                "reviews": rev.reviews().map(|(nid, r)| review(nid, r, aliases)).collect::<Vec<_>>(),
            })
@@ -172,8 +172,8 @@ fn review(nid: &NodeId, review: &Review, aliases: &impl AliasStore) -> Value {
    })
}

-
/// Returns JSON for a `Comment`.
-
fn comment(id: &CommentId, comment: &Comment, aliases: &impl AliasStore) -> Value {
+
/// Returns JSON for a Issue `Comment`.
+
fn issue_comment(id: &CommentId, comment: &Comment, aliases: &impl AliasStore) -> Value {
    json!({
        "id": *id,
        "author": author(&Author::from(comment.author()), aliases.alias(&comment.author())),
@@ -194,6 +194,33 @@ fn comment(id: &CommentId, comment: &Comment, aliases: &impl AliasStore) -> Valu
    })
}

+
/// Returns JSON for a Patch `Comment`.
+
fn patch_comment(
+
    id: &CommentId,
+
    comment: &Comment<CodeLocation>,
+
    aliases: &impl AliasStore,
+
) -> Value {
+
    json!({
+
        "id": *id,
+
        "author": author(&Author::from(comment.author()), aliases.alias(&comment.author())),
+
        "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.as_secs(),
+
            "embeds": edit.embeds,
+
          })
+
        }).collect::<Vec<_>>(),
+
        "embeds": comment.embeds().to_vec(),
+
        "reactions": comment.reactions().collect::<Vec<_>>(),
+
        "timestamp": comment.timestamp().as_secs(),
+
        "replyTo": comment.reply_to(),
+
        "location": comment.location(),
+
        "resolved": comment.resolved(),
+
    })
+
}
+

/// Returns JSON for a `Review`.
fn review_comment(
    id: &CommentId,
modified radicle-httpd/src/api/v1/projects.rs
@@ -3041,6 +3041,7 @@ mod routes {
                      "reactions": [["z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8","🚀"]],
                      "timestamp": TIMESTAMP,
                      "replyTo": null,
+
                      "location": null,
                      "resolved": false,
                    },
                    {
@@ -3063,6 +3064,7 @@ mod routes {
                      "reactions": [],
                      "timestamp": TIMESTAMP,
                      "replyTo": comment_id,
+
                      "location": null,
                      "resolved": false,
                    },
                  ],