Changes the event to send when a channel is shared or unshared (#28183)
* Changes the event to send when a channel is shared or unshared Before we were sending the CHANNEL_CONVERTED websockets event, which is intended to notify of a public channel being converted into a private one, so the interface was showing the channel as private until the client was refreshed. Now a full channel update event is sent when the channel is shared or unshared, so the interface gets the new information correctly. * Fix message type on command tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
cae456de2d
Коммит
d2c69fbf95
@@ -26,7 +26,7 @@ func setupForSharedChannels(tb testing.TB) *TestHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShareProviderDoCommand(t *testing.T) {
|
func TestShareProviderDoCommand(t *testing.T) {
|
||||||
t.Run("share command sends a websocket channel converted event", func(t *testing.T) {
|
t.Run("share command sends a websocket channel updated event", func(t *testing.T) {
|
||||||
th := setupForSharedChannels(t).initBasic()
|
th := setupForSharedChannels(t).initBasic()
|
||||||
defer th.tearDown()
|
defer th.tearDown()
|
||||||
|
|
||||||
@@ -52,14 +52,14 @@ func TestShareProviderDoCommand(t *testing.T) {
|
|||||||
response := commandProvider.DoCommand(th.App, th.Context, args, "")
|
response := commandProvider.DoCommand(th.App, th.Context, args, "")
|
||||||
require.Equal(t, "##### "+args.T("api.command_share.channel_shared"), response.Text)
|
require.Equal(t, "##### "+args.T("api.command_share.channel_shared"), response.Text)
|
||||||
|
|
||||||
channelConvertedMessages := testCluster.SelectMessages(func(msg *model.ClusterMessage) bool {
|
channelUpdatedMessages := testCluster.SelectMessages(func(msg *model.ClusterMessage) bool {
|
||||||
event, err := model.WebSocketEventFromJSON(bytes.NewReader(msg.Data))
|
event, err := model.WebSocketEventFromJSON(bytes.NewReader(msg.Data))
|
||||||
return err == nil && event.EventType() == model.WebsocketEventChannelConverted
|
return err == nil && event.EventType() == model.WebsocketEventChannelUpdated
|
||||||
})
|
})
|
||||||
assert.Len(t, channelConvertedMessages, 1) // one msg for share creation
|
assert.Len(t, channelUpdatedMessages, 1) // one msg for share creation
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("unshare command sends a websocket channel converted event", func(t *testing.T) {
|
t.Run("unshare command sends a websocket channel updated event", func(t *testing.T) {
|
||||||
th := setupForSharedChannels(t).initBasic()
|
th := setupForSharedChannels(t).initBasic()
|
||||||
defer th.tearDown()
|
defer th.tearDown()
|
||||||
|
|
||||||
@@ -84,11 +84,11 @@ func TestShareProviderDoCommand(t *testing.T) {
|
|||||||
response := commandProvider.DoCommand(th.App, th.Context, args, "")
|
response := commandProvider.DoCommand(th.App, th.Context, args, "")
|
||||||
require.Equal(t, "##### "+args.T("api.command_share.shared_channel_unavailable"), response.Text)
|
require.Equal(t, "##### "+args.T("api.command_share.shared_channel_unavailable"), response.Text)
|
||||||
|
|
||||||
channelConvertedMessages := testCluster.SelectMessages(func(msg *model.ClusterMessage) bool {
|
channelUpdatedMessages := testCluster.SelectMessages(func(msg *model.ClusterMessage) bool {
|
||||||
event, err := model.WebSocketEventFromJSON(bytes.NewReader(msg.Data))
|
event, err := model.WebSocketEventFromJSON(bytes.NewReader(msg.Data))
|
||||||
return err == nil && event.EventType() == model.WebsocketEventChannelConverted
|
return err == nil && event.EventType() == model.WebsocketEventChannelUpdated
|
||||||
})
|
})
|
||||||
require.Len(t, channelConvertedMessages, 2) // one msg for share creation, one for unshare.
|
require.Len(t, channelUpdatedMessages, 2) // one msg for share creation, one for unshare.
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invite remote to channel shared with us", func(t *testing.T) {
|
t.Run("invite remote to channel shared with us", func(t *testing.T) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package sharedchannel
|
package sharedchannel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -257,8 +258,17 @@ func (scs *Service) onConnectionStateChange(rc *model.RemoteCluster, online bool
|
|||||||
|
|
||||||
func (scs *Service) notifyClientsForSharedChannelConverted(channel *model.Channel) {
|
func (scs *Service) notifyClientsForSharedChannelConverted(channel *model.Channel) {
|
||||||
scs.platform.InvalidateCacheForChannel(channel)
|
scs.platform.InvalidateCacheForChannel(channel)
|
||||||
messageWs := model.NewWebSocketEvent(model.WebsocketEventChannelConverted, channel.TeamId, "", "", nil, "")
|
messageWs := model.NewWebSocketEvent(model.WebsocketEventChannelUpdated, "", channel.Id, "", nil, "")
|
||||||
messageWs.Add("channel_id", channel.Id)
|
channelJSON, err := json.Marshal(channel)
|
||||||
|
if err != nil {
|
||||||
|
scs.server.Log().Log(mlog.LvlSharedChannelServiceWarn, "Cannot marshal channel to notify clients",
|
||||||
|
mlog.String("channel_id", channel.Id),
|
||||||
|
mlog.Err(err),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
messageWs.Add("channel", string(channelJSON))
|
||||||
|
|
||||||
scs.app.Publish(messageWs)
|
scs.app.Publish(messageWs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ func (scs *Service) ShareChannel(sc *model.SharedChannel) (*model.SharedChannel,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// to avoid fetching the channel again, we manually set the shared
|
||||||
|
// flag before notifying the clients
|
||||||
|
channel.Shared = model.NewPointer(true)
|
||||||
|
|
||||||
scs.notifyClientsForSharedChannelConverted(channel)
|
scs.notifyClientsForSharedChannelConverted(channel)
|
||||||
return scNew, nil
|
return scNew, nil
|
||||||
@@ -93,6 +96,9 @@ func (scs *Service) UnshareChannel(channelID string) (bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
// to avoid fetching the channel again, we manually set the shared
|
||||||
|
// flag before notifying the clients
|
||||||
|
channel.Shared = model.NewPointer(false)
|
||||||
|
|
||||||
scs.notifyClientsForSharedChannelConverted(channel)
|
scs.notifyClientsForSharedChannelConverted(channel)
|
||||||
return deleted, nil
|
return deleted, nil
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user