aboutsummaryrefslogtreecommitdiff
path: root/matrix/sync.go
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-04-24 22:58:30 +0300
committerGitHub <noreply@github.com>2018-04-24 22:58:30 +0300
commit7026ed99a3ef4071a35e74d2d5f9026f6848be92 (patch)
tree33332880db2cbdaeabaeb4e1ddbf94a3f15686a3 /matrix/sync.go
parent49cd74c548e3baf259fce9270af3ecca5bdb625e (diff)
parentd7d654e2ec0a1d001f936b1575a3e6af3973a874 (diff)
Merge pull request #33 from tulir/initial-sync
Use initial sync data instead of fetching room list, state, history, etc manually
Diffstat (limited to 'matrix/sync.go')
-rw-r--r--matrix/sync.go31
1 files changed, 14 insertions, 17 deletions
diff --git a/matrix/sync.go b/matrix/sync.go
index f3966cb..8ad7ad5 100644
--- a/matrix/sync.go
+++ b/matrix/sync.go
@@ -20,8 +20,6 @@ package matrix
import (
"encoding/json"
- "fmt"
- "runtime/debug"
"time"
"maunium.net/go/gomatrix"
@@ -37,9 +35,10 @@ type SyncerSession interface {
// replace parts of this default syncer (e.g. the ProcessResponse method). The default syncer uses the observer
// pattern to notify callers about incoming events. See GomuksSyncer.OnEventType for more information.
type GomuksSyncer struct {
- Session SyncerSession
- listeners map[string][]gomatrix.OnEventListener // event type to listeners array
- FirstSyncDone bool
+ Session SyncerSession
+ listeners map[string][]gomatrix.OnEventListener // event type to listeners array
+ FirstSyncDone bool
+ InitDoneCallback func()
}
// NewGomuksSyncer returns an instantiated GomuksSyncer
@@ -53,17 +52,6 @@ func NewGomuksSyncer(session SyncerSession) *GomuksSyncer {
// ProcessResponse processes a Matrix sync response.
func (s *GomuksSyncer) ProcessResponse(res *gomatrix.RespSync, since string) (err error) {
- if len(since) == 0 {
- 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.AccountData.Events, false, false)
@@ -93,6 +81,9 @@ func (s *GomuksSyncer) ProcessResponse(res *gomatrix.RespSync, since string) (er
}
}
+ if since == "" && s.InitDoneCallback != nil {
+ s.InitDoneCallback()
+ }
s.FirstSyncDone = true
return
@@ -147,7 +138,13 @@ func (s *GomuksSyncer) GetFilterJSON(userID string) json.RawMessage {
"room": {
"include_leave": true,
"state": {
- "types": ["m.room.member"]
+ "types": [
+ "m.room.member",
+ "m.room.name",
+ "m.room.topic",
+ "m.room.canonical_alias",
+ "m.room.aliases"
+ ]
},
"timeline": {
"types": ["m.room.message"],