mattermost/model/websocket_request.go
Jesús Espino 5dd2e75c10
Extracting i18n functionality to i18n core library (#16914)
* extracting i18n functionality to i18n core library

* Removing utils.T

* Adding documentation and changing one function name for better explanation

* Changing other missing utils.T

* Adding license string

* Renaming corelibs to pkg

* Renaming corelibs to pkg (moving directory)

* Renaming from pkg to shared

* Fixing bodyPage.Html casing

* Fixing merges

* Fixing merge problem

* Fixing tests
2021-02-26 08:12:49 +01:00

35 lines
1 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
import (
"encoding/json"
"io"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
// WebSocketRequest represents a request made to the server through a websocket.
type WebSocketRequest struct {
// Client-provided fields
Seq int64 `json:"seq"` // A counter which is incremented for every request made.
Action string `json:"action"` // The action to perform for a request. For example: get_statuses, user_typing.
Data map[string]interface{} `json:"data"` // The metadata for an action.
// Server-provided fields
Session Session `json:"-"`
T i18n.TranslateFunc `json:"-"`
Locale string `json:"-"`
}
func (o *WebSocketRequest) ToJson() string {
b, _ := json.Marshal(o)
return string(b)
}
func WebSocketRequestFromJson(data io.Reader) *WebSocketRequest {
var o *WebSocketRequest
json.NewDecoder(data).Decode(&o)
return o
}