Find mutual for users; allow dots in usernames.

This commit is contained in:
Paul
2021-02-19 13:11:33 +00:00
parent 78cfbf9d21
commit 64d2707366
2 changed files with 6 additions and 9 deletions

View File

@@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
use validator::Validate; use validator::Validate;
lazy_static! { lazy_static! {
static ref RE_USERNAME: Regex = Regex::new(r"^[a-zA-Z0-9_]+$").unwrap(); static ref RE_USERNAME: Regex = Regex::new(r"^[a-zA-Z0-9_.]+$").unwrap();
} }
#[derive(Validate, Serialize, Deserialize)] #[derive(Validate, Serialize, Deserialize)]

View File

@@ -8,15 +8,12 @@ use rocket_contrib::json::JsonValue;
#[get("/<target>/mutual")] #[get("/<target>/mutual")]
pub async fn req(user: User, target: Ref) -> Result<JsonValue> { pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
let channels = get_collection("channels") let users = get_collection("users")
.find( .find(
doc! { doc! {
"$or": [
{ "type": "Group" },
],
"$and": [ "$and": [
{ "recipients": &user.id }, { "relations.id": &user.id },
{ "recipients": &target.id } { "relations.id": &target.id }
] ]
}, },
FindOptions::builder().projection(doc! { "_id": 1 }).build(), FindOptions::builder().projection(doc! { "_id": 1 }).build(),
@@ -24,7 +21,7 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
.await .await
.map_err(|_| Error::DatabaseError { .map_err(|_| Error::DatabaseError {
operation: "find", operation: "find",
with: "channels", with: "users",
})? })?
.filter_map(async move |s| s.ok()) .filter_map(async move |s| s.ok())
.collect::<Vec<Document>>() .collect::<Vec<Document>>()
@@ -33,5 +30,5 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
.filter_map(|x| x.get_str("_id").ok().map(|x| x.to_string())) .filter_map(|x| x.get_str("_id").ok().map(|x| x.to_string()))
.collect::<Vec<String>>(); .collect::<Vec<String>>();
Ok(json!({ "channels": channels })) Ok(json!({ "users": users }))
} }