forked from jmug/stoatchat
Get notifications working properly.
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, User},
|
||||
@@ -49,7 +49,22 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
None
|
||||
)
|
||||
) {
|
||||
Ok(_) => Ok(json!({ "status": "Friend" })),
|
||||
Ok(_) => {
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
status: RelationshipStatus::Friend
|
||||
}.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target.id.clone(),
|
||||
user: user.id.clone(),
|
||||
status: RelationshipStatus::Friend
|
||||
}.publish(target.id.clone())
|
||||
).ok();
|
||||
|
||||
Ok(json!({ "status": "Friend" }))
|
||||
},
|
||||
Err(_) => Err(Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
@@ -87,7 +102,25 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
None
|
||||
)
|
||||
) {
|
||||
Ok(_) => Ok(json!({ "status": "Outgoing" })),
|
||||
Ok(_) => {
|
||||
try_join!(
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: user.id.clone(),
|
||||
user: target.id.clone(),
|
||||
status: RelationshipStatus::Outgoing
|
||||
}.publish(user.id.clone()),
|
||||
ClientboundNotification::UserRelationship {
|
||||
id: target.id.clone(),
|
||||
user: user.id.clone(),
|
||||
status: RelationshipStatus::Incoming
|
||||
}.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": "Outgoing" }))
|
||||
},
|
||||
Err(_) => Err(Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
|
||||
Reference in New Issue
Block a user