1
0
Fork 0
forked from Mirrors/gomuks

hicli/send: add /rawstate command

This commit is contained in:
Tulir Asokan 2024-12-27 16:48:45 +02:00
parent 57e067b671
commit 8b1354b4a7
3 changed files with 15 additions and 2 deletions

View file

@ -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

View file

@ -211,8 +211,10 @@ export default class Client {
throw new Error("Room not found")
}
const dbEvent = await this.rpc.sendMessage(params)
if (dbEvent) {
this.#handleOutgoingEvent(dbEvent, room)
}
}
async subscribeToEmojiPack(pack: RoomStateGUID, subscribe: boolean = true) {
const emoteRooms = (this.store.accountData.get("im.ponies.emote_rooms") ?? {}) as ImagePackRooms

View file

@ -138,7 +138,7 @@ export default abstract class RPCClient {
return this.request("logout", {})
}
sendMessage(params: SendMessageParams): Promise<RawDBEvent> {
sendMessage(params: SendMessageParams): Promise<RawDBEvent | null> {
return this.request("send_message", params)
}