diff --git a/types/types.go b/types/types.go index 4920a1a..c76f74e 100644 --- a/types/types.go +++ b/types/types.go @@ -28,6 +28,24 @@ func (le LemmyError) Error() string { } type LemmyWebSocketMsg struct { - Op UserOperation `json:"op"` + Op string `json:"op"` Data json.RawMessage `json:"data"` } + +// IsOneOf checks if the message is one of the given operation. +// Operations must be of type UserOperation or UserOperationCrud. +func (msg LemmyWebSocketMsg) IsOneOf(ops ...any) bool { + for _, op := range ops { + switch op := op.(type) { + case UserOperation: + if string(op) == msg.Op { + return true + } + case UserOperationCrud: + if string(op) == msg.Op { + return true + } + } + } + return false +} diff --git a/websocket.go b/websocket.go index 9394e1e..c9e4df1 100644 --- a/websocket.go +++ b/websocket.go @@ -99,7 +99,7 @@ func (c *WSClient) Request(op types.UserOperation, data any) error { } return c.conn.WriteJSON(types.LemmyWebSocketMsg{ - Op: op, + Op: string(op), Data: d, }) }