-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add autojoin and show join leave events (#587)
space payload snapshot channel metadata includes new `ChannelSettings` message with fields for - autojoin - hide user join and leave events These can be optionally included in the Channel Inception message, if not all fields are false by default. Two new messages on Space Payload to manually toggle these two settings, as well as client endpoints. migration sets autojoin as true for default channels (22 trailing 0s), but from this PR on all channels will be not autojoin unless explicitly toggled on. snapshot migrations apply these defaults. e2e tests validate: - settings properly set on channel inception - client events emitted on changes to both settings - client space streamview state updates appropriately in response to inception and update messages - only permitted users can update these properties
- Loading branch information
Showing
21 changed files
with
2,509 additions
and
1,144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package migrations | ||
|
||
import ( | ||
. "github.com/river-build/river/core/node/protocol" | ||
"github.com/river-build/river/core/node/shared" | ||
) | ||
|
||
func snapshot_migration_0002(iSnapshot *Snapshot) *Snapshot { | ||
switch snapshot := iSnapshot.Content.(type) { | ||
case *Snapshot_SpaceContent: | ||
for _, channel := range snapshot.SpaceContent.Channels { | ||
if channel.Settings == nil { | ||
channel.Settings = &SpacePayload_ChannelSettings{} | ||
} | ||
channelId, err := shared.StreamIdFromBytes(channel.ChannelId) | ||
if err != nil { | ||
// Note: it would be better to log this error, but we have no logging | ||
// context here at this time | ||
continue | ||
} | ||
if shared.IsDefaultChannelId(channelId) { | ||
channel.Settings.Autojoin = true | ||
} | ||
} | ||
} | ||
return iSnapshot | ||
} |
54 changes: 54 additions & 0 deletions
54
core/node/events/migrations/snapshot_migration_0002_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package migrations | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
. "github.com/river-build/river/core/node/protocol" | ||
|
||
"github.com/river-build/river/core/node/shared" | ||
) | ||
|
||
func TestSnapshotMigration0002(t *testing.T) { | ||
spaceId, err := shared.MakeSpaceId() | ||
require.NoError(t, err) | ||
|
||
defaultChannelId, err := shared.MakeDefaultChannelId(spaceId) | ||
require.NoError(t, err) | ||
|
||
channelId1, err := shared.MakeChannelId(spaceId) | ||
require.NoError(t, err) | ||
|
||
spaceSnap := &Snapshot{ | ||
Content: &Snapshot_SpaceContent{ | ||
SpaceContent: &SpacePayload_Snapshot{ | ||
Inception: &SpacePayload_Inception{ | ||
StreamId: spaceId[:], | ||
}, | ||
Channels: []*SpacePayload_ChannelMetadata{ | ||
{ | ||
ChannelId: defaultChannelId[:], | ||
}, | ||
{ | ||
ChannelId: channelId1[:], | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
migratedSnapshot := snapshot_migration_0002(spaceSnap) | ||
|
||
require.Equal(t, 2, len(migratedSnapshot.GetSpaceContent().Channels)) | ||
|
||
require.True(t, bytes.Equal(migratedSnapshot.GetSpaceContent().Channels[0].ChannelId, defaultChannelId[:])) | ||
require.True(t, bytes.Equal(migratedSnapshot.GetSpaceContent().Channels[1].ChannelId, channelId1[:])) | ||
|
||
require.True(t, migratedSnapshot.GetSpaceContent().Channels[0].Settings.Autojoin) | ||
require.False(t, migratedSnapshot.GetSpaceContent().Channels[1].Settings.Autojoin) | ||
|
||
require.False(t, migratedSnapshot.GetSpaceContent().Channels[0].Settings.HideUserJoinLeaveEvents) | ||
require.False(t, migratedSnapshot.GetSpaceContent().Channels[1].Settings.HideUserJoinLeaveEvents) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.