From 719ef5eecca60c2013297f44d06621e18782f078 Mon Sep 17 00:00:00 2001 From: Nikos Filippakis Date: Sun, 21 Jun 2020 18:03:37 +0200 Subject: [PATCH] Perform a sync request with full state when starting Signed-off-by: Nikos Filippakis --- clients/clients.go | 9 +++++++++ goneb.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clients/clients.go b/clients/clients.go index fa56311..52e7fa8 100644 --- a/clients/clients.go +++ b/clients/clients.go @@ -362,6 +362,7 @@ func (c *Clients) initClient(botClient *BotClient) error { return err } + // Register sync callback for maintaining the state store and Olm machine state botClient.Register(syncer) syncer.OnEventType(mevt.EventMessage, func(_ mautrix.EventSource, event *mevt.Event) { @@ -426,6 +427,14 @@ func (c *Clients) initClient(botClient *BotClient) error { if config.Sync { go func() { + // Get the state store up to date + resp, err := botClient.SyncRequest(30000, "", "", true, mevt.PresenceOnline) + if err != nil { + log.WithError(err).Error("Error performing initial sync") + return + } + botClient.stateStore.UpdateStateStore(resp) + for { if e := client.Sync(); e != nil { log.WithFields(log.Fields{ diff --git a/goneb.go b/goneb.go index ed3ea67..8812af6 100644 --- a/goneb.go +++ b/goneb.go @@ -139,7 +139,7 @@ func insertServicesFromConfig(clis *clients.Clients, serviceReqs []api.Configure } func loadDatabase(databaseType, databaseURL, configYAML string) (*database.ServiceDB, error) { - if configYAML != "" { + if databaseType == "" && databaseURL == "" { databaseType = "sqlite3" databaseURL = ":memory:?_busy_timeout=5000" }