diff --git a/headless/headless.go b/headless/headless.go index f3578ef..2c75bfb 100644 --- a/headless/headless.go +++ b/headless/headless.go @@ -1,7 +1,6 @@ package headless import ( - "context" "errors" "fmt" "os" @@ -68,25 +67,17 @@ func Init(conf Config, updates chan fmt.Stringer) error { // sync updates <- beginningSync{} - resp, err := gmx.Matrix().Client().FullSyncRequest(mautrix.ReqSync{ - Timeout: 30000, - Since: "", - FilterID: "", - FullState: true, - SetPresence: gmx.Matrix().Client().SyncPresence, - Context: context.Background(), - StreamResponse: true, - }) - if err != nil { - return err - } - updates <- fetchedSyncData{} - gmx.Matrix().(*matrix.Container).InitSyncer() - updates <- processingSync{} - err = gmx.Matrix().(*matrix.Container).ProcessSyncResponse(resp, "") - if err != nil { - return err +syncloop: + for { + select { + case <-gmx.Matrix().(*matrix.Container).StopChannel(): + break syncloop + default: + if err := gmx.Matrix().Client().Sync(); err != nil { + return err + } + } } updates <- syncFinished{} diff --git a/matrix/matrix.go b/matrix/matrix.go index 101114a..6b9f82c 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -350,6 +350,10 @@ func (c *Container) Logout() { c.ui.OnLogout() } +func (c *Container) StopChannel() chan bool { + return c.stop +} + // Stop stops the Matrix syncer. func (c *Container) Stop() { if c.running { @@ -469,7 +473,7 @@ func (c *Container) InitSyncer() { } if c.headless { c.syncer.FirstDoneCallback = func() { - c.Stop() + c.stop <- true } }