From 1084a3eba91128768fdff5bfc6a11b1080e21dcb Mon Sep 17 00:00:00 2001 From: Amy Date: Tue, 24 Mar 2026 12:15:45 -0400 Subject: [PATCH 1/2] fix: hydrate Bot and User when using edit() closes #146 Signed-off-by: Amy --- src/classes/Bot.ts | 11 ++++++++++- src/classes/User.ts | 19 ++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/classes/Bot.ts b/src/classes/Bot.ts index 503adb12..219b92ee 100644 --- a/src/classes/Bot.ts +++ b/src/classes/Bot.ts @@ -6,6 +6,7 @@ import type { BotFlags } from "../hydration/bot.js"; import { PublicBot } from "./PublicBot.js"; import type { User } from "./User.js"; +import { hydrate } from "../hydration/index.js"; /** * Bot Class @@ -139,7 +140,15 @@ export class Bot { * @param data Changes */ async edit(data: DataEditBot): Promise { - await this.#collection.client.api.patch(`/bots/${this.id as ""}`, data); + this.#collection.updateUnderlyingObject( + this.id, + hydrate( + "bot", + await this.#collection.client.api.patch(`/bots/${this.id as ""}`, data), + this.#collection.client, + false + ) + ) } /** diff --git a/src/classes/User.ts b/src/classes/User.ts index 296650f5..04df7fef 100644 --- a/src/classes/User.ts +++ b/src/classes/User.ts @@ -7,6 +7,7 @@ import { U32_MAX, UserPermission } from "../permissions/definitions.js"; import type { Channel } from "./Channel.js"; import type { File } from "./File.js"; import { UserProfile } from "./UserProfile.js"; +import { hydrate } from "../hydration/index.js"; /** * User Class @@ -225,11 +226,19 @@ export class User { * @param data Changes */ async edit(data: DataEditUser): Promise { - await this.#collection.client.api.patch( - `/users/${ - this.id === this.#collection.client.user?.id ? "@me" : this.id - }`, - data, + this.#collection.updateUnderlyingObject( + this.id, + hydrate( + "user", + await this.#collection.client.api.patch( + `/users/${ + this.id === this.#collection.client.user?.id ? "@me" : this.id + }`, + data, + ), + this.#collection.client, + false + ) ); } From 2cc4b3f34ef012a4c4c9bc2c030b01214c28822b Mon Sep 17 00:00:00 2001 From: Amy Date: Tue, 24 Mar 2026 12:25:01 -0400 Subject: [PATCH 2/2] chore: run formatter Signed-off-by: Amy --- src/classes/Bot.ts | 14 +++++++------- src/classes/User.ts | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/classes/Bot.ts b/src/classes/Bot.ts index 219b92ee..f68a0a70 100644 --- a/src/classes/Bot.ts +++ b/src/classes/Bot.ts @@ -3,10 +3,10 @@ import { decodeTime } from "ulid"; import type { BotCollection } from "../collections/BotCollection.js"; import type { BotFlags } from "../hydration/bot.js"; +import { hydrate } from "../hydration/index.js"; import { PublicBot } from "./PublicBot.js"; import type { User } from "./User.js"; -import { hydrate } from "../hydration/index.js"; /** * Bot Class @@ -143,12 +143,12 @@ export class Bot { this.#collection.updateUnderlyingObject( this.id, hydrate( - "bot", - await this.#collection.client.api.patch(`/bots/${this.id as ""}`, data), - this.#collection.client, - false - ) - ) + "bot", + await this.#collection.client.api.patch(`/bots/${this.id as ""}`, data), + this.#collection.client, + false, + ), + ); } /** diff --git a/src/classes/User.ts b/src/classes/User.ts index 04df7fef..31cc86d9 100644 --- a/src/classes/User.ts +++ b/src/classes/User.ts @@ -2,12 +2,12 @@ import type { User as APIUser, DataEditUser, Presence } from "stoat-api"; import { decodeTime } from "ulid"; import type { UserCollection } from "../collections/UserCollection.js"; +import { hydrate } from "../hydration/index.js"; import { U32_MAX, UserPermission } from "../permissions/definitions.js"; import type { Channel } from "./Channel.js"; import type { File } from "./File.js"; import { UserProfile } from "./UserProfile.js"; -import { hydrate } from "../hydration/index.js"; /** * User Class @@ -229,16 +229,16 @@ export class User { this.#collection.updateUnderlyingObject( this.id, hydrate( - "user", - await this.#collection.client.api.patch( - `/users/${ + "user", + await this.#collection.client.api.patch( + `/users/${ this.id === this.#collection.client.user?.id ? "@me" : this.id - }`, - data, - ), - this.#collection.client, - false - ) + }`, + data, + ), + this.#collection.client, + false, + ), ); }