fix(bonfire): Ready event should include user with online status true (if applicable)

This commit is contained in:
Paul Makles
2024-06-25 21:02:27 +01:00
parent 1d5dae4751
commit c5f4b94aa5
9 changed files with 24 additions and 8 deletions

1
Cargo.lock generated
View File

@@ -3572,6 +3572,7 @@ dependencies = [
"revolt-database", "revolt-database",
"revolt-models", "revolt-models",
"revolt-permissions", "revolt-permissions",
"revolt-presence",
"revolt-result", "revolt-result",
"revolt_rocket_okapi", "revolt_rocket_okapi",
"rocket", "rocket",

View File

@@ -180,7 +180,7 @@ impl State {
.collect(); .collect();
// Make sure we see our own user correctly. // Make sure we see our own user correctly.
users.push(user.into_self().await); users.push(user.into_self(true).await);
// Set subscription state internally. // Set subscription state internally.
self.reset_state().await; self.reset_state().await;
@@ -540,6 +540,20 @@ impl State {
} }
} }
EventV1::Message(message) => {
// Since Message events are fanned out to many clients,
// we must reconstruct the relationship value at this end.
if let Some(user) = &mut message.user {
user.relationship = self
.cache
.users
.get(&self.cache.user_id)
.expect("missing self?")
.relationship_with(&message.author)
.into();
}
}
_ => {} _ => {}
} }

View File

@@ -77,6 +77,7 @@ revolt-models = { path = "../core/models", features = [
"validator", "validator",
"rocket", "rocket",
] } ] }
revolt-presence = { path = "../core/presence" }
revolt-result = { path = "../core/result", features = ["rocket", "okapi"] } revolt-result = { path = "../core/result", features = ["rocket", "okapi"] }
revolt-permissions = { path = "../core/permissions", features = ["schemas"] } revolt-permissions = { path = "../core/permissions", features = ["schemas"] }

View File

@@ -24,7 +24,7 @@ pub async fn fetch_owned_bots(db: &State<Database>, user: User) -> Result<Json<O
users.sort_by(|a, b| a.id.cmp(&b.id)); users.sort_by(|a, b| a.id.cmp(&b.id));
Ok(Json(OwnedBotsResponse { Ok(Json(OwnedBotsResponse {
users: join_all(users.into_iter().map(|user| user.into_self())).await, users: join_all(users.into_iter().map(|user| user.into_self(false))).await,
bots: bots.into_iter().map(|bot| bot.into()).collect(), bots: bots.into_iter().map(|bot| bot.into()).collect(),
})) }))
} }

View File

@@ -48,7 +48,7 @@ pub async fn complete(
Ok(Json( Ok(Json(
User::create(db, data.username, session.user_id, None) User::create(db, data.username, session.user_id, None)
.await? .await?
.into_self() .into_self(false)
.await, .await,
)) ))
} }

View File

@@ -36,7 +36,7 @@ pub async fn list(
) )
.await? .await?
.into_iter() .into_iter()
.map(|u| u.into_self()), .map(|u| u.into_self(false)),
) )
.await; .await;

View File

@@ -52,7 +52,7 @@ pub async fn edit(
&& data.flags.is_none() && data.flags.is_none()
&& data.remove.is_none() && data.remove.is_none()
{ {
return Ok(Json(user.into_self().await)); return Ok(Json(user.into_self(false).await));
} }
// 1. Remove fields from object // 1. Remove fields from object
@@ -126,5 +126,5 @@ pub async fn edit(
) )
.await?; .await?;
Ok(Json(user.into_self().await)) Ok(Json(user.into_self(false).await))
} }

View File

@@ -9,5 +9,5 @@ use rocket::serde::json::Json;
#[openapi(tag = "User Information")] #[openapi(tag = "User Information")]
#[get("/@me")] #[get("/@me")]
pub async fn fetch(user: User) -> Result<Json<v0::User>> { pub async fn fetch(user: User) -> Result<Json<v0::User>> {
Ok(Json(user.into_self().await)) Ok(Json(user.into_self(false).await))
} }

View File

@@ -15,7 +15,7 @@ use rocket::{serde::json::Json, State};
#[get("/<target>")] #[get("/<target>")]
pub async fn fetch(db: &State<Database>, user: User, target: Reference) -> Result<Json<v0::User>> { pub async fn fetch(db: &State<Database>, user: User, target: Reference) -> Result<Json<v0::User>> {
if user.id == target.id { if user.id == target.id {
return Ok(Json(user.into_self().await)); return Ok(Json(user.into_self(false).await));
} }
let target = target.as_user(db).await?; let target = target.as_user(db).await?;