Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: less information sent per SessionUpdate (Backend) #4246

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions server/src/api/boards.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ func (s *Server) exportBoard(w http.ResponseWriter, r *http.Request) {

author := note.Author.String()
for _, session := range fullBoard.BoardSessions {
if session.User.ID == note.Author {
author = session.User.Name
if session.User == note.Author {
author = session.User.String()
}
}

Expand Down
6 changes: 3 additions & 3 deletions server/src/api/event_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func isModerator(clientID uuid.UUID, sessions []*dto.BoardSession) bool {
for _, session := range sessions {
if clientID == session.User.ID {
if clientID == session.User {
if session.Role == types.SessionRoleModerator || session.Role == types.SessionRoleOwner {
return true
}
Expand Down Expand Up @@ -290,7 +290,7 @@ func (boardSubscription *BoardSubscription) eventFilter(event *realtime.BoardEve
return &ret
}

if event.Type == realtime.BoardEventParticipantUpdated {
if event.Type == realtime.BoardEventParticipantSessionUpdated {
participant, err := parseParticipantUpdated(event.Data)
if err != nil {
logger.Get().Errorw("unable to parse participantUpdated in event filter", "board", boardSubscription.boardSettings.ID, "session", userID, "err", err)
Expand All @@ -299,7 +299,7 @@ func (boardSubscription *BoardSubscription) eventFilter(event *realtime.BoardEve
if isMod {
// Cache the changes of when a participant got updated
for idx, user := range boardSubscription.boardParticipants {
if user.User.ID == participant.User.ID {
if participant.User == user.User {
boardSubscription.boardParticipants[idx] = participant
}
}
Expand Down
66 changes: 33 additions & 33 deletions server/src/api/event_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (

var (
moderatorBoardSession = dto.BoardSession{
User: dto.User{ID: uuid.New()},
User: uuid.New(),
Role: types.SessionRoleModerator,
}
ownerBoardSession = dto.BoardSession{
User: dto.User{ID: uuid.New()},
User: uuid.New(),
Role: types.SessionRoleOwner,
}
participantBoardSession = dto.BoardSession{
User: dto.User{ID: uuid.New()},
User: uuid.New(),
Role: types.SessionRoleParticipant,
}
boardSessions = []*dto.BoardSession{
Expand All @@ -44,7 +44,7 @@ var (
}
aModeratorNote = dto.Note{
ID: uuid.New(),
Author: moderatorBoardSession.User.ID,
Author: moderatorBoardSession.User,
Text: "Moderator Text",
Position: dto.NotePosition{
Column: aSeeableColumn.ID,
Expand All @@ -54,7 +54,7 @@ var (
}
aParticipantNote = dto.Note{
ID: uuid.New(),
Author: participantBoardSession.User.ID,
Author: participantBoardSession.User,
Text: "User Text",
Position: dto.NotePosition{
Column: aSeeableColumn.ID,
Expand All @@ -71,7 +71,7 @@ var (
}
aOwnerNote = dto.Note{
ID: uuid.New(),
Author: ownerBoardSession.User.ID,
Author: ownerBoardSession.User,
Text: "Owner Text",
Position: dto.NotePosition{
Column: aHiddenColumn.ID,
Expand Down Expand Up @@ -134,12 +134,12 @@ var (
initEvent = InitEvent{
Type: realtime.BoardEventInit,
Data: dto.FullBoard{
Board: &dto.Board{},
Columns: []*dto.Column{&aSeeableColumn, &aHiddenColumn},
Notes: []*dto.Note{&aOwnerNote, &aModeratorNote, &aParticipantNote},
Votings: []*dto.Voting{votingData.Voting},
Votes: []*dto.Vote{},
BoardSessions: boardSessions,
Board: &dto.Board{},
Columns: []*dto.Column{&aSeeableColumn, &aHiddenColumn},
Notes: []*dto.Note{&aOwnerNote, &aModeratorNote, &aParticipantNote},
Votings: []*dto.Voting{votingData.Voting},
Votes: []*dto.Vote{},
BoardSessions: boardSessions,
BoardSessionRequests: []*dto.BoardSessionRequest{},
},
}
Expand Down Expand Up @@ -170,23 +170,23 @@ func TestEventFilter(t *testing.T) {
}

func testIsModModerator(t *testing.T) {
isMod := isModerator(moderatorBoardSession.User.ID, boardSessions)
isMod := isModerator(moderatorBoardSession.User, boardSessions)

assert.NotNil(t, isMod)
assert.True(t, isMod)
assert.Equal(t, types.SessionRoleModerator, moderatorBoardSession.Role)
}

func testIsOwnerModerator(t *testing.T) {
isMod := isModerator(ownerBoardSession.User.ID, boardSessions)
isMod := isModerator(ownerBoardSession.User, boardSessions)

assert.NotNil(t, isMod)
assert.True(t, isMod)
assert.Equal(t, types.SessionRoleOwner, ownerBoardSession.Role)
}

func testIsParticipantModerator(t *testing.T) {
isMod := isModerator(participantBoardSession.User.ID, boardSessions)
isMod := isModerator(participantBoardSession.User, boardSessions)

assert.NotNil(t, isMod)
assert.False(t, isMod)
Expand Down Expand Up @@ -240,7 +240,7 @@ func testColumnFilterAsParticipant(t *testing.T) {
Type: realtime.BoardEventColumnsUpdated,
Data: []*dto.Column{&aSeeableColumn},
}
returnedColumnEvent := boardSub.eventFilter(columnEvent, participantBoardSession.User.ID)
returnedColumnEvent := boardSub.eventFilter(columnEvent, participantBoardSession.User)

assert.Equal(t, expectedColumnEvent, returnedColumnEvent)
}
Expand All @@ -250,7 +250,7 @@ func testColumnFilterAsOwner(t *testing.T) {
Type: realtime.BoardEventColumnsUpdated,
Data: []*dto.Column{&aSeeableColumn, &aHiddenColumn},
}
returnedColumnEvent := boardSub.eventFilter(columnEvent, ownerBoardSession.User.ID)
returnedColumnEvent := boardSub.eventFilter(columnEvent, ownerBoardSession.User)

assert.Equal(t, expectedColumnEvent, returnedColumnEvent)
}
Expand All @@ -261,7 +261,7 @@ func testColumnFilterAsModerator(t *testing.T) {
Data: []*dto.Column{&aSeeableColumn, &aHiddenColumn},
}

returnedColumnEvent := boardSub.eventFilter(columnEvent, moderatorBoardSession.User.ID)
returnedColumnEvent := boardSub.eventFilter(columnEvent, moderatorBoardSession.User)

assert.Equal(t, expectedColumnEvent, returnedColumnEvent)
}
Expand All @@ -271,7 +271,7 @@ func testNoteFilterAsParticipant(t *testing.T) {
Type: realtime.BoardEventNotesUpdated,
Data: []*dto.Note{&aParticipantNote},
}
returnedNoteEvent := boardSub.eventFilter(noteEvent, participantBoardSession.User.ID)
returnedNoteEvent := boardSub.eventFilter(noteEvent, participantBoardSession.User)

assert.Equal(t, expectedNoteEvent, returnedNoteEvent)
}
Expand All @@ -281,7 +281,7 @@ func testNoteFilterAsOwner(t *testing.T) {
Type: realtime.BoardEventNotesUpdated,
Data: []*dto.Note{&aParticipantNote, &aModeratorNote, &aOwnerNote},
}
returnedNoteEvent := boardSub.eventFilter(noteEvent, ownerBoardSession.User.ID)
returnedNoteEvent := boardSub.eventFilter(noteEvent, ownerBoardSession.User)

assert.Equal(t, expectedNoteEvent, returnedNoteEvent)
}
Expand All @@ -291,7 +291,7 @@ func testNoteFilterAsModerator(t *testing.T) {
Type: realtime.BoardEventNotesUpdated,
Data: []*dto.Note{&aParticipantNote, &aModeratorNote, &aOwnerNote},
}
returnedNoteEvent := boardSub.eventFilter(noteEvent, moderatorBoardSession.User.ID)
returnedNoteEvent := boardSub.eventFilter(noteEvent, moderatorBoardSession.User)

assert.Equal(t, expectedNoteEvent, returnedNoteEvent)
}
Expand All @@ -301,7 +301,7 @@ func testFilterVotingUpdatedAsOwner(t *testing.T) {
Type: realtime.BoardEventVotingUpdated,
Data: votingData,
}
returnedVoteEvent := boardSub.eventFilter(votingEvent, ownerBoardSession.User.ID)
returnedVoteEvent := boardSub.eventFilter(votingEvent, ownerBoardSession.User)

assert.NotNil(t, returnedVoteEvent)
assert.Equal(t, expectedVotingEvent, returnedVoteEvent)
Expand All @@ -312,7 +312,7 @@ func testFilterVotingUpdatedAsModerator(t *testing.T) {
Type: realtime.BoardEventVotingUpdated,
Data: votingData,
}
returnedVoteEvent := boardSub.eventFilter(votingEvent, moderatorBoardSession.User.ID)
returnedVoteEvent := boardSub.eventFilter(votingEvent, moderatorBoardSession.User)

assert.NotNil(t, returnedVoteEvent)
assert.Equal(t, expectedVotingEvent, returnedVoteEvent)
Expand Down Expand Up @@ -342,22 +342,22 @@ func testFilterVotingUpdatedAsParticipant(t *testing.T) {
Type: realtime.BoardEventVotingUpdated,
Data: expectedVoting,
}
returnedVoteEvent := boardSub.eventFilter(votingEvent, participantBoardSession.User.ID)
returnedVoteEvent := boardSub.eventFilter(votingEvent, participantBoardSession.User)

assert.NotNil(t, returnedVoteEvent)
assert.Equal(t, expectedVotingEvent, returnedVoteEvent)
}

func testInitFilterAsOwner(t *testing.T) {
expectedInitEvent := initEvent
returnedInitEvent := eventInitFilter(initEvent, ownerBoardSession.User.ID)
returnedInitEvent := eventInitFilter(initEvent, ownerBoardSession.User)

assert.Equal(t, expectedInitEvent, returnedInitEvent)
}

func testInitFilterAsModerator(t *testing.T) {
expectedInitEvent := initEvent
returnedInitEvent := eventInitFilter(initEvent, moderatorBoardSession.User.ID)
returnedInitEvent := eventInitFilter(initEvent, moderatorBoardSession.User)

assert.Equal(t, expectedInitEvent, returnedInitEvent)
}
Expand All @@ -382,16 +382,16 @@ func testInitFilterAsParticipant(t *testing.T) {
expectedInitEvent := InitEvent{
Type: realtime.BoardEventInit,
Data: dto.FullBoard{
Board: &dto.Board{},
Columns: []*dto.Column{&aSeeableColumn},
Notes: []*dto.Note{&aParticipantNote},
Votings: []*dto.Voting{&expectedVoting},
Votes: []*dto.Vote{},
BoardSessions: boardSessions,
Board: &dto.Board{},
Columns: []*dto.Column{&aSeeableColumn},
Notes: []*dto.Note{&aParticipantNote},
Votings: []*dto.Voting{&expectedVoting},
Votes: []*dto.Vote{},
BoardSessions: boardSessions,
BoardSessionRequests: []*dto.BoardSessionRequest{},
},
}
returnedInitEvent := eventInitFilter(initEvent, participantBoardSession.User.ID)
returnedInitEvent := eventInitFilter(initEvent, participantBoardSession.User)

assert.Equal(t, expectedInitEvent, returnedInitEvent)
}
10 changes: 2 additions & 8 deletions server/src/common/dto/board_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// BoardSession is the response for all participant requests.
type BoardSession struct {
User User `json:"user"`
User uuid.UUID `json:"user"`

// Flag indicates whether user is online and connected to the board.
Connected bool `json:"connected"`
Expand Down Expand Up @@ -40,13 +40,7 @@ type BoardSession struct {
}

func (b *BoardSession) From(session database.BoardSession) *BoardSession {
user := User{
ID: session.User,
Name: session.Name,
Avatar: session.Avatar,
AccountType: session.AccountType,
}
b.User = user
b.User = session.User
b.Connected = session.Connected
b.Ready = session.Ready
b.RaisedHand = session.RaisedHand
Expand Down
11 changes: 6 additions & 5 deletions server/src/database/board_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,19 @@ func (d *Database) GetBoardSessions(board uuid.UUID, filter ...filter.BoardSessi
}

// Gets all board sessions of a single user who he is currently connected to
func (d *Database) GetSingleUserConnectedBoards(user uuid.UUID) ([]BoardSession, error) {
var sessions []BoardSession
func (d *Database) GetSingleUserConnectedBoards(user uuid.UUID) ([]uuid.UUID, error) {
var connectedBoards []uuid.UUID
err := d.db.NewSelect().
Model(connectedBoards).
TableExpr("board_sessions AS s").
ColumnExpr("s.board, s.user, u.avatar, u.name, u.account_type, s.connected, s.show_hidden_columns, s.ready, s.raised_hand, s.role, s.banned").
ColumnExpr("s.board").
Where("s.user = ?", user).
Where("s.connected").
Join("INNER JOIN users AS u ON u.id = s.user").
Scan(context.Background(), &sessions)
Scan(context.Background(), &connectedBoards)
if err != nil {
return nil, err
}

return sessions, err
return connectedBoards, err
}
43 changes: 22 additions & 21 deletions server/src/realtime/boards.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,28 @@ import (
type BoardEventType string

const (
BoardEventInit BoardEventType = "INIT"
BoardEventBoardUpdated BoardEventType = "BOARD_UPDATED"
BoardEventBoardDeleted BoardEventType = "BOARD_DELETED"
BoardEventColumnsUpdated BoardEventType = "COLUMNS_UPDATED"
BoardEventColumnDeleted BoardEventType = "COLUMN_DELETED"
BoardEventNotesUpdated BoardEventType = "NOTES_UPDATED"
BoardEventNoteDeleted BoardEventType = "NOTE_DELETED"
BoardEventNotesSync BoardEventType = "NOTES_SYNC"
BoardEventReactionAdded BoardEventType = "REACTION_ADDED"
BoardEventReactionDeleted BoardEventType = "REACTION_DELETED"
BoardEventReactionUpdated BoardEventType = "REACTION_UPDATED"
BoardEventVotesUpdated BoardEventType = "VOTES_UPDATED"
BoardEventSessionRequestCreated BoardEventType = "REQUEST_CREATED"
BoardEventSessionRequestUpdated BoardEventType = "REQUEST_UPDATED"
BoardEventParticipantCreated BoardEventType = "PARTICIPANT_CREATED"
BoardEventParticipantUpdated BoardEventType = "PARTICIPANT_UPDATED"
BoardEventParticipantsUpdated BoardEventType = "PARTICIPANTS_UPDATED"
BoardEventVotingCreated BoardEventType = "VOTING_CREATED"
BoardEventVotingUpdated BoardEventType = "VOTING_UPDATED"
BoardEventBoardTimerUpdated BoardEventType = "BOARD_TIMER_UPDATED"
BoardEventBoardReactionAdded BoardEventType = "BOARD_REACTION_ADDED"
BoardEventInit BoardEventType = "INIT"
BoardEventBoardUpdated BoardEventType = "BOARD_UPDATED"
BoardEventBoardDeleted BoardEventType = "BOARD_DELETED"
BoardEventColumnsUpdated BoardEventType = "COLUMNS_UPDATED"
BoardEventColumnDeleted BoardEventType = "COLUMN_DELETED"
BoardEventNotesUpdated BoardEventType = "NOTES_UPDATED"
BoardEventNoteDeleted BoardEventType = "NOTE_DELETED"
BoardEventNotesSync BoardEventType = "NOTES_SYNC"
BoardEventReactionAdded BoardEventType = "REACTION_ADDED"
BoardEventReactionDeleted BoardEventType = "REACTION_DELETED"
BoardEventReactionUpdated BoardEventType = "REACTION_UPDATED"
BoardEventVotesUpdated BoardEventType = "VOTES_UPDATED"
BoardEventSessionRequestCreated BoardEventType = "REQUEST_CREATED"
BoardEventSessionRequestUpdated BoardEventType = "REQUEST_UPDATED"
BoardEventParticipantCreated BoardEventType = "PARTICIPANT_CREATED"
BoardEventParticipantUpdated BoardEventType = "PARTICIPANT_UPDATED"
BoardEventParticipantSessionUpdated BoardEventType = "PARTICIPANT_SESSION_UPDATED"
BoardEventParticipantsUpdated BoardEventType = "PARTICIPANTS_UPDATED"
BoardEventVotingCreated BoardEventType = "VOTING_CREATED"
BoardEventVotingUpdated BoardEventType = "VOTING_UPDATED"
BoardEventBoardTimerUpdated BoardEventType = "BOARD_TIMER_UPDATED"
BoardEventBoardReactionAdded BoardEventType = "BOARD_REACTION_ADDED"
)

type BoardEvent struct {
Expand Down
Loading
Loading