Add IsOneOf to websocket message
This commit is contained in:
parent
cdd67e35a3
commit
cf871efc23
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user