Skip to content

Commit a672fea

Browse files
authored
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>
1 parent 46b20bd commit a672fea

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/classes/Bot.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { decodeTime } from "ulid";
33

44
import type { BotCollection } from "../collections/BotCollection.js";
55
import type { BotFlags } from "../hydration/bot.js";
6+
import { hydrate } from "../hydration/index.js";
67

78
import { PublicBot } from "./PublicBot.js";
89
import type { User } from "./User.js";
@@ -139,7 +140,15 @@ export class Bot {
139140
* @param data Changes
140141
*/
141142
async edit(data: DataEditBot): Promise<void> {
142-
await this.#collection.client.api.patch(`/bots/${this.id as ""}`, data);
143+
this.#collection.updateUnderlyingObject(
144+
this.id,
145+
hydrate(
146+
"bot",
147+
await this.#collection.client.api.patch(`/bots/${this.id as ""}`, data),
148+
this.#collection.client,
149+
false,
150+
),
151+
);
143152
}
144153

145154
/**

src/classes/User.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { User as APIUser, DataEditUser, Presence } from "stoat-api";
22
import { decodeTime } from "ulid";
33

44
import type { UserCollection } from "../collections/UserCollection.js";
5+
import { hydrate } from "../hydration/index.js";
56
import { U32_MAX, UserPermission } from "../permissions/definitions.js";
67

78
import type { Channel } from "./Channel.js";
@@ -225,11 +226,19 @@ export class User {
225226
* @param data Changes
226227
*/
227228
async edit(data: DataEditUser): Promise<void> {
228-
await this.#collection.client.api.patch(
229-
`/users/${
230-
this.id === this.#collection.client.user?.id ? "@me" : this.id
231-
}`,
232-
data,
229+
this.#collection.updateUnderlyingObject(
230+
this.id,
231+
hydrate(
232+
"user",
233+
await this.#collection.client.api.patch(
234+
`/users/${
235+
this.id === this.#collection.client.user?.id ? "@me" : this.id
236+
}`,
237+
data,
238+
),
239+
this.#collection.client,
240+
false,
241+
),
233242
);
234243
}
235244

0 commit comments

Comments
 (0)