X-Git-Url: http://git.giacomolli.uk/onechat/blobdiff_plain/0821d23c64f4ffc856760e4914fa39ba2e3260e4..c9183f90d757006e7221ecd0d4dc0db2a25f87e0:/memory.go?ds=sidebyside diff --git a/memory.go b/memory.go index cb55cab..c3e9f45 100644 --- a/memory.go +++ b/memory.go @@ -272,15 +272,24 @@ func (m *Memory) Append(kind, text string) (Message, error) { } // addMessage builds the leaf of message when it needs no model call, or else -// adds the leaf to the queue. Then it appends the leaf to the views. +// adds the leaf to the queue. Then it appends the leaf to the views. A crash can +// stop an append after the leaf build and before the view save, so a leaf that +// is built already stays as it is, and restoreQueue settles its parent. func (m *Memory) addMessage(message Message) error { + built, err := m.tree.Built(0, message.ID) + if err != nil { + return err + } + leaf, free := freeLeaf(message) - if free { - err := m.build(leaf) + switch { + case built: + case free: + err = m.build(leaf) if err != nil { return err } - } else { + default: m.queue.AddLeaf(message.ID) }