fix: hydrate Bot and User when using edit() (#147)

* fix: hydrate Bot and User when using edit()

closes #146

Signed-off-by: Amy <amy+git@amogus.cloud>

* chore: run formatter

Signed-off-by: Amy <amy+git@amogus.cloud>

---------

Signed-off-by: Amy <amy+git@amogus.cloud>
This commit is contained in:
Amy
2026-05-10 20:15:26 -04:00
committed by GitHub
parent 46b20bd7f7
commit a672fea424
2 changed files with 24 additions and 6 deletions
+10 -1
View File
@@ -3,6 +3,7 @@ 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";
@@ -139,7 +140,15 @@ export class Bot {
* @param data Changes
*/
async edit(data: DataEditBot): Promise<void> {
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,
),
);
}
/**
+14 -5
View File
@@ -2,6 +2,7 @@ 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";
@@ -225,11 +226,19 @@ export class User {
* @param data Changes
*/
async edit(data: DataEditUser): Promise<void> {
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,
),
);
}