mirror of
https://github.com/stoatchat/javascript-client-sdk.git
synced 2026-07-19 17:13:31 -04:00
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:
+10
-1
@@ -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
@@ -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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user