From e64df67ec397795b8c6ebd06b391d953afe5a766 Mon Sep 17 00:00:00 2001
From: Tulir Asokan <tulir@maunium.net>
Date: Tue, 24 Apr 2018 16:51:40 +0300
Subject: Everything is no longer broken

---
 matrix/rooms/room.go | 10 ++++++++++
 1 file changed, 10 insertions(+)

(limited to 'matrix/rooms')

diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go
index 44a386b..9aae5ea 100644
--- a/matrix/rooms/room.go
+++ b/matrix/rooms/room.go
@@ -23,6 +23,7 @@ import (
 	"time"
 
 	"maunium.net/go/gomatrix"
+	"maunium.net/go/gomuks/debug"
 )
 
 type RoomNameSource int
@@ -148,6 +149,15 @@ func (room *Room) UpdateState(event *gomatrix.Event) {
 	case "m.room.topic":
 		room.topicCache = ""
 	}
+
+	stateKey := ""
+	if event.StateKey != nil {
+		stateKey = *event.StateKey
+	}
+	if event.Type != "m.room.member" {
+		debug.Printf("[ROOM] Updating state %s#%s for %s", event.Type, stateKey, room.ID)
+	}
+
 	if event.StateKey == nil {
 		room.State[event.Type][""] = event
 	} else {
-- 
cgit v1.2.3-70-g09d2


From 28c65275440b3f7371540b49733db8b6b170a64d Mon Sep 17 00:00:00 2001
From: Tulir Asokan <tulir@maunium.net>
Date: Tue, 24 Apr 2018 17:12:08 +0300
Subject: Fix/break/change things

---
 config/session.go    |  4 ----
 matrix/matrix.go     |  6 ++++--
 matrix/rooms/room.go |  2 +-
 matrix/sync.go       | 12 ++++++------
 ui/message-view.go   |  1 +
 5 files changed, 12 insertions(+), 13 deletions(-)

(limited to 'matrix/rooms')

diff --git a/config/session.go b/config/session.go
index e47592c..d23c778 100644
--- a/config/session.go
+++ b/config/session.go
@@ -52,10 +52,6 @@ func (config *Config) NewSession(mxid string) *Session {
 	}
 }
 
-func (s *Session) SetInitialSyncDone() {
-	s.InitialSyncDone = true
-}
-
 func (s *Session) GetUserID() string {
 	return s.UserID
 }
diff --git a/matrix/matrix.go b/matrix/matrix.go
index 530612c..f2b8bf3 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -175,6 +175,10 @@ func (c *Container) OnLogin() {
 	c.syncer.OnEventType("m.typing", c.HandleTyping)
 	c.syncer.OnEventType("m.push_rules", c.HandlePushRules)
 	c.syncer.OnEventType("m.tag", c.HandleTag)
+	c.syncer.InitDoneCallback = func() {
+		c.config.Session.InitialSyncDone = true
+		c.ui.Render()
+	}
 	c.client.Syncer = c.syncer
 
 	debug.Print("Setting existing rooms")
@@ -224,7 +228,6 @@ func (c *Container) HandleMessage(evt *gomatrix.Event) {
 
 	message := mainView.ParseEvent(roomView, evt)
 	if message != nil {
-		debug.Print("Adding message", message.ID(), c.syncer.FirstSyncDone, c.config.Session.InitialSyncDone)
 		roomView.AddMessage(message, ifc.AppendMessage)
 		if c.syncer.FirstSyncDone {
 			pushRules := c.PushRules().GetActions(roomView.MxRoom(), evt).Should()
@@ -307,7 +310,6 @@ func (c *Container) HandleMembership(evt *gomatrix.Event) {
 
 	message := mainView.ParseEvent(roomView, evt)
 	if message != nil {
-		debug.Print("Adding membership event", message.ID(), c.syncer.FirstSyncDone, c.config.Session.InitialSyncDone)
 		// TODO this shouldn't be necessary
 		//roomView.MxRoom().UpdateState(evt)
 		// TODO This should probably also be in a different place
diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go
index 9aae5ea..95349c3 100644
--- a/matrix/rooms/room.go
+++ b/matrix/rooms/room.go
@@ -155,7 +155,7 @@ func (room *Room) UpdateState(event *gomatrix.Event) {
 		stateKey = *event.StateKey
 	}
 	if event.Type != "m.room.member" {
-		debug.Printf("[ROOM] Updating state %s#%s for %s", event.Type, stateKey, room.ID)
+		debug.Printf("Updating state %s#%s for %s", event.Type, stateKey, room.ID)
 	}
 
 	if event.StateKey == nil {
diff --git a/matrix/sync.go b/matrix/sync.go
index d0e1e69..8ad7ad5 100644
--- a/matrix/sync.go
+++ b/matrix/sync.go
@@ -28,7 +28,6 @@ import (
 
 type SyncerSession interface {
 	GetRoom(id string) *rooms.Room
-	SetInitialSyncDone()
 	GetUserID() string
 }
 
@@ -36,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
@@ -81,8 +81,8 @@ func (s *GomuksSyncer) ProcessResponse(res *gomatrix.RespSync, since string) (er
 		}
 	}
 
-	if since == "" {
-		s.Session.SetInitialSyncDone()
+	if since == "" && s.InitDoneCallback != nil {
+		s.InitDoneCallback()
 	}
 	s.FirstSyncDone = true
 
diff --git a/ui/message-view.go b/ui/message-view.go
index 2e33cd7..f2fb72f 100644
--- a/ui/message-view.go
+++ b/ui/message-view.go
@@ -234,6 +234,7 @@ func (view *MessageView) replaceBuffer(original messages.UIMessage, new messages
 
 	if start == -1 {
 		debug.Print("Called replaceBuffer() with message that was not in the buffer:", original.ID())
+		debug.PrintStack()
 		view.appendBuffer(new)
 		return
 	}
-- 
cgit v1.2.3-70-g09d2