Add Operation interface
This commit is contained in:
parent
9ef13bb413
commit
187da56546
@ -32,9 +32,8 @@ type LemmyWebSocketMsg struct {
|
||||
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 {
|
||||
// IsOneOf checks if the message is one of the given operations.
|
||||
func (msg LemmyWebSocketMsg) IsOneOf(ops ...Operation) bool {
|
||||
for _, op := range ops {
|
||||
switch op := op.(type) {
|
||||
case UserOperation:
|
||||
@ -49,3 +48,15 @@ func (msg LemmyWebSocketMsg) IsOneOf(ops ...any) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type Operation interface {
|
||||
Operation() string
|
||||
}
|
||||
|
||||
func (u UserOperation) Operation() string {
|
||||
return string(u)
|
||||
}
|
||||
|
||||
func (u UserOperationCrud) Operation() string {
|
||||
return string(u)
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ func (c *WSClient) ClientLogin(ctx context.Context, l types.Login) error {
|
||||
// the authentication token will be sent instead. If data
|
||||
// has an Auth field, it will be set to the authentication
|
||||
// token automatically.
|
||||
func (c *WSClient) Request(op types.UserOperation, data any) error {
|
||||
func (c *WSClient) Request(op types.Operation, data any) error {
|
||||
if data == nil {
|
||||
data = authData{}
|
||||
}
|
||||
@ -99,7 +99,7 @@ func (c *WSClient) Request(op types.UserOperation, data any) error {
|
||||
}
|
||||
|
||||
return c.conn.WriteJSON(types.LemmyWebSocketMsg{
|
||||
Op: string(op),
|
||||
Op: op.Operation(),
|
||||
Data: d,
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user