Show a newly created bot in the rail at once
The rail was built from page props and only knew bots it already had, so a bot the coordinator created did not appear until a reload. create_bot and add_bot_to_workspace now push server:bot-created (BotCreatedData) to everyone who sees the bot: its rail row, the workspaces it is in, and whether it belongs in that user's own chat list. useLiveBots inserts it, after the pinned coordinator outside a workspace and only when the open workspace is one it joined. liveRelay pushes created bots too, so a bot added by another process still shows.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import chatBotsSql from "@/src/utils/crew-access/chat-bots-sql";
|
||||
import grabCrewRole from "../access/grab-crew-role";
|
||||
|
||||
type Params = {
|
||||
bot_id: number | string;
|
||||
user_id: number | string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether a bot belongs in a user's own chat list (`chatBotsSql`), as
|
||||
* opposed to only a workspace they're in. Used to tell a client which
|
||||
* rail a newly created bot shows up in.
|
||||
*/
|
||||
export default async function isBotInOwnChat({ bot_id, user_id }: Params) {
|
||||
const access = chatBotsSql({ role: await grabCrewRole({ user_id }), user_id });
|
||||
|
||||
const res = await BunSQLite.sql<{ present: number }>({
|
||||
sql: `SELECT 1 AS present FROM bots b WHERE b.id = ? AND ${access.sql} LIMIT 1`,
|
||||
values: [bot_id, ...access.values],
|
||||
});
|
||||
|
||||
return Boolean(res.payload?.[0]?.present);
|
||||
}
|
||||
Reference in New Issue
Block a user