package settings import ( "github.com/anytypeio/any-sync/commonspace/object/tree/objecttree" "github.com/anytypeio/any-sync/commonspace/spacesyncproto" "github.com/gogo/protobuf/proto" ) type DeletedIdsProvider interface { ProvideIds(tr objecttree.ObjectTree, startId string) (ids []string, lastId string, err error) } type provider struct{} func (p *provider) processChange(change *objecttree.Change, rootId, startId string, ids []string) []string { // ignoring root change which has empty model or startId change if change.Model == nil || (change.Id == startId && startId != "") { return ids } deleteChange := change.Model.(*spacesyncproto.SettingsData) // getting data from snapshot if we start from it if change.Id == rootId { ids = deleteChange.Snapshot.DeletedIds return ids } // otherwise getting data from content for _, cnt := range deleteChange.Content { if cnt.GetObjectDelete() != nil { ids = append(ids, cnt.GetObjectDelete().GetId()) } } return ids } func (p *provider) ProvideIds(tr objecttree.ObjectTree, startId string) (ids []string, lastId string, err error) { rootId := tr.Root().Id process := func(change *objecttree.Change) bool { lastId = change.Id ids = p.processChange(change, rootId, startId, ids) return true } convert := func(decrypted []byte) (res any, err error) { deleteChange := &spacesyncproto.SettingsData{} err = proto.Unmarshal(decrypted, deleteChange) if err != nil { return nil, err } return deleteChange, nil } if startId == "" { startId = rootId } err = tr.IterateFrom(startId, convert, process) return }