~edwargix/tallyard

bef3eba723858fb00ec72d65d903bd5a1701ac4d — David Florness 2 years ago 91069fa
Control sync filter via the new custom syncer

We have too much stuff in main.go
2 files changed, 41 insertions(+), 43 deletions(-)

M cmd/tallyard/main.go
M cmd/tallyard/syncer.go
M cmd/tallyard/main.go => cmd/tallyard/main.go +0 -43
@@ 85,12 85,6 @@ func main() {
				errorf("panic: %s\n%s", r, debug.Stack())
			}
		}()
		res, err := client.CreateFilter(electionFilter)
		if err != nil {
			errorf("couldn't create filter: %s", err)
			return
		}
		client.Store.SaveFilterID(client.UserID, res.FilterID)
		err = client.Sync()
		if err != nil {
			errorf("error during sync: %s", err)


@@ 192,43 186,6 @@ func main() {
	}
}

var electionFilter = &mautrix.Filter{
	AccountData: mautrix.FilterPart{
		NotTypes: []event.Type{event.NewEventType("*")},
	},
	Presence: mautrix.FilterPart{
		NotTypes: []event.Type{event.NewEventType("*")},
	},
	Room: mautrix.RoomFilter{
		AccountData: mautrix.FilterPart{
			NotTypes: []event.Type{event.NewEventType("*")},
		},
		Ephemeral: mautrix.FilterPart{
			NotTypes: []event.Type{event.NewEventType("*")},
		},
		State: mautrix.FilterPart{
			Types: []event.Type{
				event.StateCreate,
				event.StateEncryption,
				event.StateMember,
				event.StateRoomName,
			},
		},
		Timeline: mautrix.FilterPart{
			// TODO figure out how to have no limit; -1 is giving me 500s
			Limit: 500,
			Types: []event.Type{
				election.CreateElectionMessage,
				election.JoinElectionMessage,
				election.StartElectionMessage,
				election.KeysMessage,
				election.EvalsMessage,
				election.SumMessage,
			},
		},
	},
}

func debugEventHook(_ mautrix.EventSource, evt *event.Event) {
	log.Debugf("<%[1]s> %[4]s (%[2]s/%[3]s)\n",
		evt.Sender, evt.Type.String(), evt.ID,

M cmd/tallyard/syncer.go => cmd/tallyard/syncer.go +41 -0
@@ 6,6 6,8 @@ import (
	log "github.com/sirupsen/logrus"
	"maunium.net/go/mautrix"
	"maunium.net/go/mautrix/event"
	"maunium.net/go/mautrix/id"
	"tallyard.xyz/election"
)

type TallyardSyncer struct {


@@ 32,3 34,42 @@ func NewTallyardSyncer() *TallyardSyncer {
	}
	return t
}

func (s *TallyardSyncer) GetFilterJSON(userID id.UserID) *mautrix.Filter {
	return &mautrix.Filter{
		AccountData: mautrix.FilterPart{
			NotTypes: []event.Type{event.NewEventType("*")},
		},
		Presence: mautrix.FilterPart{
			NotTypes: []event.Type{event.NewEventType("*")},
		},
		Room: mautrix.RoomFilter{
			AccountData: mautrix.FilterPart{
				NotTypes: []event.Type{event.NewEventType("*")},
			},
			Ephemeral: mautrix.FilterPart{
				NotTypes: []event.Type{event.NewEventType("*")},
			},
			State: mautrix.FilterPart{
				Types: []event.Type{
					event.StateCreate,
					event.StateEncryption,
					event.StateMember,
					event.StateRoomName,
				},
			},
			Timeline: mautrix.FilterPart{
				// TODO figure out how to have no limit; -1 is giving me 500s
				Limit: 500,
				Types: []event.Type{
					election.CreateElectionMessage,
					election.JoinElectionMessage,
					election.StartElectionMessage,
					election.KeysMessage,
					election.EvalsMessage,
					election.SumMessage,
				},
			},
		},
	}
}