Skip to content

Commit

Permalink
style: consistent indentation
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan O’Hara <[email protected]>
  • Loading branch information
hn275 and minitech committed Apr 9, 2023
1 parent f83d62d commit b36e4ef
Showing 1 changed file with 67 additions and 67 deletions.
134 changes: 67 additions & 67 deletions src/services/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,13 @@ pub async fn delete_comment(
comment_id: web::Path<MaskedObjectId>,
) -> ApiResult<(), ()> {
match db.collection::<Comment>("comments").update_one(
doc! {"_id": masking_key.unmask(&comment_id).map_err(|masked_oid::PaddingError| Failure::BadRequest("bad masked id"))?, "owner": &user.id},
doc! {"$set": {"deleted": true}},
None,
).await {
Ok(_) => success(()), // idempotent deletion
Err(_) => Err(Failure::Unexpected),
}
doc! {"_id": masking_key.unmask(&comment_id).map_err(|masked_oid::PaddingError| Failure::BadRequest("bad masked id"))?, "owner": &user.id},
doc! {"$set": {"deleted": true}},
None,
).await {
Ok(_) => success(()), // idempotent deletion
Err(_) => Err(Failure::Unexpected),
}
}

/// The types of comment fetching options.
Expand Down Expand Up @@ -504,19 +504,19 @@ impl CommentSort {
CommentSort::Worst => vec![doc! {"absolute_score": 1}],
CommentSort::Controversial => vec![
doc! {
"$addFields": {
"score_diff": {
"$abs": {
"$subtract": ["$absolute_score", 0]
}
},
"total_votes": {
"$add": ["$votes_up", "$votes_down"]
}
"$addFields": {
"score_diff": {
"$abs": {
"$subtract": ["$absolute_score", 0]
}
},
"total_votes": {
"$add": ["$votes_up", "$votes_down"]
}
}
},
doc! {
"$sort": { "score_diff": 1, "total_votes": -1 }
"$sort": { "score_diff": 1, "total_votes": -1 }
},
],
CommentSort::Best => vec![doc! {"trending_score": -1}],
Expand Down Expand Up @@ -573,20 +573,20 @@ pub async fn get_comment(
CommentFetchType::Thread { .. } => {
vec![doc! {
"$expr": {
"$eq": [
{ "$arrayElemAt": [ "$parent_comments", -1 ] },
id
]
"$eq": [
{ "$arrayElemAt": [ "$parent_comments", -1 ] },
id
]
}
}]
}
};

find_filter.push(doc! {
"_id": {
"$not": {
"$in": &excluded_ids
}
"$not": {
"$in": &excluded_ids
}
}
});

Expand Down Expand Up @@ -701,50 +701,50 @@ pub async fn get_comment(
continue;
};
let replies = db.collection::<Comment>("comments")
.find(
doc! {
"$and": vec![
doc! {
"_id": {
"$not": {
"$in": &excluded_ids
}
}
},
doc! {
"$expr": {
"$eq": [
{ "$arrayElemAt": [ "$parent_comments", -1 ] },
masking_key.unmask(&parent_comment.id).map_err(|masked_oid::PaddingError| Failure::BadRequest("bad masked id"))?
]
}
},
.find(
doc! {
"$and": vec![
doc! {
"_id": {
"$not": {
"$in": &excluded_ids
}
}
},
doc! {
"$expr": {
"$eq": [
{ "$arrayElemAt": [ "$parent_comments", -1 ] },
masking_key.unmask(&parent_comment.id).map_err(|masked_oid::PaddingError| Failure::BadRequest("bad masked id"))?
]
},
FindOptions::builder()
.sort(doc! {"replies": -1}) // sort threaded comments by replies to help build the best tree structures
.limit(i64::from(conf::MAX_REPLYING_COMMENTS_PER_LOAD))
.build()
)
.await
.map_err(to_unexpected!("Getting comments cursor failed"))?
.map_ok(|comment| Ok(CommentDetail {
id: masking_key.mask(&comment.id),
parent_comments: comment.parent_comments.iter().map(|id| masking_key.mask(id)).collect(),
parent_post: masking_key.mask(&comment.parent_post),
text: if comment.deleted {"[deleted]".to_string()} else {comment.text},
replies: comment.replies,
children: vec![],
votes: Votes {
up: u32::try_from(comment.votes_up).unwrap(),
down: u32::try_from(comment.votes_down).unwrap(),
},
}))
.try_collect::<Vec<Result<CommentDetail, Failure<()>>>>()
.await
.map_err(to_unexpected!("Getting comments failed"))?
.into_iter()
.collect::<Result<Vec<CommentDetail>, Failure<()>>>()?;
}
},
]
},
FindOptions::builder()
.sort(doc! {"replies": -1}) // sort threaded comments by replies to help build the best tree structures
.limit(i64::from(conf::MAX_REPLYING_COMMENTS_PER_LOAD))
.build()
)
.await
.map_err(to_unexpected!("Getting comments cursor failed"))?
.map_ok(|comment| Ok(CommentDetail {
id: masking_key.mask(&comment.id),
parent_comments: comment.parent_comments.iter().map(|id| masking_key.mask(id)).collect(),
parent_post: masking_key.mask(&comment.parent_post),
text: if comment.deleted {"[deleted]".to_string()} else {comment.text},
replies: comment.replies,
children: vec![],
votes: Votes {
up: u32::try_from(comment.votes_up).unwrap(),
down: u32::try_from(comment.votes_down).unwrap(),
},
}))
.try_collect::<Vec<Result<CommentDetail, Failure<()>>>>()
.await
.map_err(to_unexpected!("Getting comments failed"))?
.into_iter()
.collect::<Result<Vec<CommentDetail>, Failure<()>>>()?;
for comment in replies {
if count < conf::MIN_REPLYING_COMMENTS_PER_LOAD_IF_AVAILABLE
|| rand::thread_rng().gen_bool(p(1.0, parent_comment.replies as f64))
Expand Down

0 comments on commit b36e4ef

Please sign in to comment.