mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-09 17:45:03 +09:00
Add settings snapshot logic
This commit is contained in:
parent
16a5c2efe9
commit
8729d069dc
6 changed files with 71 additions and 10 deletions
|
@ -40,6 +40,8 @@ var (
|
|||
ErrCantDeleteSpace = errors.New("not able to delete space")
|
||||
)
|
||||
|
||||
var doSnapshot = objecttree.DoSnapshot
|
||||
|
||||
type BuildTreeFunc func(ctx context.Context, id string, listener updatelistener.UpdateListener) (t synctree.SyncTree, err error)
|
||||
|
||||
type Deps struct {
|
||||
|
@ -228,14 +230,13 @@ func (s *settingsObject) DeleteObject(id string) (err error) {
|
|||
err = ErrObjDoesNotExist
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: add snapshot logic
|
||||
res, err := s.changeFactory.CreateObjectDeleteChange(id, s.state, false)
|
||||
isSnapshot := doSnapshot(s.Len())
|
||||
res, err := s.changeFactory.CreateObjectDeleteChange(id, s.state, isSnapshot)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return s.addContent(res)
|
||||
return s.addContent(res, isSnapshot)
|
||||
}
|
||||
|
||||
func (s *settingsObject) verifyDeleteSpace(raw *treechangeproto.RawTreeChangeWithId) (err error) {
|
||||
|
@ -246,12 +247,12 @@ func (s *settingsObject) verifyDeleteSpace(raw *treechangeproto.RawTreeChangeWit
|
|||
return verifyDeleteContent(data, "")
|
||||
}
|
||||
|
||||
func (s *settingsObject) addContent(data []byte) (err error) {
|
||||
func (s *settingsObject) addContent(data []byte, isSnapshot bool) (err error) {
|
||||
accountData := s.account.Account()
|
||||
_, err = s.AddContent(context.Background(), objecttree.SignableChangeContent{
|
||||
Data: data,
|
||||
Key: accountData.SignKey,
|
||||
IsSnapshot: false,
|
||||
IsSnapshot: isSnapshot,
|
||||
IsEncrypted: false,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -24,9 +24,10 @@ func (c *changeFactory) CreateObjectDeleteChange(id string, state *State, isSnap
|
|||
Content: []*spacesyncproto.SpaceSettingsContent{
|
||||
{Value: content},
|
||||
},
|
||||
Snapshot: nil,
|
||||
}
|
||||
// TODO: add snapshot logic
|
||||
if isSnapshot {
|
||||
change.Snapshot = c.makeSnapshot(state, id, "")
|
||||
}
|
||||
res, err = change.Marshal()
|
||||
return
|
||||
}
|
||||
|
@ -39,9 +40,21 @@ func (c *changeFactory) CreateSpaceDeleteChange(peerId string, state *State, isS
|
|||
Content: []*spacesyncproto.SpaceSettingsContent{
|
||||
{Value: content},
|
||||
},
|
||||
Snapshot: nil,
|
||||
}
|
||||
// TODO: add snapshot logic
|
||||
if isSnapshot {
|
||||
change.Snapshot = c.makeSnapshot(state, "", peerId)
|
||||
}
|
||||
res, err = change.Marshal()
|
||||
return
|
||||
}
|
||||
|
||||
func (c *changeFactory) makeSnapshot(state *State, objectId, deleterPeer string) *spacesyncproto.SpaceSettingsSnapshot {
|
||||
deletedIds := state.DeletedIds
|
||||
if objectId != "" {
|
||||
deletedIds = append(deletedIds, objectId)
|
||||
}
|
||||
return &spacesyncproto.SpaceSettingsSnapshot{
|
||||
DeletedIds: deletedIds,
|
||||
DeleterPeerId: deleterPeer,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue