First pass at adding a waiting room.
This commit is contained in:
@@ -42,6 +42,20 @@ var hallUnlockSchedules = struct {
|
||||
entries: make(map[*hall.Hall]*scheduledHallUnlock),
|
||||
}
|
||||
|
||||
func scheduledUnlockDeadline(g *hall.Hall) (time.Time, bool) {
|
||||
hallUnlockSchedules.Lock()
|
||||
entry := hallUnlockSchedules.entries[g]
|
||||
if entry == nil {
|
||||
hallUnlockSchedules.Unlock()
|
||||
return time.Time{}, false
|
||||
}
|
||||
entry.mu.Lock()
|
||||
deadline, active := entry.deadline, entry.active
|
||||
entry.mu.Unlock()
|
||||
hallUnlockSchedules.Unlock()
|
||||
return deadline, active
|
||||
}
|
||||
|
||||
func scheduledUnlockRequestFromValue(value interface{}) (scheduledUnlockRequest, error) {
|
||||
v, ok := value.(map[string]interface{})
|
||||
if !ok {
|
||||
@@ -265,6 +279,7 @@ func scheduleHallUnlock(g *hall.Hall, issuer *webClient, deadline, now time.Time
|
||||
broadcastHallInfo(g, message, true)
|
||||
}
|
||||
entry.mu.Unlock()
|
||||
waitingHallChanged(g)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -310,6 +325,7 @@ func finishScheduledUnlock(entry *scheduledHallUnlock) {
|
||||
}
|
||||
entry.mu.Unlock()
|
||||
hallUnlockSchedules.Unlock()
|
||||
waitingHallChanged(entry.hall)
|
||||
}
|
||||
|
||||
func setHallLockState(g *hall.Hall, locked bool, message string) bool {
|
||||
@@ -329,6 +345,7 @@ func setHallLockState(g *hall.Hall, locked bool, message string) bool {
|
||||
broadcastHallInfo(g, "Hall unlocked", false)
|
||||
}
|
||||
hallUnlockSchedules.Unlock()
|
||||
waitingHallChanged(g)
|
||||
return entry != nil
|
||||
}
|
||||
|
||||
@@ -343,6 +360,21 @@ func cancelScheduledHallUnlock(g *hall.Hall) bool {
|
||||
return entry != nil
|
||||
}
|
||||
|
||||
func cancelScheduledUnlockByIssuer(g *hall.Hall, issuer *webClient) bool {
|
||||
hallUnlockSchedules.Lock()
|
||||
entry := hallUnlockSchedules.entries[g]
|
||||
if entry == nil || entry.issuer != issuer {
|
||||
hallUnlockSchedules.Unlock()
|
||||
return false
|
||||
}
|
||||
delete(hallUnlockSchedules.entries, g)
|
||||
deactivateScheduledUnlock(entry)
|
||||
hallUnlockSchedules.Unlock()
|
||||
broadcastHallInfo(g, "Scheduled hall unlock cancelled because the issuing operator is no longer present as an operator.", true)
|
||||
waitingHallChanged(g)
|
||||
return true
|
||||
}
|
||||
|
||||
func deactivateScheduledUnlock(entry *scheduledHallUnlock) {
|
||||
entry.mu.Lock()
|
||||
entry.active = false
|
||||
|
||||
Reference in New Issue
Block a user