forked from Mirrors/gomuks
hicli/send: add /rawstate command
This commit is contained in:
parent
57e067b671
commit
8b1354b4a7
3 changed files with 15 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue