|
|
|
@ -5,7 +5,6 @@ use bcrypt::verify;
|
|
|
|
|
use captcha::{gen, Difficulty};
|
|
|
|
|
use chrono::Duration;
|
|
|
|
|
use lemmy_api_common::{
|
|
|
|
|
blocking,
|
|
|
|
|
collect_moderated_communities,
|
|
|
|
|
get_local_user_view_from_jwt,
|
|
|
|
|
is_admin,
|
|
|
|
@ -86,11 +85,9 @@ impl Perform for Login {
|
|
|
|
|
|
|
|
|
|
// Fetch that username / email
|
|
|
|
|
let username_or_email = data.username_or_email.clone();
|
|
|
|
|
let local_user_view = blocking(context.pool(), move |conn| {
|
|
|
|
|
LocalUserView::find_by_email_or_name(conn, &username_or_email)
|
|
|
|
|
})
|
|
|
|
|
.await?
|
|
|
|
|
.map_err(|_| ApiError::err("couldnt_find_that_username_or_email"))?;
|
|
|
|
|
let local_user_view =
|
|
|
|
|
LocalUserView::find_by_email_or_name(&&context.pool.get().await?, &username_or_email)
|
|
|
|
|
.map_err(|_| ApiError::err("couldnt_find_that_username_or_email"))?;
|
|
|
|
|
|
|
|
|
|
// Verify the password
|
|
|
|
|
let valid: bool = verify(
|
|
|
|
@ -220,16 +217,8 @@ impl Perform for SaveUserSettings {
|
|
|
|
|
bot_account,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let person_res = blocking(context.pool(), move |conn| {
|
|
|
|
|
Person::update(conn, person_id, &person_form)
|
|
|
|
|
})
|
|
|
|
|
.await?;
|
|
|
|
|
let _updated_person: Person = match person_res {
|
|
|
|
|
Ok(p) => p,
|
|
|
|
|
Err(_) => {
|
|
|
|
|
return Err(ApiError::err("user_already_exists").into());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Person::update(&&context.pool.get().await?, person_id, &person_form)
|
|
|
|
|
.map_err(|_| ApiError::err("user_already_exists"))?;
|
|
|
|
|
|
|
|
|
|
let local_user_form = LocalUserForm {
|
|
|
|
|
person_id,
|
|
|
|
@ -248,24 +237,20 @@ impl Perform for SaveUserSettings {
|
|
|
|
|
send_notifications_to_email: data.send_notifications_to_email,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let local_user_res = blocking(context.pool(), move |conn| {
|
|
|
|
|
LocalUser::update(conn, local_user_id, &local_user_form)
|
|
|
|
|
})
|
|
|
|
|
.await?;
|
|
|
|
|
let updated_local_user = match local_user_res {
|
|
|
|
|
Ok(u) => u,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
let err_type = if e.to_string()
|
|
|
|
|
== "duplicate key value violates unique constraint \"local_user_email_key\""
|
|
|
|
|
{
|
|
|
|
|
"email_already_exists"
|
|
|
|
|
} else {
|
|
|
|
|
"user_already_exists"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Err(ApiError::err(err_type).into());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let updated_local_user =
|
|
|
|
|
LocalUser::update(&&context.pool.get().await?, local_user_id, &local_user_form).map_err(
|
|
|
|
|
|e| {
|
|
|
|
|
let err_type = if e.to_string()
|
|
|
|
|
== "duplicate key value violates unique constraint \"local_user_email_key\""
|
|
|
|
|
{
|
|
|
|
|
"email_already_exists"
|
|
|
|
|
} else {
|
|
|
|
|
"user_already_exists"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ApiError::err(err_type)
|
|
|
|
|
},
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
// Return the jwt
|
|
|
|
|
Ok(LoginResponse {
|
|
|
|
@ -305,10 +290,8 @@ impl Perform for ChangePassword {
|
|
|
|
|
|
|
|
|
|
let local_user_id = local_user_view.local_user.id;
|
|
|
|
|
let new_password = data.new_password.to_owned();
|
|
|
|
|
let updated_local_user = blocking(context.pool(), move |conn| {
|
|
|
|
|
LocalUser::update_password(conn, local_user_id, &new_password)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
let updated_local_user =
|
|
|
|
|
LocalUser::update_password(&&context.pool.get().await?, local_user_id, &new_password)?;
|
|
|
|
|
|
|
|
|
|
// Return the jwt
|
|
|
|
|
Ok(LoginResponse {
|
|
|
|
@ -334,16 +317,8 @@ impl Perform for AddAdmin {
|
|
|
|
|
|
|
|
|
|
let added = data.added;
|
|
|
|
|
let added_person_id = data.person_id;
|
|
|
|
|
let added_admin = match blocking(context.pool(), move |conn| {
|
|
|
|
|
Person::add_admin(conn, added_person_id, added)
|
|
|
|
|
})
|
|
|
|
|
.await?
|
|
|
|
|
{
|
|
|
|
|
Ok(a) => a,
|
|
|
|
|
Err(_) => {
|
|
|
|
|
return Err(ApiError::err("couldnt_update_user").into());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let added_admin = Person::add_admin(&&context.pool.get().await?, added_person_id, added)
|
|
|
|
|
.map_err(|_| ApiError::err("couldnt_update_user"))?;
|
|
|
|
|
|
|
|
|
|
// Mod tables
|
|
|
|
|
let form = ModAddForm {
|
|
|
|
@ -352,14 +327,11 @@ impl Perform for AddAdmin {
|
|
|
|
|
removed: Some(!data.added),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
blocking(context.pool(), move |conn| ModAdd::create(conn, &form)).await??;
|
|
|
|
|
ModAdd::create(&&context.pool.get().await?, &form)?;
|
|
|
|
|
|
|
|
|
|
let site_creator_id = blocking(context.pool(), move |conn| {
|
|
|
|
|
Site::read(conn, 1).map(|s| s.creator_id)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
let site_creator_id = Site::read(&&context.pool.get().await?, 1).map(|s| s.creator_id)?;
|
|
|
|
|
|
|
|
|
|
let mut admins = blocking(context.pool(), move |conn| PersonViewSafe::admins(conn)).await??;
|
|
|
|
|
let mut admins = PersonViewSafe::admins(&&context.pool.get().await?)?;
|
|
|
|
|
let creator_index = admins
|
|
|
|
|
.iter()
|
|
|
|
|
.position(|r| r.person.id == site_creator_id)
|
|
|
|
@ -396,26 +368,21 @@ impl Perform for BanPerson {
|
|
|
|
|
|
|
|
|
|
let ban = data.ban;
|
|
|
|
|
let banned_person_id = data.person_id;
|
|
|
|
|
let ban_person = move |conn: &'_ _| Person::ban_person(conn, banned_person_id, ban);
|
|
|
|
|
if blocking(context.pool(), ban_person).await?.is_err() {
|
|
|
|
|
let ban_person = Person::ban_person(&&context.pool.get().await?, banned_person_id, ban);
|
|
|
|
|
if ban_person.is_err() {
|
|
|
|
|
return Err(ApiError::err("couldnt_update_user").into());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove their data if that's desired
|
|
|
|
|
if data.remove_data.unwrap_or(false) {
|
|
|
|
|
// Posts
|
|
|
|
|
blocking(context.pool(), move |conn: &'_ _| {
|
|
|
|
|
Post::update_removed_for_creator(conn, banned_person_id, None, true)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
Post::update_removed_for_creator(&&context.pool.get().await?, banned_person_id, None, true)?;
|
|
|
|
|
|
|
|
|
|
// Communities
|
|
|
|
|
// Remove all communities where they're the top mod
|
|
|
|
|
// for now, remove the communities manually
|
|
|
|
|
let first_mod_communities = blocking(context.pool(), move |conn: &'_ _| {
|
|
|
|
|
CommunityModeratorView::get_community_first_mods(conn)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
let first_mod_communities =
|
|
|
|
|
CommunityModeratorView::get_community_first_mods(&&context.pool.get().await?)?;
|
|
|
|
|
|
|
|
|
|
// Filter to only this banned users top communities
|
|
|
|
|
let banned_user_first_communities: Vec<CommunityModeratorView> = first_mod_communities
|
|
|
|
@ -424,17 +391,15 @@ impl Perform for BanPerson {
|
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
for first_mod_community in banned_user_first_communities {
|
|
|
|
|
blocking(context.pool(), move |conn: &'_ _| {
|
|
|
|
|
Community::update_removed(conn, first_mod_community.community.id, true)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
Community::update_removed(
|
|
|
|
|
&&context.pool.get().await?,
|
|
|
|
|
first_mod_community.community.id,
|
|
|
|
|
true,
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Comments
|
|
|
|
|
blocking(context.pool(), move |conn: &'_ _| {
|
|
|
|
|
Comment::update_removed_for_creator(conn, banned_person_id, true)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
Comment::update_removed_for_creator(&&context.pool.get().await?, banned_person_id, true)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mod tables
|
|
|
|
@ -448,13 +413,10 @@ impl Perform for BanPerson {
|
|
|
|
|
expires,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
blocking(context.pool(), move |conn| ModBan::create(conn, &form)).await??;
|
|
|
|
|
ModBan::create(&&context.pool.get().await?, &form)?;
|
|
|
|
|
|
|
|
|
|
let person_id = data.person_id;
|
|
|
|
|
let person_view = blocking(context.pool(), move |conn| {
|
|
|
|
|
PersonViewSafe::read(conn, person_id)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
let person_view = PersonViewSafe::read(&&context.pool.get().await?, person_id)?;
|
|
|
|
|
|
|
|
|
|
let res = BanPersonResponse {
|
|
|
|
|
person_view,
|
|
|
|
@ -497,23 +459,18 @@ impl Perform for BlockPerson {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if data.block {
|
|
|
|
|
let block = move |conn: &'_ _| PersonBlock::block(conn, &person_block_form);
|
|
|
|
|
if blocking(context.pool(), block).await?.is_err() {
|
|
|
|
|
let block = PersonBlock::block(&&context.pool.get().await?, &person_block_form);
|
|
|
|
|
if block.is_err() {
|
|
|
|
|
return Err(ApiError::err("person_block_already_exists").into());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
let unblock = move |conn: &'_ _| PersonBlock::unblock(conn, &person_block_form);
|
|
|
|
|
if blocking(context.pool(), unblock).await?.is_err() {
|
|
|
|
|
let unblock = PersonBlock::unblock(&&context.pool.get().await?, &person_block_form);
|
|
|
|
|
if unblock.is_err() {
|
|
|
|
|
return Err(ApiError::err("person_block_already_exists").into());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO does any federated stuff need to be done here?
|
|
|
|
|
|
|
|
|
|
let person_view = blocking(context.pool(), move |conn| {
|
|
|
|
|
PersonViewSafe::read(conn, target_id)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
let person_view = PersonViewSafe::read(&&context.pool.get().await?, target_id)?;
|
|
|
|
|
|
|
|
|
|
let res = BlockPersonResponse {
|
|
|
|
|
person_view,
|
|
|
|
@ -544,18 +501,15 @@ impl Perform for GetReplies {
|
|
|
|
|
let person_id = local_user_view.person.id;
|
|
|
|
|
let show_bot_accounts = local_user_view.local_user.show_bot_accounts;
|
|
|
|
|
|
|
|
|
|
let replies = blocking(context.pool(), move |conn| {
|
|
|
|
|
CommentQueryBuilder::create(conn)
|
|
|
|
|
.sort(sort)
|
|
|
|
|
.unread_only(unread_only)
|
|
|
|
|
.recipient_id(person_id)
|
|
|
|
|
.show_bot_accounts(show_bot_accounts)
|
|
|
|
|
.my_person_id(person_id)
|
|
|
|
|
.page(page)
|
|
|
|
|
.limit(limit)
|
|
|
|
|
.list()
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
let replies = CommentQueryBuilder::create(&&context.pool.get().await?)
|
|
|
|
|
.sort(sort)
|
|
|
|
|
.unread_only(unread_only)
|
|
|
|
|
.recipient_id(person_id)
|
|
|
|
|
.show_bot_accounts(show_bot_accounts)
|
|
|
|
|
.my_person_id(person_id)
|
|
|
|
|
.page(page)
|
|
|
|
|
.limit(limit)
|
|
|
|
|
.list()?;
|
|
|
|
|
|
|
|
|
|
Ok(GetRepliesResponse { replies })
|
|
|
|
|
}
|
|
|
|
@ -579,17 +533,14 @@ impl Perform for GetPersonMentions {
|
|
|
|
|
let limit = data.limit;
|
|
|
|
|
let unread_only = data.unread_only;
|
|
|
|
|
let person_id = local_user_view.person.id;
|
|
|
|
|
let mentions = blocking(context.pool(), move |conn| {
|
|
|
|
|
PersonMentionQueryBuilder::create(conn)
|
|
|
|
|
.recipient_id(person_id)
|
|
|
|
|
.my_person_id(person_id)
|
|
|
|
|
.sort(sort)
|
|
|
|
|
.unread_only(unread_only)
|
|
|
|
|
.page(page)
|
|
|
|
|
.limit(limit)
|
|
|
|
|
.list()
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
let mentions = PersonMentionQueryBuilder::create(&&context.pool.get().await?)
|
|
|
|
|
.recipient_id(person_id)
|
|
|
|
|
.my_person_id(person_id)
|
|
|
|
|
.sort(sort)
|
|
|
|
|
.unread_only(unread_only)
|
|
|
|
|
.page(page)
|
|
|
|
|
.limit(limit)
|
|
|
|
|
.list()?;
|
|
|
|
|
|
|
|
|
|
Ok(GetPersonMentionsResponse { mentions })
|
|
|
|
|
}
|
|
|
|
@ -608,10 +559,7 @@ impl Perform for MarkPersonMentionAsRead {
|
|
|
|
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
|
|
|
|
|
|
|
|
|
let person_mention_id = data.person_mention_id;
|
|
|
|
|
let read_person_mention = blocking(context.pool(), move |conn| {
|
|
|
|
|
PersonMention::read(conn, person_mention_id)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
let read_person_mention = PersonMention::read(&&context.pool.get().await?, person_mention_id)?;
|
|
|
|
|
|
|
|
|
|
if local_user_view.person.id != read_person_mention.recipient_id {
|
|
|
|
|
return Err(ApiError::err("couldnt_update_comment").into());
|
|
|
|
@ -620,17 +568,18 @@ impl Perform for MarkPersonMentionAsRead {
|
|
|
|
|
let person_mention_id = read_person_mention.id;
|
|
|
|
|
let read = data.read;
|
|
|
|
|
let update_mention =
|
|
|
|
|
move |conn: &'_ _| PersonMention::update_read(conn, person_mention_id, read);
|
|
|
|
|
if blocking(context.pool(), update_mention).await?.is_err() {
|
|
|
|
|
PersonMention::update_read(&&context.pool.get().await?, person_mention_id, read);
|
|
|
|
|
if update_mention.is_err() {
|
|
|
|
|
return Err(ApiError::err("couldnt_update_comment").into());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let person_mention_id = read_person_mention.id;
|
|
|
|
|
let person_id = local_user_view.person.id;
|
|
|
|
|
let person_mention_view = blocking(context.pool(), move |conn| {
|
|
|
|
|
PersonMentionView::read(conn, person_mention_id, Some(person_id))
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
let person_mention_view = PersonMentionView::read(
|
|
|
|
|
&&context.pool.get().await?,
|
|
|
|
|
person_mention_id,
|
|
|
|
|
Some(person_id),
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
Ok(PersonMentionResponse {
|
|
|
|
|
person_mention_view,
|
|
|
|
@ -651,41 +600,35 @@ impl Perform for MarkAllAsRead {
|
|
|
|
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
|
|
|
|
|
|
|
|
|
let person_id = local_user_view.person.id;
|
|
|
|
|
let replies = blocking(context.pool(), move |conn| {
|
|
|
|
|
CommentQueryBuilder::create(conn)
|
|
|
|
|
.my_person_id(person_id)
|
|
|
|
|
.recipient_id(person_id)
|
|
|
|
|
.unread_only(true)
|
|
|
|
|
.page(1)
|
|
|
|
|
.limit(999)
|
|
|
|
|
.list()
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
let replies = CommentQueryBuilder::create(&&context.pool.get().await?)
|
|
|
|
|
.my_person_id(person_id)
|
|
|
|
|
.recipient_id(person_id)
|
|
|
|
|
.unread_only(true)
|
|
|
|
|
.page(1)
|
|
|
|
|
.limit(999)
|
|
|
|
|
.list()?;
|
|
|
|
|
|
|
|
|
|
// TODO: this should probably be a bulk operation
|
|
|
|
|
// Not easy to do as a bulk operation,
|
|
|
|
|
// because recipient_id isn't in the comment table
|
|
|
|
|
for comment_view in &replies {
|
|
|
|
|
let reply_id = comment_view.comment.id;
|
|
|
|
|
let mark_as_read = move |conn: &'_ _| Comment::update_read(conn, reply_id, true);
|
|
|
|
|
if blocking(context.pool(), mark_as_read).await?.is_err() {
|
|
|
|
|
let mark_as_read = Comment::update_read(&&context.pool.get().await?, reply_id, true);
|
|
|
|
|
if mark_as_read.is_err() {
|
|
|
|
|
return Err(ApiError::err("couldnt_update_comment").into());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mark all user mentions as read
|
|
|
|
|
let update_person_mentions =
|
|
|
|
|
move |conn: &'_ _| PersonMention::mark_all_as_read(conn, person_id);
|
|
|
|
|
if blocking(context.pool(), update_person_mentions)
|
|
|
|
|
.await?
|
|
|
|
|
.is_err()
|
|
|
|
|
{
|
|
|
|
|
PersonMention::mark_all_as_read(&&context.pool.get().await?, person_id);
|
|
|
|
|
if update_person_mentions.is_err() {
|
|
|
|
|
return Err(ApiError::err("couldnt_update_comment").into());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mark all private_messages as read
|
|
|
|
|
let update_pm = move |conn: &'_ _| PrivateMessage::mark_all_as_read(conn, person_id);
|
|
|
|
|
if blocking(context.pool(), update_pm).await?.is_err() {
|
|
|
|
|
let update_pm = PrivateMessage::mark_all_as_read(&&context.pool.get().await?, person_id);
|
|
|
|
|
if update_pm.is_err() {
|
|
|
|
|
return Err(ApiError::err("couldnt_update_private_message").into());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -706,11 +649,8 @@ impl Perform for PasswordReset {
|
|
|
|
|
|
|
|
|
|
// Fetch that email
|
|
|
|
|
let email = data.email.clone();
|
|
|
|
|
let local_user_view = blocking(context.pool(), move |conn| {
|
|
|
|
|
LocalUserView::find_by_email(conn, &email)
|
|
|
|
|
})
|
|
|
|
|
.await?
|
|
|
|
|
.map_err(|_| ApiError::err("couldnt_find_that_username_or_email"))?;
|
|
|
|
|
let local_user_view = LocalUserView::find_by_email(&&context.pool.get().await?, &email)
|
|
|
|
|
.map_err(|_| ApiError::err("couldnt_find_that_username_or_email"))?;
|
|
|
|
|
|
|
|
|
|
// Generate a random token
|
|
|
|
|
let token = generate_random_string();
|
|
|
|
@ -718,10 +658,7 @@ impl Perform for PasswordReset {
|
|
|
|
|
// Insert the row
|
|
|
|
|
let token2 = token.clone();
|
|
|
|
|
let local_user_id = local_user_view.local_user.id;
|
|
|
|
|
blocking(context.pool(), move |conn| {
|
|
|
|
|
PasswordResetRequest::create_token(conn, local_user_id, &token2)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
PasswordResetRequest::create_token(&&context.pool.get().await?, local_user_id, &token2)?;
|
|
|
|
|
|
|
|
|
|
// Email the pure token to the user.
|
|
|
|
|
// TODO no i18n support here.
|
|
|
|
@ -749,10 +686,8 @@ impl Perform for PasswordChange {
|
|
|
|
|
|
|
|
|
|
// Fetch the user_id from the token
|
|
|
|
|
let token = data.token.clone();
|
|
|
|
|
let local_user_id = blocking(context.pool(), move |conn| {
|
|
|
|
|
PasswordResetRequest::read_from_token(conn, &token).map(|p| p.local_user_id)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
let local_user_id = PasswordResetRequest::read_from_token(&&context.pool.get().await?, &token)
|
|
|
|
|
.map(|p| p.local_user_id)?;
|
|
|
|
|
|
|
|
|
|
password_length_check(&data.password)?;
|
|
|
|
|
|
|
|
|
@ -763,11 +698,9 @@ impl Perform for PasswordChange {
|
|
|
|
|
|
|
|
|
|
// Update the user with the new password
|
|
|
|
|
let password = data.password.clone();
|
|
|
|
|
let updated_local_user = blocking(context.pool(), move |conn| {
|
|
|
|
|
LocalUser::update_password(conn, local_user_id, &password)
|
|
|
|
|
})
|
|
|
|
|
.await?
|
|
|
|
|
.map_err(|_| ApiError::err("couldnt_update_user"))?;
|
|
|
|
|
let updated_local_user =
|
|
|
|
|
LocalUser::update_password(&&context.pool.get().await?, local_user_id, &password)
|
|
|
|
|
.map_err(|_| ApiError::err("couldnt_update_user"))?;
|
|
|
|
|
|
|
|
|
|
// Return the jwt
|
|
|
|
|
Ok(LoginResponse {
|
|
|
|
@ -802,16 +735,11 @@ impl Perform for GetReportCount {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
let ids = community_ids.clone();
|
|
|
|
|
let comment_reports = blocking(context.pool(), move |conn| {
|
|
|
|
|
CommentReportView::get_report_count(conn, &ids)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
let comment_reports =
|
|
|
|
|
CommentReportView::get_report_count(&&context.pool.get().await?, &ids)?;
|
|
|
|
|
|
|
|
|
|
let ids = community_ids.clone();
|
|
|
|
|
let post_reports = blocking(context.pool(), move |conn| {
|
|
|
|
|
PostReportView::get_report_count(conn, &ids)
|
|
|
|
|
})
|
|
|
|
|
.await??;
|
|
|
|
|
let post_reports = PostReportView::get_report_count(&&context.pool.get().await?, &ids)?;
|
|
|
|
|
|
|
|
|
|
GetReportCountResponse {
|
|
|
|
|
community: data.community,
|
|
|
|
|