forked from jmug/stoatchat
Breaking: Provide new user object instead of id.
Fix rustup complaining about join macros.
This commit is contained in:
@@ -31,6 +31,8 @@ pub async fn req(user: User, username: String) -> Result<JsonValue> {
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
let target_user = Ref::from(target_id.to_string())?.fetch_user().await?;
|
||||
|
||||
match get_relationship(&user, &target_id) {
|
||||
RelationshipStatus::User => return Err(Error::NoEffect),
|
||||
RelationshipStatus::Friend => return Err(Error::AlreadyFriends),
|
||||
@@ -65,16 +67,19 @@ pub async fn req(user: User, username: String) -> Result<JsonValue> {
|
||||
)
|
||||
) {
|
||||
Ok(_) => {
|
||||
let target_user = target_user.from_override(&user, RelationshipStatus::Friend).await?;
|
||||
let user = user.from_override(&target_user, RelationshipStatus::Friend).await?;
|
||||
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target_id.to_string(),
|
||||
user: target_user,
|
||||
status: RelationshipStatus::Friend
|
||||
}
|
||||
.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target_id.to_string(),
|
||||
user: user.id.clone(),
|
||||
user,
|
||||
status: RelationshipStatus::Friend
|
||||
}
|
||||
.publish(target_id.to_string())
|
||||
@@ -121,16 +126,18 @@ pub async fn req(user: User, username: String) -> Result<JsonValue> {
|
||||
)
|
||||
) {
|
||||
Ok(_) => {
|
||||
let target_user = target_user.from_override(&user, RelationshipStatus::Outgoing).await?;
|
||||
let user = user.from_override(&target_user, RelationshipStatus::Incoming).await?;
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target_id.to_string(),
|
||||
user: target_user,
|
||||
status: RelationshipStatus::Outgoing
|
||||
}
|
||||
.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target_id.to_string(),
|
||||
user: user.id.clone(),
|
||||
user,
|
||||
status: RelationshipStatus::Incoming
|
||||
}
|
||||
.publish(target_id.to_string())
|
||||
|
||||
@@ -10,6 +10,8 @@ use rocket_contrib::json::JsonValue;
|
||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
let col = get_collection("users");
|
||||
|
||||
let target = target.fetch_user().await?;
|
||||
|
||||
match get_relationship(&user, &target.id) {
|
||||
RelationshipStatus::User | RelationshipStatus::Blocked => Err(Error::NoEffect),
|
||||
RelationshipStatus::BlockedOther => {
|
||||
@@ -33,7 +35,7 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
user: target,
|
||||
status: RelationshipStatus::Blocked,
|
||||
}
|
||||
.publish(user.id.clone())
|
||||
@@ -74,19 +76,23 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
)
|
||||
) {
|
||||
Ok(_) => {
|
||||
let target = target.from_override(&user, RelationshipStatus::Friend).await?;
|
||||
let user = user.from_override(&target, RelationshipStatus::Friend).await?;
|
||||
let target_id = target.id.clone();
|
||||
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
user: target,
|
||||
status: RelationshipStatus::Blocked
|
||||
}
|
||||
.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target.id.clone(),
|
||||
user: user.id.clone(),
|
||||
id: target_id.clone(),
|
||||
user,
|
||||
status: RelationshipStatus::BlockedOther
|
||||
}
|
||||
.publish(target.id.clone())
|
||||
.publish(target_id)
|
||||
)
|
||||
.ok();
|
||||
|
||||
@@ -128,19 +134,23 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
)
|
||||
) {
|
||||
Ok(_) => {
|
||||
let target = target.from_override(&user, RelationshipStatus::Blocked).await?;
|
||||
let user = user.from_override(&target, RelationshipStatus::BlockedOther).await?;
|
||||
let target_id = target.id.clone();
|
||||
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
user: target,
|
||||
status: RelationshipStatus::Blocked
|
||||
}
|
||||
.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target.id.clone(),
|
||||
user: user.id.clone(),
|
||||
id: target_id.clone(),
|
||||
user,
|
||||
status: RelationshipStatus::BlockedOther
|
||||
}
|
||||
.publish(target.id.clone())
|
||||
.publish(target_id)
|
||||
)
|
||||
.ok();
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ use rocket_contrib::json::JsonValue;
|
||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
let col = get_collection("users");
|
||||
|
||||
let target = target.fetch_user().await?;
|
||||
|
||||
match get_relationship(&user, &target.id) {
|
||||
RelationshipStatus::Friend
|
||||
| RelationshipStatus::Outgoing
|
||||
@@ -43,19 +45,23 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
)
|
||||
) {
|
||||
Ok(_) => {
|
||||
let target = target.from_override(&user, RelationshipStatus::None).await?;
|
||||
let user = user.from_override(&target, RelationshipStatus::None).await?;
|
||||
let target_id = target.id.clone();
|
||||
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
user: target,
|
||||
status: RelationshipStatus::None
|
||||
}
|
||||
.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target.id.clone(),
|
||||
user: user.id.clone(),
|
||||
id: target_id.clone(),
|
||||
user,
|
||||
status: RelationshipStatus::None
|
||||
}
|
||||
.publish(target.id.clone())
|
||||
.publish(target_id)
|
||||
)
|
||||
.ok();
|
||||
|
||||
|
||||
@@ -9,10 +9,11 @@ use rocket_contrib::json::JsonValue;
|
||||
#[delete("/<target>/block")]
|
||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
let col = get_collection("users");
|
||||
let target = target.fetch_user().await?;
|
||||
|
||||
match get_relationship(&user, &target.id) {
|
||||
RelationshipStatus::Blocked => {
|
||||
match get_relationship(&target.fetch_user().await?, &user.id) {
|
||||
match get_relationship(&target, &user.id) {
|
||||
RelationshipStatus::Blocked => {
|
||||
col.update_one(
|
||||
doc! {
|
||||
@@ -32,9 +33,10 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
let target = target.from_override(&user, RelationshipStatus::BlockedOther).await?;
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
user: target,
|
||||
status: RelationshipStatus::BlockedOther,
|
||||
}
|
||||
.publish(user.id.clone())
|
||||
@@ -73,19 +75,23 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
)
|
||||
) {
|
||||
Ok(_) => {
|
||||
let target = target.from_override(&user, RelationshipStatus::None).await?;
|
||||
let user = user.from_override(&target, RelationshipStatus::None).await?;
|
||||
let target_id = target.id.clone();
|
||||
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
user: target,
|
||||
status: RelationshipStatus::None
|
||||
}
|
||||
.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target.id.clone(),
|
||||
user: user.id.clone(),
|
||||
id: target_id.clone(),
|
||||
user: user,
|
||||
status: RelationshipStatus::None
|
||||
}
|
||||
.publish(target.id.clone())
|
||||
.publish(target_id)
|
||||
)
|
||||
.ok();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user