[MM-40638] Type all of the websocket event names as a new type WebsocketEventType (#25454)
Co-authored-by: Sudheer Tripathi <sudheer@clearglass.com> Co-authored-by: Sudheer Tripathi <31629433+sudheer121@users.noreply.github.com> Co-authored-by: Sudheer Tripathi <tripathisudheer604@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e1f72576fb
Коммит
51e73b681b
@@ -853,7 +853,7 @@ func (a *App) DeleteGroupMembers(groupID string, userIDs []string) ([]*model.Gro
|
||||
return members, nil
|
||||
}
|
||||
|
||||
func (a *App) publishGroupMemberEvent(eventName string, groupMember *model.GroupMember) *model.AppError {
|
||||
func (a *App) publishGroupMemberEvent(eventName model.WebsocketEventType, groupMember *model.GroupMember) *model.AppError {
|
||||
messageWs := model.NewWebSocketEvent(eventName, "", "", groupMember.UserId, nil, "")
|
||||
groupMemberJSON, jsonErr := json.Marshal(groupMember)
|
||||
if jsonErr != nil {
|
||||
|
||||
@@ -504,7 +504,7 @@ func TestConnectFakeWebSocket(t *testing.T) {
|
||||
msg := model.NewWebSocketEvent(model.WebsocketEventPosted, teamID, "", "", nil, "")
|
||||
th.App.Publish(msg)
|
||||
|
||||
msg = model.NewWebSocketEvent("test_event_with_data", "", "", userID, nil, "")
|
||||
msg = model.NewWebSocketEvent(model.WebsocketEventPostEdited, "", "", userID, nil, "")
|
||||
msg.Add("key1", "value1")
|
||||
msg.Add("key2", 2)
|
||||
msg.Add("key3", []string{"three", "trois"})
|
||||
@@ -515,7 +515,7 @@ func TestConnectFakeWebSocket(t *testing.T) {
|
||||
assert.Equal(t, teamID, received.GetBroadcast().TeamId)
|
||||
|
||||
received = <-messages
|
||||
require.Equal(t, "test_event_with_data", received.EventType())
|
||||
require.Equal(t, model.WebsocketEventPostEdited, received.EventType())
|
||||
assert.Equal(t, userID, received.GetBroadcast().UserId)
|
||||
// These type changes are annoying but unavoidable because event data is untyped
|
||||
assert.Equal(t, map[string]any{
|
||||
|
||||
@@ -76,7 +76,7 @@ func (ps *PlatformService) PublishPluginClusterEvent(productID string, ev model.
|
||||
}
|
||||
|
||||
func (ps *PlatformService) PublishWebSocketEvent(productID string, event string, payload map[string]any, broadcast *model.WebsocketBroadcast) {
|
||||
ev := model.NewWebSocketEvent(fmt.Sprintf("custom_%v_%v", productID, event), "", "", "", nil, "")
|
||||
ev := model.NewWebSocketEvent(model.WebsocketEventType(fmt.Sprintf("custom_%v_%v", productID, event)), "", "", "", nil, "")
|
||||
ev = ev.SetBroadcast(broadcast).SetData(payload)
|
||||
ps.Publish(ev)
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func TestConfigSave(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
metricsMock := &mocks.MetricsInterface{}
|
||||
metricsMock.On("IncrementWebsocketEvent", mock.AnythingOfType("string")).Return()
|
||||
metricsMock.On("IncrementWebsocketEvent", model.WebsocketEventConfigChanged).Return()
|
||||
metricsMock.On("IncrementWebSocketBroadcastBufferSize", mock.AnythingOfType("string"), mock.AnythingOfType("float64")).Return()
|
||||
metricsMock.On("DecrementWebSocketBroadcastBufferSize", mock.AnythingOfType("string"), mock.AnythingOfType("float64")).Return()
|
||||
metricsMock.On("Register").Return()
|
||||
|
||||
@@ -11,10 +11,11 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/utils"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/services/sharedchannel"
|
||||
)
|
||||
|
||||
var sharedChannelEventsForSync model.StringArray = []string{
|
||||
var sharedChannelEventsForSync = []model.WebsocketEventType{
|
||||
model.WebsocketEventPosted,
|
||||
model.WebsocketEventPostEdited,
|
||||
model.WebsocketEventPostDeleted,
|
||||
@@ -22,7 +23,7 @@ var sharedChannelEventsForSync model.StringArray = []string{
|
||||
model.WebsocketEventReactionRemoved,
|
||||
}
|
||||
|
||||
var sharedChannelEventsForInvitation model.StringArray = []string{
|
||||
var sharedChannelEventsForInvitation = []model.WebsocketEventType{
|
||||
model.WebsocketEventDirectAdded,
|
||||
}
|
||||
|
||||
@@ -39,7 +40,7 @@ func (ps *PlatformService) SharedChannelSyncHandler(event *model.WebSocketEvent)
|
||||
if err != nil {
|
||||
mlog.Warn(
|
||||
err.Error(),
|
||||
mlog.String("event", event.EventType()),
|
||||
mlog.String("event", string(event.EventType())),
|
||||
mlog.String("action", "content_sync"),
|
||||
)
|
||||
}
|
||||
@@ -48,17 +49,17 @@ func (ps *PlatformService) SharedChannelSyncHandler(event *model.WebSocketEvent)
|
||||
if err != nil {
|
||||
mlog.Warn(
|
||||
err.Error(),
|
||||
mlog.String("event", event.EventType()),
|
||||
mlog.String("event", string(event.EventType())),
|
||||
mlog.String("action", "invitation"),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isEligibleForEvents(syncService SharedChannelServiceIFace, event *model.WebSocketEvent, events model.StringArray) bool {
|
||||
func isEligibleForEvents(syncService SharedChannelServiceIFace, event *model.WebSocketEvent, events []model.WebsocketEventType) bool {
|
||||
return syncServiceEnabled(syncService) &&
|
||||
eventHasChannel(event) &&
|
||||
events.Contains(event.EventType())
|
||||
utils.Contains(events, event.EventType())
|
||||
}
|
||||
|
||||
func eventHasChannel(event *model.WebSocketEvent) bool {
|
||||
|
||||
@@ -54,7 +54,7 @@ func (he *HookedWebSocketEvent) Add(key string, value any) {
|
||||
he.copy.Add(key, value)
|
||||
}
|
||||
|
||||
func (he *HookedWebSocketEvent) EventType() string {
|
||||
func (he *HookedWebSocketEvent) EventType() model.WebsocketEventType {
|
||||
if he.copy == nil {
|
||||
return he.original.EventType()
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ func (wc *WebConn) writePump() {
|
||||
logData := []mlog.Field{
|
||||
mlog.String("user_id", wc.UserId),
|
||||
mlog.String("conn_id", wc.GetConnectionID()),
|
||||
mlog.String("type", msg.EventType()),
|
||||
mlog.String("type", string(msg.EventType())),
|
||||
mlog.Int("size", buf.Len()),
|
||||
}
|
||||
if evtOk {
|
||||
@@ -735,7 +735,7 @@ func (wc *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
|
||||
"websocket.slow: dropping message",
|
||||
mlog.String("user_id", wc.UserId),
|
||||
mlog.String("conn_id", wc.GetConnectionID()),
|
||||
mlog.String("type", msg.EventType()),
|
||||
mlog.String("type", string(msg.EventType())),
|
||||
)
|
||||
// Reset timer to now.
|
||||
wc.lastLogTimeSlow = time.Now()
|
||||
|
||||
@@ -36,7 +36,7 @@ func (wr *WebSocketRouter) ServeWebSocket(conn *WebConn, r *model.WebSocketReque
|
||||
return
|
||||
}
|
||||
|
||||
if r.Action == model.WebsocketAuthenticationChallenge {
|
||||
if r.Action == string(model.WebsocketAuthenticationChallenge) {
|
||||
if conn.GetSessionToken() != "" {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -957,7 +957,7 @@ func (api *PluginAPI) KVList(page, perPage int) ([]string, *model.AppError) {
|
||||
}
|
||||
|
||||
func (api *PluginAPI) PublishWebSocketEvent(event string, payload map[string]any, broadcast *model.WebsocketBroadcast) {
|
||||
ev := model.NewWebSocketEvent(fmt.Sprintf("custom_%v_%v", api.id, event), "", "", "", nil, "")
|
||||
ev := model.NewWebSocketEvent(model.WebsocketEventType(fmt.Sprintf("custom_%v_%v", api.id, event)), "", "", "", nil, "")
|
||||
ev = ev.SetBroadcast(broadcast).SetData(payload)
|
||||
api.app.Publish(ev)
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ func (a *App) GetAcknowledgementsForPostList(postList *model.PostList) (map[stri
|
||||
return acknowledgementsMap, nil
|
||||
}
|
||||
|
||||
func (a *App) sendAcknowledgementEvent(event string, acknowledgement *model.PostAcknowledgement, post *model.Post) {
|
||||
func (a *App) sendAcknowledgementEvent(event model.WebsocketEventType, acknowledgement *model.PostAcknowledgement, post *model.Post) {
|
||||
// send out that a acknowledgement has been added/removed
|
||||
message := model.NewWebSocketEvent(event, "", post.ChannelId, "", nil, "")
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ func (a *App) DeleteReactionForPost(c request.CTX, reaction *model.Reaction) *mo
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) sendReactionEvent(event string, reaction *model.Reaction, post *model.Post) {
|
||||
func (a *App) sendReactionEvent(event model.WebsocketEventType, reaction *model.Reaction, post *model.Post) {
|
||||
// send out that a reaction has been added/removed
|
||||
message := model.NewWebSocketEvent(event, "", post.ChannelId, "", nil, "")
|
||||
reactionJSON, err := json.Marshal(reaction)
|
||||
|
||||
@@ -388,7 +388,7 @@ func (a *App) RegenerateTeamInviteId(teamID string) (*model.Team, *model.AppErro
|
||||
return updatedTeam, nil
|
||||
}
|
||||
|
||||
func (a *App) sendTeamEvent(team *model.Team, event string) *model.AppError {
|
||||
func (a *App) sendTeamEvent(team *model.Team, event model.WebsocketEventType) *model.AppError {
|
||||
sanitizedTeam := &model.Team{}
|
||||
*sanitizedTeam = *team
|
||||
sanitizedTeam.Sanitize()
|
||||
|
||||
@@ -1633,7 +1633,7 @@ func TestTeamSendEvents(t *testing.T) {
|
||||
|
||||
testCluster.ClearMessages()
|
||||
|
||||
wsEvents := []string{model.WebsocketEventUpdateTeam, model.WebsocketEventRestoreTeam, model.WebsocketEventDeleteTeam}
|
||||
wsEvents := []model.WebsocketEventType{model.WebsocketEventUpdateTeam, model.WebsocketEventRestoreTeam, model.WebsocketEventDeleteTeam}
|
||||
for _, wsEvent := range wsEvents {
|
||||
appErr := th.App.sendTeamEvent(team, wsEvent)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
Ссылка в новой задаче
Block a user