mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 05:26:59 +00:00
Add notifications to remaining routes.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::util::result::Result;
|
||||
use crate::{notifications::{events::ClientboundNotification, hive}, util::result::Result};
|
||||
use crate::{
|
||||
database::entities::RelationshipStatus, database::entities::User, database::get_collection,
|
||||
database::guards::reference::Ref, database::permissions::get_relationship, util::result::Error,
|
||||
@@ -32,6 +32,12 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
status: RelationshipStatus::Blocked
|
||||
}.publish(user.id.clone()).await.ok();
|
||||
|
||||
Ok(json!({ "status": "Blocked" }))
|
||||
}
|
||||
RelationshipStatus::None => {
|
||||
@@ -65,7 +71,25 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
None
|
||||
)
|
||||
) {
|
||||
Ok(_) => Ok(json!({ "status": "Blocked" })),
|
||||
Ok(_) => {
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
status: RelationshipStatus::Blocked
|
||||
}.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target.id.clone(),
|
||||
user: user.id.clone(),
|
||||
status: RelationshipStatus::BlockedOther
|
||||
}.publish(target.id.clone())
|
||||
).ok();
|
||||
|
||||
hive::subscribe_if_exists(user.id.clone(), target.id.clone()).ok();
|
||||
hive::subscribe_if_exists(target.id.clone(), user.id.clone()).ok();
|
||||
|
||||
Ok(json!({ "status": "Blocked" }))
|
||||
},
|
||||
Err(_) => Err(Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
@@ -101,7 +125,22 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
None
|
||||
)
|
||||
) {
|
||||
Ok(_) => Ok(json!({ "status": "Blocked" })),
|
||||
Ok(_) => {
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
status: RelationshipStatus::Blocked
|
||||
}.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target.id.clone(),
|
||||
user: user.id.clone(),
|
||||
status: RelationshipStatus::BlockedOther
|
||||
}.publish(target.id.clone())
|
||||
).ok();
|
||||
|
||||
Ok(json!({ "status": "Blocked" }))
|
||||
},
|
||||
Err(_) => Err(Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::util::result::Result;
|
||||
use crate::{notifications::{hive, events::ClientboundNotification}, util::result::Result};
|
||||
use crate::{
|
||||
database::entities::RelationshipStatus, database::entities::User, database::get_collection,
|
||||
database::guards::reference::Ref, database::permissions::get_relationship, util::result::Error,
|
||||
@@ -6,6 +6,7 @@ use crate::{
|
||||
use futures::try_join;
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use hive_pubsub::PubSub;
|
||||
|
||||
#[delete("/<target>/friend")]
|
||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
@@ -47,7 +48,26 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
None
|
||||
)
|
||||
) {
|
||||
Ok(_) => Ok(json!({ "status": "None" })),
|
||||
Ok(_) => {
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
status: RelationshipStatus::None
|
||||
}.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target.id.clone(),
|
||||
user: user.id.clone(),
|
||||
status: RelationshipStatus::None
|
||||
}.publish(target.id.clone())
|
||||
).ok();
|
||||
|
||||
let hive = hive::get_hive();
|
||||
hive.unsubscribe(&user.id, &target.id).ok();
|
||||
hive.unsubscribe(&target.id, &user.id).ok();
|
||||
|
||||
Ok(json!({ "status": "None" }))
|
||||
},
|
||||
Err(_) => Err(Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::util::result::Result;
|
||||
use crate::{notifications::{events::ClientboundNotification, hive}, util::result::Result};
|
||||
use crate::{
|
||||
database::entities::RelationshipStatus, database::entities::User, database::get_collection,
|
||||
database::guards::reference::Ref, database::permissions::get_relationship, util::result::Error,
|
||||
@@ -39,6 +39,12 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
status: RelationshipStatus::BlockedOther
|
||||
}.publish(user.id.clone()).await.ok();
|
||||
|
||||
Ok(json!({ "status": "BlockedOther" }))
|
||||
}
|
||||
RelationshipStatus::BlockedOther => {
|
||||
@@ -70,7 +76,26 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
None
|
||||
)
|
||||
) {
|
||||
Ok(_) => Ok(json!({ "status": "None" })),
|
||||
Ok(_) => {
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
status: RelationshipStatus::None
|
||||
}.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target.id.clone(),
|
||||
user: user.id.clone(),
|
||||
status: RelationshipStatus::None
|
||||
}.publish(target.id.clone())
|
||||
).ok();
|
||||
|
||||
let hive = hive::get_hive();
|
||||
hive.unsubscribe(&user.id, &target.id).ok();
|
||||
hive.unsubscribe(&target.id, &user.id).ok();
|
||||
|
||||
Ok(json!({ "status": "None" }))
|
||||
},
|
||||
Err(_) => Err(Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
|
||||
Reference in New Issue
Block a user