Unverified Commit c37d153f authored by Saturnino Abril's avatar Saturnino Abril Committed by GitHub

[MM-10519] Send websocket event whenever the channel has changed it's type (public|private) (#8798)

* send websocket event whenever the channel has changed it's type (public|private)

* updated per comment
Signed-off-by: default avatarSaturnino Abril <saturnino.abril@gmail.com>

* add channel_converted websocket event
Signed-off-by: default avatarSaturnino Abril <saturnino.abril@gmail.com>

* only send channel_id via websocket message for "channel_converted" event
Signed-off-by: default avatarSaturnino Abril <saturnino.abril@gmail.com>
parent c3e9c414
......@@ -11,6 +11,7 @@ import (
"strconv"
"strings"
"testing"
"time"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
......@@ -933,12 +934,42 @@ func TestConvertChannelToPrivate(t *testing.T) {
t.Fatal("should not return a channel")
}
WebSocketClient, err := th.CreateWebSocketClient()
if err != nil {
t.Fatal(err)
}
WebSocketClient.Listen()
publicChannel2 := th.CreatePublicChannel()
rchannel, resp = th.SystemAdminClient.ConvertChannelToPrivate(publicChannel2.Id)
CheckOKStatus(t, resp)
if rchannel.Type != model.CHANNEL_PRIVATE {
t.Fatal("channel should be converted from public to private")
}
stop := make(chan bool)
eventHit := false
go func() {
for {
select {
case resp := <-WebSocketClient.EventChannel:
if resp.Event == model.WEBSOCKET_EVENT_CHANNEL_CONVERTED && resp.Data["channel_id"].(string) == publicChannel2.Id {
eventHit = true
}
case <-stop:
return
}
}
}()
time.Sleep(400 * time.Millisecond)
stop <- true
if !eventHit {
t.Fatal("did not receive channel_converted event")
}
}
func TestRestoreChannel(t *testing.T) {
......
......@@ -366,6 +366,12 @@ func (a *App) UpdateChannelPrivacy(oldChannel *model.Channel, user *model.User)
return channel, err
}
a.InvalidateCacheForChannel(channel)
messageWs := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_CONVERTED, channel.TeamId, "", "", nil)
messageWs.Add("channel_id", channel.Id)
a.Publish(messageWs)
return channel, nil
}
}
......
......@@ -14,8 +14,9 @@ const (
WEBSOCKET_EVENT_POSTED = "posted"
WEBSOCKET_EVENT_POST_EDITED = "post_edited"
WEBSOCKET_EVENT_POST_DELETED = "post_deleted"
WEBSOCKET_EVENT_CHANNEL_DELETED = "channel_deleted"
WEBSOCKET_EVENT_CHANNEL_CONVERTED = "channel_converted"
WEBSOCKET_EVENT_CHANNEL_CREATED = "channel_created"
WEBSOCKET_EVENT_CHANNEL_DELETED = "channel_deleted"
WEBSOCKET_EVENT_CHANNEL_UPDATED = "channel_updated"
WEBSOCKET_EVENT_CHANNEL_MEMBER_UPDATED = "channel_member_updated"
WEBSOCKET_EVENT_DIRECT_ADDED = "direct_added"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment