Browse Source

not return blocked_count

master
hole-thu 3 years ago
parent
commit
2bae66099d
  1. 8
      src/api/comment.rs
  2. 7
      src/api/post.rs

8
src/api/comment.rs

@ -31,7 +31,7 @@ pub struct CommentOutput {
is_tmp: bool, is_tmp: bool,
create_time: i64, create_time: i64,
is_blocked: bool, is_blocked: bool,
blocked_count: Option<i32>, //blocked_count: Option<i32>,
// for old version frontend // for old version frontend
timestamp: i64, timestamp: i64,
blocked: bool, blocked: bool,
@ -42,7 +42,7 @@ pub async fn c2output<'r>(
cs: &[Comment], cs: &[Comment],
user: &CurrentUser, user: &CurrentUser,
cached_block_dict: &HashMap<String, bool>, cached_block_dict: &HashMap<String, bool>,
rconn: &RdsConn, //rconn: &RdsConn,
) -> Vec<CommentOutput> { ) -> Vec<CommentOutput> {
let mut hash2id = HashMap::<&String, i32>::from([(&p.author_hash, 0)]); let mut hash2id = HashMap::<&String, i32>::from([(&p.author_hash, 0)]);
let name_ids_iter = cs.iter().map(|c| match hash2id.get(&c.author_hash) { let name_ids_iter = cs.iter().map(|c| match hash2id.get(&c.author_hash) {
@ -69,6 +69,7 @@ pub async fn c2output<'r>(
is_tmp: c.is_tmp, is_tmp: c.is_tmp,
create_time: c.create_time.timestamp(), create_time: c.create_time.timestamp(),
is_blocked, is_blocked,
/*
blocked_count: if user.is_admin { blocked_count: if user.is_admin {
BlockCounter::get_count(rconn, &c.author_hash) BlockCounter::get_count(rconn, &c.author_hash)
.await .await
@ -77,6 +78,7 @@ pub async fn c2output<'r>(
} else { } else {
None None
}, },
*/
timestamp: c.create_time.timestamp(), timestamp: c.create_time.timestamp(),
blocked: is_blocked, blocked: is_blocked,
}) })
@ -99,7 +101,7 @@ pub async fn get_comment(pid: i32, user: CurrentUser, db: Db, rconn: RdsConn) ->
let cached_block_dict = BlockDictCache::init(&user.namehash, p.id, &rconn) let cached_block_dict = BlockDictCache::init(&user.namehash, p.id, &rconn)
.get_or_create(&user, &hash_list) .get_or_create(&user, &hash_list)
.await?; .await?;
let data = c2output(&p, &cs, &user, &cached_block_dict, &rconn).await; let data = c2output(&p, &cs, &user, &cached_block_dict).await;
Ok(json!({ Ok(json!({
"code": 0, "code": 0,

7
src/api/post.rs

@ -49,7 +49,7 @@ pub struct PostOutput {
attention: bool, attention: bool,
hot_score: Option<i32>, hot_score: Option<i32>,
is_blocked: bool, is_blocked: bool,
blocked_count: Option<i32>, //blocked_count: Option<i32>,
poll: Option<Value>, poll: Option<Value>,
// for old version frontend // for old version frontend
timestamp: i64, timestamp: i64,
@ -98,19 +98,20 @@ async fn p2output(p: &Post, user: &CurrentUser, db: &Db, rconn: &RdsConn) -> Api
is_tmp: p.is_tmp, is_tmp: p.is_tmp,
is_reported: user.is_admin.then(|| p.is_reported), is_reported: user.is_admin.then(|| p.is_reported),
comments: OptionFuture::from( comments: OptionFuture::from(
comments comments.map(|cs| async move { c2output(p, &cs, user, &cached_block_dict).await }),
.map(|cs| async move { c2output(p, &cs, user, &cached_block_dict, rconn).await }),
) )
.await, .await,
can_del: p.check_permission(user, "wd").is_ok(), can_del: p.check_permission(user, "wd").is_ok(),
attention: Attention::init(&user.namehash, rconn).has(p.id).await?, attention: Attention::init(&user.namehash, rconn).has(p.id).await?,
hot_score: user.is_admin.then(|| p.hot_score), hot_score: user.is_admin.then(|| p.hot_score),
is_blocked, is_blocked,
/*
blocked_count: if user.is_admin { blocked_count: if user.is_admin {
BlockCounter::get_count(rconn, &p.author_hash).await? BlockCounter::get_count(rconn, &p.author_hash).await?
} else { } else {
None None
}, },
*/
poll: if can_view { poll: if can_view {
get_poll_dict(p.id, rconn, &user.namehash).await get_poll_dict(p.id, rconn, &user.namehash).await
} else { } else {

Loading…
Cancel
Save