diff options
author | Tulir Asokan <tulir@maunium.net> | 2019-06-15 18:03:28 +0300 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2019-06-15 18:03:28 +0300 |
commit | ef509eb3082e4017284345b195ce0489c90a993d (patch) | |
tree | 1c2f6d8431fc62999971cab5b105075fd2c84227 /matrix | |
parent | 0f08c49df40f77e90e4b5ef7604c74631065faa3 (diff) |
Fix infinite recursion
Diffstat (limited to 'matrix')
-rw-r--r-- | matrix/rooms/room.go | 35 |
1 files changed, 25 insertions, 10 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() { |