From 8b1354b4a77ca0a68ef4dabb5a875e0fb8bd92b6 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 27 Dec 2024 16:48:45 +0200 Subject: [PATCH] hicli/send: add /rawstate command --- pkg/hicli/send.go | 11 +++++++++++ web/src/api/client.ts | 4 +++- web/src/api/rpc.ts | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/hicli/send.go b/pkg/hicli/send.go index 9670fac..998382f 100644 --- a/pkg/hicli/send.go +++ b/pkg/hicli/send.go @@ -91,6 +91,17 @@ func (h *HiClient) SendMessage( return nil, fmt.Errorf("invalid JSON in /raw command") } return h.send(ctx, roomID, event.Type{Type: parts[1]}, content, "", unencrypted) + } else if strings.HasPrefix(text, "/rawstate ") { + parts := strings.SplitN(text, " ", 4) + if len(parts) < 4 || len(parts[1]) == 0 { + return nil, fmt.Errorf("invalid /rawstate command") + } + content := json.RawMessage(parts[3]) + if !json.Valid(content) { + return nil, fmt.Errorf("invalid JSON in /rawstate command") + } + _, err := h.SetState(ctx, roomID, event.Type{Type: parts[1], Class: event.StateEventType}, parts[2], content) + return nil, err } var content event.MessageEventContent msgType := event.MsgText diff --git a/web/src/api/client.ts b/web/src/api/client.ts index cbdefd0..89e78a0 100644 --- a/web/src/api/client.ts +++ b/web/src/api/client.ts @@ -211,7 +211,9 @@ export default class Client { throw new Error("Room not found") } const dbEvent = await this.rpc.sendMessage(params) - this.#handleOutgoingEvent(dbEvent, room) + if (dbEvent) { + this.#handleOutgoingEvent(dbEvent, room) + } } async subscribeToEmojiPack(pack: RoomStateGUID, subscribe: boolean = true) { diff --git a/web/src/api/rpc.ts b/web/src/api/rpc.ts index 7f9004f..b967010 100644 --- a/web/src/api/rpc.ts +++ b/web/src/api/rpc.ts @@ -138,7 +138,7 @@ export default abstract class RPCClient { return this.request("logout", {}) } - sendMessage(params: SendMessageParams): Promise { + sendMessage(params: SendMessageParams): Promise { return this.request("send_message", params) }