Skip to content

Commit

Permalink
Attempt new headless sync implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
FIGBERT committed Sep 18, 2023
1 parent c3920a4 commit 05ccf81
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
29 changes: 10 additions & 19 deletions headless/headless.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package headless

import (
"context"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -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{}

Expand Down
6 changes: 5 additions & 1 deletion matrix/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -469,7 +473,7 @@ func (c *Container) InitSyncer() {
}
if c.headless {
c.syncer.FirstDoneCallback = func() {
c.Stop()
c.stop <- true
}
}

Expand Down

0 comments on commit 05ccf81

Please sign in to comment.