httpd: Add author alias to reactions
This commit is contained in:
parent
64fd41961e
commit
5bdc2ad1fb
|
|
@ -137,13 +137,10 @@ pub(crate) fn patch(
|
||||||
"description": rev.description(),
|
"description": rev.description(),
|
||||||
"edits": rev.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
|
"edits": rev.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
|
||||||
"reactions": rev.reactions().iter().flat_map(|(location, reaction)| {
|
"reactions": rev.reactions().iter().flat_map(|(location, reaction)| {
|
||||||
let reactions = reaction.iter().fold(BTreeMap::new(), |mut acc: BTreeMap<&Reaction, Vec<_>>, (author, emoji)| {
|
reactions(reaction.iter().fold(BTreeMap::new(), |mut acc: BTreeMap<&Reaction, Vec<_>>, (author, emoji)| {
|
||||||
acc.entry(emoji).or_default().push(author);
|
acc.entry(emoji).or_default().push(author);
|
||||||
acc
|
acc
|
||||||
});
|
}), location.as_ref(), aliases)
|
||||||
reactions.iter().map(|(emoji, authors)|
|
|
||||||
json!({ "location": location, "emoji": emoji, "authors": authors })
|
|
||||||
).collect::<Vec<_>>()
|
|
||||||
}).collect::<Vec<_>>(),
|
}).collect::<Vec<_>>(),
|
||||||
"base": rev.base(),
|
"base": rev.base(),
|
||||||
"oid": rev.head(),
|
"oid": rev.head(),
|
||||||
|
|
@ -160,6 +157,28 @@ pub(crate) fn patch(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns JSON for a `reaction`.
|
||||||
|
fn reactions(
|
||||||
|
reactions: BTreeMap<&Reaction, Vec<&ActorId>>,
|
||||||
|
location: Option<&CodeLocation>,
|
||||||
|
aliases: &impl AliasStore,
|
||||||
|
) -> Vec<Value> {
|
||||||
|
reactions
|
||||||
|
.into_iter()
|
||||||
|
.map(|(emoji, authors)| {
|
||||||
|
if let Some(l) = location {
|
||||||
|
json!({ "location": l, "emoji": emoji, "authors": authors.into_iter().map(|a|
|
||||||
|
author(&Author::from(*a), aliases.alias(a))
|
||||||
|
).collect::<Vec<_>>()})
|
||||||
|
} else {
|
||||||
|
json!({ "emoji": emoji, "authors": authors.into_iter().map(|a|
|
||||||
|
author(&Author::from(*a), aliases.alias(a))
|
||||||
|
).collect::<Vec<_>>()})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns JSON for an `author` and fills in `alias` when present.
|
/// Returns JSON for an `author` and fills in `alias` when present.
|
||||||
fn author(author: &Author, alias: Option<Alias>) -> Value {
|
fn author(author: &Author, alias: Option<Alias>) -> Value {
|
||||||
match alias {
|
match alias {
|
||||||
|
|
@ -212,9 +231,7 @@ fn issue_comment(id: &CommentId, comment: &Comment, aliases: &impl AliasStore) -
|
||||||
"body": comment.body(),
|
"body": comment.body(),
|
||||||
"edits": comment.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
|
"edits": comment.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
|
||||||
"embeds": comment.embeds().to_vec(),
|
"embeds": comment.embeds().to_vec(),
|
||||||
"reactions": comment.reactions().iter().map(|(emoji, authors)|
|
"reactions": reactions(comment.reactions(), None, aliases),
|
||||||
json!({ "emoji": emoji, "authors": authors })
|
|
||||||
).collect::<Vec<_>>(),
|
|
||||||
"timestamp": comment.timestamp().as_secs(),
|
"timestamp": comment.timestamp().as_secs(),
|
||||||
"replyTo": comment.reply_to(),
|
"replyTo": comment.reply_to(),
|
||||||
"resolved": comment.is_resolved(),
|
"resolved": comment.is_resolved(),
|
||||||
|
|
@ -233,9 +250,7 @@ fn patch_comment(
|
||||||
"body": comment.body(),
|
"body": comment.body(),
|
||||||
"edits": comment.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
|
"edits": comment.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
|
||||||
"embeds": comment.embeds().to_vec(),
|
"embeds": comment.embeds().to_vec(),
|
||||||
"reactions": comment.reactions().iter().map(|(emoji, authors)|
|
"reactions": reactions(comment.reactions(), None, aliases),
|
||||||
json!({ "emoji": emoji, "authors": authors })
|
|
||||||
).collect::<Vec<_>>(),
|
|
||||||
"timestamp": comment.timestamp().as_secs(),
|
"timestamp": comment.timestamp().as_secs(),
|
||||||
"replyTo": comment.reply_to(),
|
"replyTo": comment.reply_to(),
|
||||||
"location": comment.location(),
|
"location": comment.location(),
|
||||||
|
|
@ -255,9 +270,7 @@ fn review_comment(
|
||||||
"body": comment.body(),
|
"body": comment.body(),
|
||||||
"edits": comment.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
|
"edits": comment.edits().map(|e| edit(e, aliases)).collect::<Vec<_>>(),
|
||||||
"embeds": comment.embeds().to_vec(),
|
"embeds": comment.embeds().to_vec(),
|
||||||
"reactions": comment.reactions().iter().map(|(emoji, authors)|
|
"reactions": reactions(comment.reactions(), None, aliases),
|
||||||
json!({ "emoji": emoji, "authors": authors })
|
|
||||||
).collect::<Vec<_>>(),
|
|
||||||
"timestamp": comment.timestamp().as_secs(),
|
"timestamp": comment.timestamp().as_secs(),
|
||||||
"replyTo": comment.reply_to(),
|
"replyTo": comment.reply_to(),
|
||||||
"location": comment.location(),
|
"location": comment.location(),
|
||||||
|
|
|
||||||
|
|
@ -2297,7 +2297,9 @@ mod routes {
|
||||||
"reactions": [
|
"reactions": [
|
||||||
{
|
{
|
||||||
"emoji": "🚀",
|
"emoji": "🚀",
|
||||||
"authors": ["z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8"]
|
"authors": [
|
||||||
|
{ "id": "did:key:z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8" }
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"timestamp": TIMESTAMP,
|
"timestamp": TIMESTAMP,
|
||||||
|
|
@ -3131,9 +3133,10 @@ mod routes {
|
||||||
],
|
],
|
||||||
"reactions": [
|
"reactions": [
|
||||||
{
|
{
|
||||||
"location": null,
|
|
||||||
"emoji": "🙏",
|
"emoji": "🙏",
|
||||||
"authors": ["z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8"],
|
"authors": [
|
||||||
|
{ "id": "did:key:z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8" }
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
|
|
@ -3149,7 +3152,9 @@ mod routes {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"emoji": "🚀",
|
"emoji": "🚀",
|
||||||
"authors": ["z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8"]
|
"authors": [
|
||||||
|
{ "id": "did:key:z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8" }
|
||||||
|
]
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"base": PARENT,
|
"base": PARENT,
|
||||||
|
|
@ -3338,7 +3343,9 @@ mod routes {
|
||||||
"reactions": [
|
"reactions": [
|
||||||
{
|
{
|
||||||
"emoji": "🚀",
|
"emoji": "🚀",
|
||||||
"authors": ["z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8"]
|
"authors": [
|
||||||
|
{ "id": "did:key:z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8" }
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"timestamp": TIMESTAMP,
|
"timestamp": TIMESTAMP,
|
||||||
|
|
@ -3581,7 +3588,9 @@ mod routes {
|
||||||
"reactions": [
|
"reactions": [
|
||||||
{
|
{
|
||||||
"emoji": "🚀",
|
"emoji": "🚀",
|
||||||
"authors": ["z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8"],
|
"authors": [
|
||||||
|
{ "id": "did:key:z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8" }
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"timestamp": 1671125284,
|
"timestamp": 1671125284,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue