Initial move to initial sync. Everything broke :(

This commit is contained in:
Tulir Asokan 2018-04-24 02:11:32 +03:00
parent 2a0145db88
commit fcd9a932cb
3 changed files with 17 additions and 13 deletions

View File

@ -35,6 +35,8 @@ type Session struct {
FilterID string FilterID string
Rooms map[string]*rooms.Room Rooms map[string]*rooms.Room
PushRules *pushrules.PushRuleset PushRules *pushrules.PushRuleset
InitialSyncDone bool
} }
func (config *Config) LoadSession(mxid string) error { func (config *Config) LoadSession(mxid string) error {
@ -50,6 +52,10 @@ func (config *Config) NewSession(mxid string) *Session {
} }
} }
func (s *Session) SetInitialSyncDone() {
s.InitialSyncDone = true
}
func (s *Session) GetUserID() string { func (s *Session) GetUserID() string {
return s.UserID return s.UserID
} }

View File

@ -191,7 +191,7 @@ func (c *Container) OnLogin() {
c.syncer.OnEventType("m.tag", c.HandleTag) c.syncer.OnEventType("m.tag", c.HandleTag)
c.client.Syncer = c.syncer c.client.Syncer = c.syncer
c.UpdateRoomList() //c.UpdateRoomList()
} }
// Start moves the UI to the main view, calls OnLogin() and runs the syncer forever until stopped with Stop() // Start moves the UI to the main view, calls OnLogin() and runs the syncer forever until stopped with Stop()
@ -296,6 +296,10 @@ func (c *Container) HandleMembership(evt *gomatrix.Event) {
c.processOwnMembershipChange(evt) c.processOwnMembershipChange(evt)
} }
if !c.config.Session.InitialSyncDone && evt.Timestamp < time.Now().Add(-1*time.Hour).Unix() {
return
}
mainView := c.ui.MainView() mainView := c.ui.MainView()
roomView := mainView.GetRoom(evt.RoomID) roomView := mainView.GetRoom(evt.RoomID)
if roomView == nil { if roomView == nil {

View File

@ -20,16 +20,16 @@ package matrix
import ( import (
"encoding/json" "encoding/json"
"fmt"
"runtime/debug"
"time" "time"
"maunium.net/go/gomatrix" "maunium.net/go/gomatrix"
"maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/matrix/rooms" "maunium.net/go/gomuks/matrix/rooms"
) )
type SyncerSession interface { type SyncerSession interface {
GetRoom(id string) *rooms.Room GetRoom(id string) *rooms.Room
SetInitialSyncDone()
GetUserID() string GetUserID() string
} }
@ -53,16 +53,7 @@ func NewGomuksSyncer(session SyncerSession) *GomuksSyncer {
// ProcessResponse processes a Matrix sync response. // ProcessResponse processes a Matrix sync response.
func (s *GomuksSyncer) ProcessResponse(res *gomatrix.RespSync, since string) (err error) { func (s *GomuksSyncer) ProcessResponse(res *gomatrix.RespSync, since string) (err error) {
if len(since) == 0 { debug.Print("Processing sync response", since, res)
return
}
// debug.Print("Processing sync response", since, res)
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("ProcessResponse for %s since %s panicked: %s\n%s", s.Session.GetUserID(), since, r, debug.Stack())
}
}()
s.processSyncEvents(nil, res.Presence.Events, false, false) s.processSyncEvents(nil, res.Presence.Events, false, false)
s.processSyncEvents(nil, res.AccountData.Events, false, false) s.processSyncEvents(nil, res.AccountData.Events, false, false)
@ -93,6 +84,9 @@ func (s *GomuksSyncer) ProcessResponse(res *gomatrix.RespSync, since string) (er
} }
} }
if since == "" {
s.Session.SetInitialSyncDone()
}
s.FirstSyncDone = true s.FirstSyncDone = true
return return