WIP create change continue

This commit is contained in:
mcrakhman 2022-07-07 11:32:02 +02:00 committed by Mikhail Iudin
parent 2f66bd3e9c
commit 8f704e6de0
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0
3 changed files with 12 additions and 1 deletions

View File

@ -15,6 +15,7 @@ type AccountData struct {
} }
type Document struct { type Document struct {
// TODO: ensure that every operation on Document is synchronized
thread threadmodels.Thread thread threadmodels.Thread
stateProvider InitialStateProvider stateProvider InitialStateProvider
accountData *AccountData accountData *AccountData
@ -99,6 +100,14 @@ func (d *Document) Create(payload *CreateChangePayload) error {
if err != nil { if err != nil {
return err return err
} }
if aclChange.AclData != nil {
// we can apply change right away without going through builder, because
err = d.docContext.aclState.ApplyChange(payload.Id, aclChange)
if err != nil {
return err
}
}
d.docContext.fullTree.AddFast(ch) d.docContext.fullTree.AddFast(ch)
err = d.thread.AddChange(&threadmodels.RawChange{ err = d.thread.AddChange(&threadmodels.RawChange{
@ -157,6 +166,7 @@ func (d *Document) Update(changes ...*threadmodels.RawChange) (DocumentState, Up
break break
} }
// TODO: we should still check if the user making those changes are able to write using "aclState"
// decrypting everything, because we have no new keys // decrypting everything, because we have no new keys
for _, ch := range treeChanges { for _, ch := range treeChanges {
if ch.Content.GetChangesData() != nil { if ch.Content.GetChangesData() != nil {

View File

@ -1,7 +1,7 @@
package data package data
type documentContext struct { type documentContext struct {
aclTree *Tree aclTree *Tree // TODO: remove it, because we don't use it
fullTree *Tree fullTree *Tree
aclState *ACLState aclState *ACLState
docState DocumentState docState DocumentState

View File

@ -66,6 +66,7 @@ func (d *documentStateBuilder) build() (s DocumentState, err error) {
func (d *documentStateBuilder) appendFrom(fromId string, init DocumentState) (s DocumentState, err error) { func (d *documentStateBuilder) appendFrom(fromId string, init DocumentState) (s DocumentState, err error) {
// TODO: we should do something like state copy probably // TODO: we should do something like state copy probably
s = init s = init
// TODO: we should have the same logic as in ACLStateBuilder, that means we should either pass in both methods state from the outside or save the state inside the builder
d.tree.Iterate(fromId, func(c *Change) (isContinue bool) { d.tree.Iterate(fromId, func(c *Change) (isContinue bool) {
if c.Id == fromId { if c.Id == fromId {
return true return true