@@ 415,26 415,36 @@ func (elections *ElectionsMap) onKeysMessage(evt *event.Event, client *mautrix.C
return
}
+ // this makes JoinIDIndex availabe below
+ startEvt := elections.EventStore.GetStartEvent(evt.RoomID, content.StartID)
+ if startEvt == nil {
+ debugf("we couldn't process the start event, %s", content.StartID)
+ return
+ }
+
+ el := elections.GetElection(startEvt.CreateID)
+ if el == nil {
+ // should never happen because we retrieved the join event above
+ errorf("election %s doesn't exist", startEvt.ID)
+ return
+ }
+
joinEvt := elections.EventStore.GetJoinEvent(evt.RoomID, content.JoinID)
if joinEvt == nil {
debugf("we couldn't get the join event, %s", content.JoinID)
return
}
+
+ // ensure keys sender also sent join event
if evt.Sender != joinEvt.Sender {
warnf("they did not send the join event; %s did", joinEvt.Sender)
return
}
- // process the start event so that JoinIDIndex is availabe below
- if elections.EventStore.GetStartEvent(evt.RoomID, content.StartID) == nil {
- debugf("we couldn't process the start event, %s", content.StartID)
- return
- }
-
- el := elections.GetElection(joinEvt.CreateID)
- if el == nil {
- // should never happen because we retrieved the join event above
- errorf("election %s doesn't exist", joinEvt.ID)
+ // ensure join event and start event belong to the same election
+ if _, voterExists := el.Joins[joinEvt.ID]; !voterExists {
+ warnf("the join event %s and start event %s do not belong to the same election",
+ joinEvt.ID, startEvt.ID)
return
}