mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 10:33:41 -05:00
Add sync implementation to headless.go
This commit is contained in:
parent
704fc53db1
commit
b1c940a0a8
2 changed files with 57 additions and 19 deletions
|
@ -1,6 +1,7 @@
|
||||||
package headless
|
package headless
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
@ -10,6 +11,7 @@ import (
|
||||||
"maunium.net/go/mautrix/crypto/ssss"
|
"maunium.net/go/mautrix/crypto/ssss"
|
||||||
|
|
||||||
"maunium.net/go/gomuks/initialize"
|
"maunium.net/go/gomuks/initialize"
|
||||||
|
"maunium.net/go/gomuks/matrix"
|
||||||
"maunium.net/go/gomuks/ui"
|
"maunium.net/go/gomuks/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -76,8 +78,32 @@ func HeadlessInit(conf HeadlessConfig) error {
|
||||||
// sync
|
// sync
|
||||||
// how?
|
// how?
|
||||||
// this does too much: gmx.Matrix().Start()
|
// this does too much: gmx.Matrix().Start()
|
||||||
|
//
|
||||||
|
// figbert:
|
||||||
|
// just looking to perform the initial sync. is gmx.Matrix().Client().Sync()
|
||||||
|
// the way to go? should i copy+paste the synce initialization from Start()
|
||||||
|
// and OnLogin()?
|
||||||
|
//
|
||||||
|
// tulir:
|
||||||
|
// not sure if there's any easy way to run a single sync, maybe calling
|
||||||
|
// Client.FullSyncRequest + Syncer.ProcessSync manually
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
gmx.Matrix().(*matrix.Container).InitSyncer()
|
||||||
|
err = gmx.Matrix().(*matrix.Container).ProcessSyncResponse(resp, "")
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func initDirs() (string, string, string, string, error) {
|
func initDirs() (string, string, string, string, error) {
|
||||||
|
|
|
@ -381,15 +381,9 @@ func (s StubSyncingModal) SetSteps(i int) {}
|
||||||
func (s StubSyncingModal) Step() {}
|
func (s StubSyncingModal) Step() {}
|
||||||
func (s StubSyncingModal) Close() {}
|
func (s StubSyncingModal) Close() {}
|
||||||
|
|
||||||
// OnLogin initializes the syncer and updates the room list.
|
func (c *Container) InitSyncer() {
|
||||||
func (c *Container) OnLogin() {
|
|
||||||
c.cryptoOnLogin()
|
|
||||||
c.ui.OnLogin()
|
|
||||||
|
|
||||||
c.client.Store = c.config
|
|
||||||
|
|
||||||
debug.Print("Initializing syncer")
|
|
||||||
c.syncer = NewGomuksSyncer(c.config.Rooms)
|
c.syncer = NewGomuksSyncer(c.config.Rooms)
|
||||||
|
|
||||||
if c.crypto != nil {
|
if c.crypto != nil {
|
||||||
c.syncer.OnSync(c.crypto.ProcessSyncResponse)
|
c.syncer.OnSync(c.crypto.ProcessSyncResponse)
|
||||||
c.syncer.OnEventType(event.StateMember, func(source mautrix.EventSource, evt *event.Event) {
|
c.syncer.OnEventType(event.StateMember, func(source mautrix.EventSource, evt *event.Event) {
|
||||||
|
@ -403,6 +397,7 @@ func (c *Container) OnLogin() {
|
||||||
} else {
|
} else {
|
||||||
c.syncer.OnEventType(event.EventEncrypted, c.HandleEncryptedUnsupported)
|
c.syncer.OnEventType(event.EventEncrypted, c.HandleEncryptedUnsupported)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.syncer.OnEventType(event.EventMessage, c.HandleMessage)
|
c.syncer.OnEventType(event.EventMessage, c.HandleMessage)
|
||||||
c.syncer.OnEventType(event.EventSticker, c.HandleMessage)
|
c.syncer.OnEventType(event.EventSticker, c.HandleMessage)
|
||||||
c.syncer.OnEventType(event.EventReaction, c.HandleMessage)
|
c.syncer.OnEventType(event.EventReaction, c.HandleMessage)
|
||||||
|
@ -418,16 +413,7 @@ func (c *Container) OnLogin() {
|
||||||
c.syncer.OnEventType(event.AccountDataPushRules, c.HandlePushRules)
|
c.syncer.OnEventType(event.AccountDataPushRules, c.HandlePushRules)
|
||||||
c.syncer.OnEventType(event.AccountDataRoomTags, c.HandleTag)
|
c.syncer.OnEventType(event.AccountDataRoomTags, c.HandleTag)
|
||||||
c.syncer.OnEventType(AccountDataGomuksPreferences, c.HandlePreferences)
|
c.syncer.OnEventType(AccountDataGomuksPreferences, c.HandlePreferences)
|
||||||
if len(c.config.AuthCache.NextBatch) == 0 {
|
|
||||||
c.syncer.Progress = c.ui.MainView().OpenSyncingModal()
|
|
||||||
c.syncer.Progress.SetMessage("Waiting for /sync response from server")
|
|
||||||
c.syncer.Progress.SetIndeterminate()
|
|
||||||
c.syncer.FirstDoneCallback = func() {
|
|
||||||
c.syncer.Progress.Close()
|
|
||||||
c.syncer.Progress = StubSyncingModal{}
|
|
||||||
c.syncer.FirstDoneCallback = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.syncer.InitDoneCallback = func() {
|
c.syncer.InitDoneCallback = func() {
|
||||||
debug.Print("Initial sync done")
|
debug.Print("Initial sync done")
|
||||||
c.config.AuthCache.InitialSyncDone = true
|
c.config.AuthCache.InitialSyncDone = true
|
||||||
|
@ -448,7 +434,33 @@ func (c *Container) OnLogin() {
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
dbg.FreeOSMemory()
|
dbg.FreeOSMemory()
|
||||||
}
|
}
|
||||||
|
|
||||||
c.client.Syncer = c.syncer
|
c.client.Syncer = c.syncer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Container) ProcessSyncResponse(res *mautrix.RespSync, since string) error {
|
||||||
|
return c.syncer.ProcessResponse(res, since)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnLogin initializes the syncer and updates the room list.
|
||||||
|
func (c *Container) OnLogin() {
|
||||||
|
c.cryptoOnLogin()
|
||||||
|
c.ui.OnLogin()
|
||||||
|
|
||||||
|
c.client.Store = c.config
|
||||||
|
|
||||||
|
debug.Print("Initializing syncer")
|
||||||
|
c.InitSyncer()
|
||||||
|
if len(c.config.AuthCache.NextBatch) == 0 {
|
||||||
|
c.syncer.Progress = c.ui.MainView().OpenSyncingModal()
|
||||||
|
c.syncer.Progress.SetMessage("Waiting for /sync response from server")
|
||||||
|
c.syncer.Progress.SetIndeterminate()
|
||||||
|
c.syncer.FirstDoneCallback = func() {
|
||||||
|
c.syncer.Progress.Close()
|
||||||
|
c.syncer.Progress = StubSyncingModal{}
|
||||||
|
c.syncer.FirstDoneCallback = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
debug.Print("Setting existing rooms")
|
debug.Print("Setting existing rooms")
|
||||||
c.ui.MainView().SetRooms(c.config.Rooms)
|
c.ui.MainView().SetRooms(c.config.Rooms)
|
||||||
|
|
Loading…
Add table
Reference in a new issue