aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2019-06-15 18:03:28 +0300
committerTulir Asokan <tulir@maunium.net>2019-06-15 18:03:28 +0300
commitef509eb3082e4017284345b195ce0489c90a993d (patch)
tree1c2f6d8431fc62999971cab5b105075fd2c84227
parent0f08c49df40f77e90e4b5ef7604c74631065faa3 (diff)
Fix infinite recursion
-rw-r--r--matrix/rooms/room.go35
-rw-r--r--ui/room-view.go7
2 files changed, 27 insertions, 15 deletions
diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go
index 972a32a..ec8b0d9 100644
--- a/matrix/rooms/room.go
+++ b/matrix/rooms/room.go
@@ -115,10 +115,11 @@ type Room struct {
cache *RoomCache
// Lock for state and other room stuff.
lock sync.RWMutex
- // Function to call when room state is unloaded.
- onUnload func() bool
- // Function to call when room state is loaded.
- onLoad func() bool
+ // Pre/post un/load hooks
+ preUnload func() bool
+ preLoad func() bool
+ postUnload func()
+ postLoad func()
// Whether or not the room state has changed
changed bool
@@ -143,7 +144,7 @@ func (room *Room) Load() {
if room.Loaded() {
return
}
- if room.onLoad != nil && !room.onLoad() {
+ if room.preLoad != nil && !room.preLoad() {
return
}
room.lock.Lock()
@@ -178,6 +179,9 @@ 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() {
@@ -185,7 +189,7 @@ func (room *Room) Touch() {
}
func (room *Room) Unload() bool {
- if room.onUnload != nil && !room.onUnload() {
+ if room.preUnload != nil && !room.preUnload() {
return false
}
debug.Print("Unloading", room.ID)
@@ -196,15 +200,26 @@ func (room *Room) Unload() bool {
room.canonicalAliasCache = ""
room.firstMemberCache = nil
room.secondMemberCache = nil
+ if room.postUnload != nil {
+ room.postUnload()
+ }
return true
}
-func (room *Room) SetOnUnload(fn func() bool) {
- room.onUnload = fn
+func (room *Room) SetPreUnload(fn func() bool) {
+ room.preUnload = fn
+}
+
+func (room *Room) SetPreLoad(fn func() bool) {
+ room.preLoad = fn
+}
+
+func (room *Room) SetPostUnload(fn func()) {
+ room.postUnload = fn
}
-func (room *Room) SetOnLoad(fn func() bool) {
- room.onLoad = fn
+func (room *Room) SetPostLoad(fn func()) {
+ room.postLoad = fn
}
func (room *Room) Save() {
diff --git a/ui/room-view.go b/ui/room-view.go
index 48943a7..00aa09a 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -93,17 +93,14 @@ func NewRoomView(parent *MainView, room *rooms.Room) *RoomView {
config: parent.config,
}
view.content = NewMessageView(view)
- view.Room.SetOnUnload(func() bool {
+ view.Room.SetPreUnload(func() bool {
if view.parent.currentRoom == view {
return false
}
view.content.Unload()
return true
})
- view.Room.SetOnLoad(func() bool {
- view.loadTyping()
- return true
- })
+ view.Room.SetPostLoad(view.loadTyping)
view.input.
SetBackgroundColor(tcell.ColorDefault).