refactor: store all known as map for access
This commit is contained in:
@@ -13,15 +13,15 @@ type Room struct {
|
||||
CurrentSpeaker PersonId // i guess let's set to zero value when it's noone from the room
|
||||
// all people that were visiting room before, spectating now or being a participant
|
||||
// used to check person password against the name
|
||||
AllKnownPeople []Person
|
||||
AllKnownPeople map[PersonId]Person
|
||||
// person ids of people who are currently participating in the discussion at the table
|
||||
// TODO for now peson in seated at join and removed at logout in routes
|
||||
Paricipants []PersonId
|
||||
Paricipants []PersonId
|
||||
ParticipantHands map[PersonId]HandGesture
|
||||
Marks map[HandGesture]PersonId
|
||||
}
|
||||
|
||||
func (r *Room)InitMaps() {
|
||||
func (r *Room) InitMaps() {
|
||||
if r.ParticipantHands == nil {
|
||||
r.ParticipantHands = make(map[PersonId]HandGesture)
|
||||
}
|
||||
@@ -35,7 +35,7 @@ func (r *Room)InitMaps() {
|
||||
// if you are speaking - change nothing
|
||||
// if nobody is speaking, set this person as a first speaker
|
||||
func (r *Room) RaiseHand(p PersonId, gesture HandGesture) Room {
|
||||
if (r.CurrentSpeaker == p) {
|
||||
if r.CurrentSpeaker == p {
|
||||
// if person already speaking, should first end speaking
|
||||
return *r
|
||||
}
|
||||
@@ -120,7 +120,7 @@ gestureIteration:
|
||||
func (r *Room) PersonToStandUpFromTable(p PersonId) {
|
||||
r.ReleaseHand(p)
|
||||
if slices.Contains(r.Paricipants, p) {
|
||||
updated := slices.DeleteFunc(r.Paricipants, func(sittingPerson PersonId) bool {
|
||||
updated := slices.DeleteFunc(r.Paricipants, func(sittingPerson PersonId) bool {
|
||||
return sittingPerson == p
|
||||
})
|
||||
r.Paricipants = updated
|
||||
@@ -167,10 +167,12 @@ func (r *Room) Equal(other *Room) bool {
|
||||
if r.Name != other.Name || r.PasswordHash != other.PasswordHash || r.CurrentSpeaker != other.CurrentSpeaker {
|
||||
return false
|
||||
}
|
||||
if !slices.Equal(r.AdminIds, other.AdminIds) || !slices.Equal(r.Paricipants, other.Paricipants) || !slices.Equal(r.AllKnownPeople, other.AllKnownPeople) {
|
||||
if !slices.Equal(r.AdminIds, other.AdminIds) || !slices.Equal(r.Paricipants, other.Paricipants) {
|
||||
return false
|
||||
}
|
||||
if !maps.Equal(r.ParticipantHands, other.ParticipantHands) || !maps.Equal(r.Marks, other.Marks) {
|
||||
if !maps.Equal(r.ParticipantHands, other.ParticipantHands) ||
|
||||
!maps.Equal(r.Marks, other.Marks) ||
|
||||
!maps.Equal(r.AllKnownPeople, other.AllKnownPeople) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -188,7 +190,7 @@ const (
|
||||
)
|
||||
|
||||
func GestureFromInt(num int) (HandGesture, bool) {
|
||||
if (num >= int(ChangeTopic) && num <= int(Meta)) {
|
||||
if num >= int(ChangeTopic) && num <= int(Meta) {
|
||||
return HandGesture(num), true
|
||||
}
|
||||
return HandGesture(0), false
|
||||
|
||||
Reference in New Issue
Block a user