diff --git a/core/block/editor/state/normalize.go b/core/block/editor/state/normalize.go index 9c4d02760..ee9b82391 100644 --- a/core/block/editor/state/normalize.go +++ b/core/block/editor/state/normalize.go @@ -2,8 +2,6 @@ package state import ( "fmt" - "github.com/anytypeio/go-anytype-middleware/core/block/simple/base" - "github.com/globalsign/mgo/bson" "github.com/anytypeio/go-anytype-middleware/core/block/simple" @@ -43,12 +41,7 @@ func (s *State) normalize(withLayouts bool) (err error) { } } if b.Model().Id == s.RootId() { - if n, ok := b.(base.Normalizable); ok { - if err := n.Normalize(); err != nil { - return fmt.Errorf("custom normalization for block %s: %w", b.Model().Id, err) - } - } - + s.normalizeSmartBlock(b) } } @@ -291,6 +284,22 @@ func (s *State) removeDuplicates() { }) } +func (s *State) normalizeSmartBlock(b simple.Block) { + if isBlockEmpty(b) { + b.Model().Content = &model.BlockContentOfSmartblock{ + Smartblock: &model.BlockContentSmartblock{}, + } + } +} + +func isBlockEmpty(b simple.Block) bool { + if b.Model().Content == nil { + return true + } + smartBlock := b.Model().Content.(*model.BlockContentOfSmartblock) + return smartBlock == nil || smartBlock.Smartblock == nil +} + func CleanupLayouts(s *State) (removedCount int) { var cleanup func(id string) []string cleanup = func(id string) (result []string) { diff --git a/core/block/simple/base/base.go b/core/block/simple/base/base.go index e958a0ada..ba5434bb8 100644 --- a/core/block/simple/base/base.go +++ b/core/block/simple/base/base.go @@ -30,10 +30,6 @@ type Base struct { *model.Block } -type Normalizable interface { - Normalize() error -} - func (s *Base) Model() *model.Block { return s.Block } @@ -109,23 +105,6 @@ func (b *Base) String() string { return fmt.Sprintf("%s: %T (%d)", b.Id, b.Content, len(b.ChildrenIds)) } -func (b *Base) Normalize() error { - if isBlockEmpty(b) { - b.Content = &model.BlockContentOfSmartblock{ - Smartblock: &model.BlockContentSmartblock{}, - } - } - return nil -} - -func isBlockEmpty(block *Base) bool { - if block.Content == nil { - return true - } - smartBlock := block.Content.(*model.BlockContentOfSmartblock) - return smartBlock == nil || smartBlock.Smartblock == nil -} - func stringSlicesEq(s1, s2 []string) bool { if len(s1) != len(s2) { return false