~edwargix/tallyard

d1052e81716762e853cca3c8f00e5db74890a98d — David Florness 2 years ago a442f09
Actually use custom syncer and fix inheritance from DefaultSyncer

I forgot to actually use the new tallyard syncer in 1e94d712 (making that commit
essentially a no-op).

Also, we want to make sure we correctly initialize the custom syncer with
NewDefaultSyncer, which sets important values like ParseEventContent.

Fixes: 1e94d712
2 files changed, 18 insertions(+), 1 deletions(-)

M cmd/tallyard/main.go
M cmd/tallyard/syncer.go
M cmd/tallyard/main.go => cmd/tallyard/main.go +2 -1
@@ 52,6 52,8 @@ func main() {
	}

	client, err := mautrix.NewClient(authInfo.Homeserver, authInfo.UserID, authInfo.AccessToken)
	syncer := NewTallyardSyncer()
	client.Syncer = syncer
	client.Logger = TallyardLogger{}
	if err != nil {
		log.Panic(err)


@@ 67,7 69,6 @@ func main() {
	client.Store = matrix.NewTallyardStore(electionsMap)
	defer electionsMap.Save()

	syncer := client.Syncer.(*mautrix.DefaultSyncer)
	syncer.OnEvent(debugEventHook)
	syncer.OnEvent(client.Store.(*matrix.TallyardStore).UpdateState)
	electionsMap.SetupEventHooks(client, syncer)

M cmd/tallyard/syncer.go => cmd/tallyard/syncer.go +16 -0
@@ 5,6 5,7 @@ import (

	log "github.com/sirupsen/logrus"
	"maunium.net/go/mautrix"
	"maunium.net/go/mautrix/event"
)

type TallyardSyncer struct {


@@ 16,3 17,18 @@ func (s *TallyardSyncer) OnFailedSync(res *mautrix.RespSync, err error) (time.Du
	log.Warnf("encountered sync error; retrying in %s: %s", sleepDuration, err)
	return sleepDuration, nil
}

func NewTallyardSyncer() *TallyardSyncer {
	t := &TallyardSyncer{
		mautrix.NewDefaultSyncer(),
	}
	t.ParseErrorHandler = func(evt *event.Event, err error) bool {
		if evt == nil {
			log.Debugf("a parse error occurred for nil event: %s", err)
		} else {
			log.Debugf("a parse error occurred for event %s: %s", evt.ID, err)
		}
		return false
	}
	return t
}