| 1 | import type * as ivschat from "@distilled.cloud/aws/ivschat"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Room } from "./Room.ts"; |
| 5 | |
| 6 | /** |
| 7 | * The `roomIdentifier` is injected by the binding from the bound room; |
| 8 | * the caller supplies the target message `id` and an optional `reason`. |
| 9 | */ |
| 10 | export interface DeleteMessageRequest extends Omit< |
| 11 | ivschat.DeleteMessageRequest, |
| 12 | "roomIdentifier" |
| 13 | > {} |
| 14 | |
| 15 | /** |
| 16 | * Moderate the bound room by deleting a message — the effectful call made |
| 17 | * from a deployed Lambda or Task. It broadcasts a `DELETEMESSAGE` event to |
| 18 | * every connected client, directing them to remove the message (`id` is the |
| 19 | * ID from the WebSocket `SendMessage` response); an optional `reason` is |
| 20 | * attached to the event. |
| 21 | * |
| 22 | * ### Moderating Messages |
| 23 | * Provide the `DeleteMessageHttp` implementation layer on the Function |
| 24 | * effect, bind the room in the init phase, then call the returned client at |
| 25 | * runtime. The binding grants `ivschat:DeleteMessage` on the room and |
| 26 | * injects its ARN as the `roomIdentifier` automatically. |
| 27 | * |
| 28 | * **Example:** Delete a message from a Lambda |
| 29 | * ```typescript |
| 30 | * // init |
| 31 | * const room = yield* IVSChat.Room("LiveChat"); |
| 32 | * const deleteMessage = yield* IVSChat.DeleteMessage(room); |
| 33 | * |
| 34 | * return { |
| 35 | * fetch: Effect.gen(function* () { |
| 36 | * // runtime |
| 37 | * const { id } = yield* deleteMessage({ |
| 38 | * id: flaggedMessageId, |
| 39 | * reason: "abusive content", |
| 40 | * }); |
| 41 | * return HttpServerResponse.json({ deleted: id }); |
| 42 | * }), |
| 43 | * }; |
| 44 | * // on the Function effect: |
| 45 | * // .pipe(Effect.provide(IVSChat.DeleteMessageHttp)) |
| 46 | * ``` |
| 47 | * |
| 48 | * @binding |
| 49 | */ |
| 50 | export interface DeleteMessage extends Binding.Service< |
| 51 | DeleteMessage, |
| 52 | "AWS.IVSChat.DeleteMessage", |
| 53 | ( |
| 54 | room: Room, |
| 55 | ) => Effect.Effect< |
| 56 | ( |
| 57 | request: DeleteMessageRequest, |
| 58 | ) => Effect.Effect< |
| 59 | ivschat.DeleteMessageResponse, |
| 60 | ivschat.DeleteMessageError |
| 61 | > |
| 62 | > |
| 63 | > {} |
| 64 | export const DeleteMessage = Binding.Service<DeleteMessage>( |
| 65 | "AWS.IVSChat.DeleteMessage", |
| 66 | ); |