refactor: store all known as map for access
This commit is contained in:
parent
9f4fe20979
commit
f8db7c14c8
|
@ -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
|
||||
|
|
|
@ -135,7 +135,8 @@ func createRoomHandler(templateFs *embed.FS,
|
|||
PasswordHash: r.PostFormValue("roomPassword"), // TODO hash the password, not to store
|
||||
AdminIds: []rooms.PersonId{person.Id},
|
||||
Paricipants: []rooms.PersonId{person.Id},
|
||||
AllKnownPeople: []rooms.Person{person},
|
||||
AllKnownPeople: map[rooms.PersonId]rooms.Person{
|
||||
person.Id: person},
|
||||
}
|
||||
err = roomsM.Save(newRoom)
|
||||
if err != nil {
|
||||
|
@ -247,7 +248,7 @@ func joinRoomHandler(templateFs *embed.FS,
|
|||
err := roomsM.Update(r.Context(), room.Name, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
||||
log.Printf("/login/join about to modify room %+v", fromRoom)
|
||||
toRoom = fromRoom
|
||||
toRoom.AllKnownPeople = append(toRoom.AllKnownPeople, person)
|
||||
toRoom.AllKnownPeople[person.Id] = person
|
||||
log.Printf("/login/join will save %+v", toRoom)
|
||||
return toRoom
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue