aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2019-06-16 14:29:03 +0300
committerTulir Asokan <tulir@maunium.net>2019-06-16 14:54:12 +0300
commit2b7d5d54011ffcc93511bf05f44163a4b7a1270c (patch)
tree48a88e26a12f04b3f922c9ec54c4e2db061125fb
parent6bb932212cbadac6eed59ac153ebe041523f7570 (diff)
Fix reply rendering infinite loop bug
-rw-r--r--go.mod2
-rw-r--r--matrix/matrix.go7
-rw-r--r--matrix/rooms/room.go6
-rw-r--r--ui/commands.go2
-rw-r--r--ui/message-view.go2
-rw-r--r--ui/messages/base.go4
-rw-r--r--ui/messages/parser.go4
7 files changed, 17 insertions, 10 deletions
diff --git a/go.mod b/go.mod
index c4cd3e1..94aa798 100644
--- a/go.mod
+++ b/go.mod
@@ -25,7 +25,7 @@ require (
gopkg.in/russross/blackfriday.v2 v2.0.1
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2
gopkg.in/yaml.v2 v2.2.2
- maunium.net/go/mautrix v0.1.0-alpha.3.0.20190607192515-d505052a02ac
+ maunium.net/go/mautrix v0.1.0-alpha.3.0.20190616114735-e5bf3141e88e
maunium.net/go/mauview v0.0.0-20190606152754-de9e0a754a5d
maunium.net/go/tcell v0.0.0-20190606152714-9a88fc07b3ed
)
diff --git a/matrix/matrix.go b/matrix/matrix.go
index 1a75f96..cfd5614 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -29,7 +29,9 @@ import (
"path"
"path/filepath"
"regexp"
+ "runtime"
"time"
+ dbg "runtime/debug"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/format"
@@ -232,6 +234,11 @@ func (c *Container) OnLogin() {
debug.Print("Adding rooms to UI")
c.ui.MainView().SetRooms(c.config.Rooms)
c.ui.Render()
+ // The initial sync can be a bit heavy, so we force run the GC here
+ // after cleaning up rooms from memory above.
+ debug.Print("Running GC")
+ runtime.GC()
+ dbg.FreeOSMemory()
}
c.client.Syncer = c.syncer
diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go
index a0918b1..be91065 100644
--- a/matrix/rooms/room.go
+++ b/matrix/rooms/room.go
@@ -148,6 +148,9 @@ func (room *Room) Load() {
room.lock.Lock()
room.load()
room.lock.Unlock()
+ if room.postLoad != nil {
+ room.postLoad()
+ }
}
func (room *Room) load() {
@@ -177,9 +180,6 @@ func (room *Room) load() {
debug.Print("Failed to decode room state:", err)
}
room.changed = false
- if room.postLoad != nil {
- room.postLoad()
- }
}
func (room *Room) Touch() {
diff --git a/ui/commands.go b/ui/commands.go
index ab02735..0b15d8e 100644
--- a/ui/commands.go
+++ b/ui/commands.go
@@ -76,8 +76,8 @@ var rainbow = GradientTable{
}
func cmdHeapProfile(cmd *Command) {
- dbg.FreeOSMemory()
runtime.GC()
+ dbg.FreeOSMemory()
memProfile, err := os.Create("gomuks.heap.prof")
if err != nil {
debug.Print("Failed to open gomuks.heap.prof:", err)
diff --git a/ui/message-view.go b/ui/message-view.go
index 81a6d7c..9aa38a1 100644
--- a/ui/message-view.go
+++ b/ui/message-view.go
@@ -143,7 +143,7 @@ func (view *MessageView) AddMessage(ifcMessage ifc.Message, direction MessageDir
view.replaceMessage(oldMsg, message)
view.deleteMessageID(message.TxnID)
direction = IgnoreMessage
- } else if oldMsg = view.getMessageByID(message.Relation.EventID); oldMsg != nil {
+ } else if oldMsg = view.getMessageByID(message.Relation.GetReplaceID()); oldMsg != nil {
direction = IgnoreMessage
}
diff --git a/ui/messages/base.go b/ui/messages/base.go
index 123c5c1..ef495fb 100644
--- a/ui/messages/base.go
+++ b/ui/messages/base.go
@@ -241,6 +241,7 @@ func (msg *UIMessage) Draw(screen mauview.Screen) {
func (msg *UIMessage) Clone() *UIMessage {
clone := *msg
+ clone.ReplyTo = nil
clone.Renderer = clone.Renderer.Clone()
return &clone
}
@@ -253,7 +254,8 @@ func (msg *UIMessage) CalculateReplyBuffer(preferences config.UserPreferences, w
}
func (msg *UIMessage) CalculateBuffer(preferences config.UserPreferences, width int) {
- msg.Renderer.CalculateBuffer(preferences, width-1, msg)
+ msg.Renderer.CalculateBuffer(preferences, width, msg)
+ msg.CalculateReplyBuffer(preferences, width)
}
func (msg *UIMessage) DrawReply(screen mauview.Screen) mauview.Screen {
diff --git a/ui/messages/parser.go b/ui/messages/parser.go
index 123f323..29f078c 100644
--- a/ui/messages/parser.go
+++ b/ui/messages/parser.go
@@ -49,9 +49,7 @@ func ParseEvent(matrix ifc.MatrixContainer, mainView ifc.MainView, room *rooms.R
}
if len(evt.Content.GetReplyTo()) > 0 {
if replyToMsg := getCachedEvent(mainView, room.ID, evt.Content.GetReplyTo()); replyToMsg != nil {
- replyToMsg = replyToMsg.Clone()
- replyToMsg.ReplyTo = nil
- msg.ReplyTo = replyToMsg
+ msg.ReplyTo = replyToMsg.Clone()
} else if replyToEvt, _ := matrix.GetEvent(room, evt.Content.GetReplyTo()); replyToEvt != nil {
if replyToMsg := directParseEvent(matrix, room, replyToEvt); replyToMsg != nil {
msg.ReplyTo = replyToMsg