* Follows initial

* Fix #171, Fix #170, Fix #169, Fix #164

* More work on follows

* Fix compile error

* Upgrade meili version, add follows to search
This commit is contained in:
Geometrically
2021-03-04 20:35:23 -07:00
committed by GitHub
parent e46ff3de8b
commit 0ccb6cb873
25 changed files with 2298 additions and 782 deletions

View File

@@ -24,7 +24,7 @@ impl User {
avatar_url, bio, created
)
VALUES (
$1, $2, $3, $4, $5,
$1, $2, LOWER($3), $4, $5,
$6, $7, $8
)
",
@@ -126,7 +126,7 @@ impl User {
u.avatar_url, u.bio,
u.created, u.role
FROM users u
WHERE u.username = $1
WHERE LOWER(u.username) = LOWER($1)
",
username
)
@@ -239,6 +239,29 @@ impl User {
.execute(exec)
.await?;
use futures::TryStreamExt;
let notifications: Vec<i64> = sqlx::query!(
"
SELECT n.id FROM notifications n
WHERE n.user_id = $1
",
id as UserId,
)
.fetch_many(exec)
.try_filter_map(|e| async { Ok(e.right().map(|m| m.id as i64)) })
.try_collect::<Vec<i64>>()
.await?;
sqlx::query!(
"
DELETE FROM notifications
WHERE user_id = $1
",
id as UserId,
)
.execute(exec)
.await?;
sqlx::query!(
"
DELETE FROM reports
@@ -249,6 +272,26 @@ impl User {
.execute(exec)
.await?;
sqlx::query!(
"
DELETE FROM mod_follows
WHERE follower_id = $1
",
id as UserId,
)
.execute(exec)
.await?;
sqlx::query!(
"
DELETE FROM notifications_actions
WHERE notification_id IN (SELECT * FROM UNNEST($1::bigint[]))
",
&notifications
)
.execute(exec)
.await?;
sqlx::query!(
"
DELETE FROM team_members
@@ -298,6 +341,38 @@ impl User {
let _result = super::mod_item::Mod::remove_full(mod_id, exec).await?;
}
let notifications: Vec<i64> = sqlx::query!(
"
SELECT n.id FROM notifications n
WHERE n.user_id = $1
",
id as UserId,
)
.fetch_many(exec)
.try_filter_map(|e| async { Ok(e.right().map(|m| m.id as i64)) })
.try_collect::<Vec<i64>>()
.await?;
sqlx::query!(
"
DELETE FROM notifications
WHERE user_id = $1
",
id as UserId,
)
.execute(exec)
.await?;
sqlx::query!(
"
DELETE FROM notifications_actions
WHERE notification_id IN (SELECT * FROM UNNEST($1::bigint[]))
",
&notifications
)
.execute(exec)
.await?;
let deleted_user: UserId = crate::models::users::DELETED_USER.into();
sqlx::query!(