@@ 49,7 49,10 @@ func main() {
panic(err)
}
- localVoter := election.NewLocalVoter(client.UserID)
+ if data.LocalVoter == nil {
+ data.LocalVoter = election.NewLocalVoter(client.UserID)
+ data.Save()
+ }
elections := election.NewElectionsMap()
@@ 69,7 72,7 @@ func main() {
})
syncer.OnEventType(election.EvalMessage, func(source mautrix.EventSource, evt *event.Event) {
DebugCB(source, evt)
- election.OnEvalMessage(source, evt, elections, localVoter)
+ election.OnEvalMessage(source, evt, elections, data.LocalVoter)
})
syncer.OnEventType(election.SumMessage, func(source mautrix.EventSource, evt *event.Event) {
DebugCB(source, evt)
@@ 92,17 95,17 @@ func main() {
}
}()
- el, ballot := ui.TUI(client, elections, localVoter)
+ el, ballot := ui.TUI(client, elections, data.LocalVoter)
- localVoter.Poly = math.NewRandomPoly(uint(len(el.Voters)-1), 1024, ballot)
+ data.LocalVoter.Poly = math.NewRandomPoly(uint(len(el.Voters)-1), 1024, ballot)
// TODO we may not have all voters' info
- err = localVoter.SendEvals(client, el)
+ err = data.LocalVoter.SendEvals(client, el)
if err != nil {
panic(err)
}
- err = localVoter.SendSum(client, el)
+ err = data.LocalVoter.SendSum(client, el)
if err != nil {
panic(err)
}
@@ 10,14 10,16 @@ import (
"github.com/kyoh86/xdg"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/id"
+ "tallyard.xyz/election"
)
type Data struct {
- Homeserver string `json:"homeserver"`
- Username string `json:"username"`
- AccessToken string `json:"access_token"`
- DeviceID id.DeviceID `json:"device_id"`
- UserID id.UserID `json:"user_id"`
+ Homeserver string `json:"homeserver"`
+ Username string `json:"username"`
+ AccessToken string `json:"access_token"`
+ DeviceID id.DeviceID `json:"device_id"`
+ UserID id.UserID `json:"user_id"`
+ LocalVoter *election.LocalVoter `json:"local_voter,omitempty"`
}
var dataFname = xdg.DataHome() + "/tallyard/data.json"