feat: saving person pass across logout/rejoin
This commit is contained in:
parent
517fda2512
commit
16df084928
|
@ -11,10 +11,12 @@ type Room struct {
|
||||||
AdminIds []PersonId
|
AdminIds []PersonId
|
||||||
PasswordHash string
|
PasswordHash string
|
||||||
CurrentSpeaker PersonId // i guess let's set to zero value when it's noone from the room
|
CurrentSpeaker PersonId // i guess let's set to zero value when it's noone from the room
|
||||||
Paricipants []Person
|
// all people that were visiting room before, spectating now or being a participant
|
||||||
// TODO hands, for each type of hand?
|
// used to check person password against the name
|
||||||
// i guess participants order fixed for now?
|
AllKnownPeople []Person
|
||||||
// and i'll still need 'current' for each hand level
|
// 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
|
||||||
ParticipantHands map[PersonId]HandGesture
|
ParticipantHands map[PersonId]HandGesture
|
||||||
Marks map[HandGesture]PersonId
|
Marks map[HandGesture]PersonId
|
||||||
}
|
}
|
||||||
|
@ -68,9 +70,9 @@ gestureIteration:
|
||||||
for i := 1; i < participantsCount; i++ {
|
for i := 1; i < participantsCount; i++ {
|
||||||
checkIndex := (startIndex + i) % participantsCount
|
checkIndex := (startIndex + i) % participantsCount
|
||||||
checkPerson := r.Paricipants[checkIndex]
|
checkPerson := r.Paricipants[checkIndex]
|
||||||
checkGesture, isFound := r.ParticipantHands[checkPerson.Id]
|
checkGesture, isFound := r.ParticipantHands[checkPerson]
|
||||||
if isFound && checkGesture == gesture {
|
if isFound && checkGesture == gesture {
|
||||||
nextSpeakerId, nextSpeakerFound = checkPerson.Id, true
|
nextSpeakerId, nextSpeakerFound = checkPerson, true
|
||||||
break gestureIteration
|
break gestureIteration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,9 +130,7 @@ func (r *Room) gestureSearchStartIndex(gesture, curSpeakerGesture HandGesture) i
|
||||||
log.Printf("> selecting person from which to start. cur speaker %s, for gestrue %s, got person %d",
|
log.Printf("> selecting person from which to start. cur speaker %s, for gestrue %s, got person %d",
|
||||||
curSpeakerGesture.String(), gesture.String(), personFromWhichToStartSearch)
|
curSpeakerGesture.String(), gesture.String(), personFromWhichToStartSearch)
|
||||||
|
|
||||||
indexFromWhichToStart := slices.IndexFunc(r.Paricipants, func(p Person) bool {
|
indexFromWhichToStart := slices.Index(r.Paricipants, personFromWhichToStartSearch)
|
||||||
return p.Id == personFromWhichToStartSearch
|
|
||||||
})
|
|
||||||
return indexFromWhichToStart
|
return indexFromWhichToStart
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ func (r *Room) Equal(other *Room) bool {
|
||||||
if r.Name != other.Name || r.PasswordHash != other.PasswordHash || r.CurrentSpeaker != other.CurrentSpeaker {
|
if r.Name != other.Name || r.PasswordHash != other.PasswordHash || r.CurrentSpeaker != other.CurrentSpeaker {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !slices.Equal(r.AdminIds, other.AdminIds) || !slices.Equal(r.Paricipants, other.Paricipants) {
|
if !slices.Equal(r.AdminIds, other.AdminIds) || !slices.Equal(r.Paricipants, other.Paricipants) || !slices.Equal(r.AllKnownPeople, other.AllKnownPeople) {
|
||||||
return false
|
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) {
|
||||||
|
|
|
@ -55,7 +55,7 @@ var singleHandActive releaseHandTest = releaseHandTest{
|
||||||
room: Room{
|
room: Room{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CurrentSpeaker: person1.Id,
|
CurrentSpeaker: person1.Id,
|
||||||
Paricipants: []Person{
|
AllKnownPeople: []Person{
|
||||||
person1,
|
person1,
|
||||||
person2,
|
person2,
|
||||||
},
|
},
|
||||||
|
@ -67,7 +67,7 @@ var singleHandActive releaseHandTest = releaseHandTest{
|
||||||
expected: Room{
|
expected: Room{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CurrentSpeaker: PersonId(0),
|
CurrentSpeaker: PersonId(0),
|
||||||
Paricipants: []Person{
|
AllKnownPeople: []Person{
|
||||||
person1,
|
person1,
|
||||||
person2,
|
person2,
|
||||||
},
|
},
|
||||||
|
@ -81,10 +81,10 @@ var raisingLevelFromExpandToClarifyingQ releaseHandTest = releaseHandTest{
|
||||||
room: Room{
|
room: Room{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CurrentSpeaker: person1.Id,
|
CurrentSpeaker: person1.Id,
|
||||||
Paricipants: []Person{
|
Paricipants: []PersonId{
|
||||||
person1,
|
person1.Id,
|
||||||
person2,
|
person2.Id,
|
||||||
person3,
|
person3.Id,
|
||||||
},
|
},
|
||||||
ParticipantHands: map[PersonId]HandGesture{
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
person1.Id: Expand,
|
person1.Id: Expand,
|
||||||
|
@ -95,10 +95,10 @@ var raisingLevelFromExpandToClarifyingQ releaseHandTest = releaseHandTest{
|
||||||
expected: Room{
|
expected: Room{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CurrentSpeaker: person3.Id,
|
CurrentSpeaker: person3.Id,
|
||||||
Paricipants: []Person{
|
Paricipants: []PersonId{
|
||||||
person1,
|
person1.Id,
|
||||||
person2,
|
person2.Id,
|
||||||
person3,
|
person3.Id,
|
||||||
},
|
},
|
||||||
ParticipantHands: map[PersonId]HandGesture{
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
person3.Id: ClarifyingQ,
|
person3.Id: ClarifyingQ,
|
||||||
|
@ -115,10 +115,10 @@ var selectNextHigherLevel releaseHandTest = releaseHandTest{
|
||||||
room: Room{
|
room: Room{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CurrentSpeaker: person1.Id,
|
CurrentSpeaker: person1.Id,
|
||||||
Paricipants: []Person{
|
Paricipants: []PersonId{
|
||||||
person1,
|
person1.Id,
|
||||||
person2,
|
person2.Id,
|
||||||
person3,
|
person3.Id,
|
||||||
},
|
},
|
||||||
ParticipantHands: map[PersonId]HandGesture{
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
person1.Id: Meta,
|
person1.Id: Meta,
|
||||||
|
@ -130,10 +130,10 @@ var selectNextHigherLevel releaseHandTest = releaseHandTest{
|
||||||
expected: Room{
|
expected: Room{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CurrentSpeaker: person3.Id,
|
CurrentSpeaker: person3.Id,
|
||||||
Paricipants: []Person{
|
Paricipants: []PersonId{
|
||||||
person1,
|
person1.Id,
|
||||||
person2,
|
person2.Id,
|
||||||
person3,
|
person3.Id,
|
||||||
},
|
},
|
||||||
ParticipantHands: map[PersonId]HandGesture{
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
person2.Id: Expand,
|
person2.Id: Expand,
|
||||||
|
@ -150,11 +150,11 @@ var usingMarkToLoverLevel releaseHandTest = releaseHandTest{
|
||||||
room: Room{
|
room: Room{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CurrentSpeaker: person3.Id,
|
CurrentSpeaker: person3.Id,
|
||||||
Paricipants: []Person{
|
Paricipants: []PersonId{
|
||||||
person1,
|
person1.Id,
|
||||||
person2,
|
person2.Id,
|
||||||
person3,
|
person3.Id,
|
||||||
person4,
|
person4.Id,
|
||||||
},
|
},
|
||||||
ParticipantHands: map[PersonId]HandGesture{
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
person2.Id: Expand,
|
person2.Id: Expand,
|
||||||
|
@ -170,11 +170,11 @@ var usingMarkToLoverLevel releaseHandTest = releaseHandTest{
|
||||||
expected: Room{
|
expected: Room{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CurrentSpeaker: person2.Id,
|
CurrentSpeaker: person2.Id,
|
||||||
Paricipants: []Person{
|
Paricipants: []PersonId{
|
||||||
person1,
|
person1.Id,
|
||||||
person2,
|
person2.Id,
|
||||||
person3,
|
person3.Id,
|
||||||
person4,
|
person4.Id,
|
||||||
},
|
},
|
||||||
ParticipantHands: map[PersonId]HandGesture{
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
person2.Id: Expand,
|
person2.Id: Expand,
|
||||||
|
@ -191,11 +191,11 @@ var releasingNonSpeakerHand releaseHandTest = releaseHandTest{
|
||||||
room: Room{
|
room: Room{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CurrentSpeaker: person3.Id,
|
CurrentSpeaker: person3.Id,
|
||||||
Paricipants: []Person{
|
Paricipants: []PersonId{
|
||||||
person1,
|
person1.Id,
|
||||||
person2,
|
person2.Id,
|
||||||
person3,
|
person3.Id,
|
||||||
person4,
|
person4.Id,
|
||||||
},
|
},
|
||||||
ParticipantHands: map[PersonId]HandGesture{
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
person2.Id: Expand,
|
person2.Id: Expand,
|
||||||
|
@ -211,11 +211,11 @@ var releasingNonSpeakerHand releaseHandTest = releaseHandTest{
|
||||||
expected: Room{
|
expected: Room{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CurrentSpeaker: person3.Id,
|
CurrentSpeaker: person3.Id,
|
||||||
Paricipants: []Person{
|
Paricipants: []PersonId{
|
||||||
person1,
|
person1.Id,
|
||||||
person2,
|
person2.Id,
|
||||||
person3,
|
person3.Id,
|
||||||
person4,
|
person4.Id,
|
||||||
},
|
},
|
||||||
ParticipantHands: map[PersonId]HandGesture{
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
person2.Id: Expand,
|
person2.Id: Expand,
|
||||||
|
|
|
@ -116,7 +116,8 @@ func createRoomHandler(templateFs *embed.FS,
|
||||||
Name: roomName,
|
Name: roomName,
|
||||||
PasswordHash: r.PostFormValue("roomPassword"), // TODO hash the password, not to store
|
PasswordHash: r.PostFormValue("roomPassword"), // TODO hash the password, not to store
|
||||||
AdminIds: []rooms.PersonId{person.Id},
|
AdminIds: []rooms.PersonId{person.Id},
|
||||||
Paricipants: []rooms.Person{person},
|
Paricipants: []rooms.PersonId{person.Id},
|
||||||
|
AllKnownPeople: []rooms.Person{person},
|
||||||
}
|
}
|
||||||
err = roomsM.Save(newRoom)
|
err = roomsM.Save(newRoom)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -188,7 +189,7 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||||
log.Printf("/login/join error getting room %s", roomName)
|
log.Printf("/login/join error getting room %s", roomName)
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
// TODO render error to be put in error place
|
// TODO render error to be put in error place
|
||||||
return
|
return // no such room
|
||||||
} else {
|
} else {
|
||||||
log.Printf("/login/submit found room %+v", room)
|
log.Printf("/login/submit found room %+v", room)
|
||||||
}
|
}
|
||||||
|
@ -198,11 +199,11 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||||
log.Printf("/login/join bad room pass for %+v", room)
|
log.Printf("/login/join bad room pass for %+v", room)
|
||||||
w.WriteHeader(http.StatusForbidden)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
// TODO render error to be put in error place
|
// TODO render error to be put in error place
|
||||||
return
|
return // bad room password
|
||||||
}
|
}
|
||||||
|
|
||||||
var person rooms.Person
|
var person rooms.Person
|
||||||
for _, participant := range room.Paricipants {
|
for _, participant := range room.AllKnownPeople {
|
||||||
if participant.Name == personName {
|
if participant.Name == personName {
|
||||||
person = participant
|
person = participant
|
||||||
}
|
}
|
||||||
|
@ -214,7 +215,7 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||||
log.Printf("/login/join bad person pass for %+s", person.Name)
|
log.Printf("/login/join bad person pass for %+s", person.Name)
|
||||||
w.WriteHeader(http.StatusForbidden)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
// TODO render error to be put in error place
|
// TODO render error to be put in error place
|
||||||
return
|
return // bad person password
|
||||||
}
|
}
|
||||||
// person joining for thethe first time
|
// person joining for thethe first time
|
||||||
if (person == rooms.Person{}) {
|
if (person == rooms.Person{}) {
|
||||||
|
@ -227,7 +228,7 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||||
}
|
}
|
||||||
err := roomsM.Update(context.TODO(), room.Name, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
err := roomsM.Update(context.TODO(), room.Name, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
||||||
toRoom = fromRoom
|
toRoom = fromRoom
|
||||||
toRoom.Paricipants = append(toRoom.Paricipants, person)
|
toRoom.AllKnownPeople = append(toRoom.AllKnownPeople, person)
|
||||||
return toRoom
|
return toRoom
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -235,13 +236,25 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
// TODO render error to be put in error place
|
// TODO render error to be put in error place
|
||||||
// with message try again
|
// with message try again
|
||||||
return
|
return // error adding New person
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO handle context and cancells, with separate function that writeds new updated room
|
// TODO handle context and cancells, with separate function that writeds new updated room
|
||||||
// now we have room and person, can create a session
|
// now we have room and person, can create a session
|
||||||
// and we've checked password
|
// and we've checked password
|
||||||
|
|
||||||
|
err = roomsM.Update(context.TODO(), room.Name, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
||||||
|
toRoom.Paricipants = append(toRoom.Paricipants, person.Id)
|
||||||
|
return toRoom
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("/login/join problem sitting joining person at a table %+v", person.Name)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
// TODO render error to be put in error place
|
||||||
|
// with message try again
|
||||||
|
return // error sitting a new person
|
||||||
|
}
|
||||||
|
|
||||||
newSessionId, err := sessionSM.Save(room.Name, person.Id)
|
newSessionId, err := sessionSM.Save(room.Name, person.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("/login/submit > error saving session %s", err)
|
log.Printf("/login/submit > error saving session %s", err)
|
||||||
|
|
Loading…
Reference in New Issue