mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 17:44:59 +09:00
GO-5344 Merge branch 'main' of github.com:anyproto/anytype-heart into go-5344-add-mention-counters
This commit is contained in:
commit
85fff3c4db
11 changed files with 67 additions and 14 deletions
|
@ -116,6 +116,10 @@ func validateDetails(s *pb.SnapshotWithType, info *useCaseInfo) (err error) {
|
|||
continue
|
||||
}
|
||||
|
||||
if k == bundle.RelationKeyAutoWidgetTargets.String() && val == "bin" {
|
||||
continue
|
||||
}
|
||||
|
||||
_, found := info.objects[val]
|
||||
if !found {
|
||||
if isBrokenTemplate(k, val) {
|
||||
|
|
|
@ -95,7 +95,7 @@ func (ot *ObjectType) Init(ctx *smartblock.InitContext) (err error) {
|
|||
|
||||
func (ot *ObjectType) CreationStateMigration(ctx *smartblock.InitContext) migration.Migration {
|
||||
return migration.Migration{
|
||||
Version: 2,
|
||||
Version: 4,
|
||||
Proc: func(s *state.State) {
|
||||
if len(ctx.ObjectTypeKeys) > 0 && len(ctx.State.ObjectTypeKeys()) == 0 {
|
||||
ctx.State.SetObjectTypeKeys(ctx.ObjectTypeKeys)
|
||||
|
@ -417,7 +417,7 @@ func (ot *ObjectType) dataviewTemplates() []template.StateTransformer {
|
|||
|
||||
dvContent.Dataview.TargetObjectId = ot.Id()
|
||||
return []template.StateTransformer{
|
||||
template.WithDataviewID(state.DataviewBlockID, dvContent, false),
|
||||
template.WithDataviewIDIfNotExists(state.DataviewBlockID, dvContent, false),
|
||||
template.WithForcedDetail(bundle.RelationKeySetOf, domain.StringList([]string{ot.Id()})),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -405,6 +405,22 @@ var WithAllBlocksEditsRestricted = StateTransformer(func(s *state.State) {
|
|||
})
|
||||
})
|
||||
|
||||
var WithDataviewIDIfNotExists = func(id string, dataview *model.BlockContentOfDataview, forceViews bool) StateTransformer {
|
||||
return func(s *state.State) {
|
||||
WithEmpty(s)
|
||||
if !s.Exists(id) {
|
||||
s.Set(simple.New(&model.Block{Content: dataview, Id: id}))
|
||||
if !s.IsParentOf(s.RootId(), id) {
|
||||
err := s.InsertTo(s.RootId(), model.Block_Inner, id)
|
||||
if err != nil {
|
||||
log.Errorf("template WithDataview failed to insert: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var WithDataviewID = func(id string, dataview *model.BlockContentOfDataview, forceViews bool) StateTransformer {
|
||||
return func(s *state.State) {
|
||||
WithEmpty(s)
|
||||
|
@ -414,10 +430,8 @@ var WithDataviewID = func(id string, dataview *model.BlockContentOfDataview, for
|
|||
if dvBlock, ok := b.(simpleDataview.Block); !ok {
|
||||
return true
|
||||
} else {
|
||||
if len(dvBlock.Model().GetDataview().Relations) == 0 ||
|
||||
!slice.UnsortedEqual(dvBlock.Model().GetDataview().Source, dataview.Dataview.Source) ||
|
||||
if !slice.UnsortedEqual(dvBlock.Model().GetDataview().Source, dataview.Dataview.Source) ||
|
||||
len(dvBlock.Model().GetDataview().Views) == 0 ||
|
||||
forceViews && len(dvBlock.Model().GetDataview().Relations) != len(dataview.Dataview.Relations) ||
|
||||
forceViews && !pbtypes.DataviewViewsEqualSorted(dvBlock.Model().GetDataview().Views, dataview.Dataview.Views) {
|
||||
|
||||
/* log.With("object" s.RootId()).With("name", pbtypes.GetString(s.Details(), "name")).Warnf("dataview needs to be migrated: %v, %v, %v, %v",
|
||||
|
|
|
@ -166,7 +166,6 @@ func (oc *ObjectCreator) Create(dataObject *DataObject, sn *common.Snapshot) (*d
|
|||
|
||||
func canUpdateObject(sbType coresb.SmartBlockType) bool {
|
||||
return sbType != coresb.SmartBlockTypeRelation &&
|
||||
sbType != coresb.SmartBlockTypeObjectType &&
|
||||
sbType != coresb.SmartBlockTypeRelationOption &&
|
||||
sbType != coresb.SmartBlockTypeFileObject &&
|
||||
sbType != coresb.SmartBlockTypeParticipant
|
||||
|
|
|
@ -42,6 +42,7 @@ import (
|
|||
"github.com/anyproto/anytype-heart/pb"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/core"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/core/smartblock"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/localstore/addr"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/localstore/filestore"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore"
|
||||
|
@ -494,7 +495,15 @@ func (i *Import) getObjectID(
|
|||
return err
|
||||
}
|
||||
oldIDToNew[snapshot.Id] = id
|
||||
if payload.RootRawChange != nil {
|
||||
var isBundled bool
|
||||
switch snapshot.Snapshot.SbType {
|
||||
case smartblock.SmartBlockTypeObjectType:
|
||||
isBundled = bundle.HasObjectTypeByKey(domain.TypeKey(snapshot.Snapshot.Data.Key))
|
||||
case smartblock.SmartBlockTypeRelation:
|
||||
isBundled = bundle.HasRelation(domain.RelationKey(snapshot.Snapshot.Data.Key))
|
||||
}
|
||||
// bundled types will be created and then updated, cause they can be installed asynchronously
|
||||
if payload.RootRawChange != nil && !isBundled {
|
||||
createPayloads[id] = payload
|
||||
}
|
||||
return i.extractInternalKey(snapshot, oldIDToNew)
|
||||
|
|
2
go.mod
2
go.mod
|
@ -8,7 +8,7 @@ require (
|
|||
github.com/VividCortex/ewma v1.2.0
|
||||
github.com/adrium/goheif v0.0.0-20230113233934-ca402e77a786
|
||||
github.com/anyproto/any-store v0.1.13
|
||||
github.com/anyproto/any-sync v0.6.10
|
||||
github.com/anyproto/any-sync v0.6.13
|
||||
github.com/anyproto/anytype-publish-server/publishclient v0.0.0-20250131145601-de288583ff2a
|
||||
github.com/anyproto/go-chash v0.1.0
|
||||
github.com/anyproto/go-naturaldate/v2 v2.0.2-0.20230524105841-9829cfd13438
|
||||
|
|
4
go.sum
4
go.sum
|
@ -80,8 +80,8 @@ github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kk
|
|||
github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=
|
||||
github.com/anyproto/any-store v0.1.13 h1:1wmm0qQIRShaycBLKwcgkQbRKy3WrNPAShTE5fwzfCY=
|
||||
github.com/anyproto/any-store v0.1.13/go.mod h1:2M0Xf4rmijoKGd+nqqeKG8I1yIokCLEIxrAXEoHjXn4=
|
||||
github.com/anyproto/any-sync v0.6.10 h1:TV3yLkp5NK7FkddUvVtfxT01t/Xi+DlKbvisGEQwmC0=
|
||||
github.com/anyproto/any-sync v0.6.10/go.mod h1:TSKgCoTV40Bt8AfCh3RxPUUAfYGrhc8Mzh8/AiVlvX4=
|
||||
github.com/anyproto/any-sync v0.6.13 h1:p1uc6uc+69X/WaaWVKs83sH8zDAbBo0COKYTcvHFXX8=
|
||||
github.com/anyproto/any-sync v0.6.13/go.mod h1:TSKgCoTV40Bt8AfCh3RxPUUAfYGrhc8Mzh8/AiVlvX4=
|
||||
github.com/anyproto/anytype-publish-server/publishclient v0.0.0-20250131145601-de288583ff2a h1:ZZM+0OUCQMWSLSflpkf0ZMVo3V76qEDDIXPpQOClNs0=
|
||||
github.com/anyproto/anytype-publish-server/publishclient v0.0.0-20250131145601-de288583ff2a/go.mod h1:4fkueCZcGniSMXkrwESO8zzERrh/L7WHimRNWecfGM0=
|
||||
github.com/anyproto/badger/v4 v4.2.1-0.20240110160636-80743fa3d580 h1:Ba80IlCCxkZ9H1GF+7vFu/TSpPvbpDCxXJ5ogc4euYc=
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
|
||||
)
|
||||
|
||||
const RelationChecksum = "a23583f8faef1cbfcd05ca1d2761538e67bbdd1336d1a467a0d657b5f986b313"
|
||||
const RelationChecksum = "c4effd0b56ce4d007b246e0371064334d9a7acd7dee184669939217848faa938"
|
||||
const (
|
||||
RelationKeyTag domain.RelationKey = "tag"
|
||||
RelationKeyCamera domain.RelationKey = "camera"
|
||||
|
@ -291,6 +291,7 @@ var (
|
|||
Hidden: true,
|
||||
Id: "_brautoWidgetDisabled",
|
||||
Key: "autoWidgetDisabled",
|
||||
MaxCount: 1,
|
||||
Name: "Auto Widget disabled",
|
||||
ReadOnly: false,
|
||||
ReadOnlyRelation: true,
|
||||
|
|
|
@ -1521,7 +1521,7 @@
|
|||
"format": "checkbox",
|
||||
"hidden": true,
|
||||
"key": "autoWidgetDisabled",
|
||||
"maxCount": 0,
|
||||
"maxCount": 1,
|
||||
"name": "Auto Widget disabled",
|
||||
"readonly": false,
|
||||
"source": "details"
|
||||
|
|
|
@ -259,7 +259,7 @@ func (b *builtinObjects) importArchive(
|
|||
importRequest := &importer.ImportRequest{
|
||||
RpcObjectImportRequest: &pb.RpcObjectImportRequest{
|
||||
SpaceId: spaceID,
|
||||
UpdateExistingObjects: false,
|
||||
UpdateExistingObjects: true,
|
||||
Type: model.Import_Pb,
|
||||
Mode: pb.RpcObjectImportRequest_ALL_OR_NOTHING,
|
||||
NoProgress: progress == nil,
|
||||
|
@ -392,7 +392,7 @@ func (b *builtinObjects) createWidgets(ctx session.Context, spaceId string, useC
|
|||
log.Errorf("failed to get type id: %w", err)
|
||||
return
|
||||
}
|
||||
for _, typeId := range []string{pageTypeId, taskTypeId} {
|
||||
for _, typeId := range []string{taskTypeId, pageTypeId} {
|
||||
if has, err := b.typeHasObjects(spaceId, typeId); err != nil {
|
||||
log.Warnf("failed to check if type '%s' has objects: %v", pageTypeId, err)
|
||||
} else if has {
|
||||
|
@ -400,10 +400,36 @@ func (b *builtinObjects) createWidgets(ctx session.Context, spaceId string, useC
|
|||
}
|
||||
}
|
||||
|
||||
var welcomePageId string
|
||||
if useCase == pb.RpcObjectImportUseCaseRequest_GET_STARTED {
|
||||
welcomePageId, err = b.getNewObjectID(spaceId, "bafyreidbxbw522cupdbxgzdpqayqb33ttvhyhlquprnbcgvpfp2p7pd4tq")
|
||||
if err != nil {
|
||||
log.Errorf("failed to get welcome page: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(widgetTargetsToCreate) == 0 {
|
||||
return
|
||||
}
|
||||
if err = cache.DoStateCtx(b.objectGetter, ctx, widgetObjectID, func(s *state.State, w widget.Widget) error {
|
||||
|
||||
if useCase == pb.RpcObjectImportUseCaseRequest_GET_STARTED && welcomePageId != "" {
|
||||
if _, err = w.CreateBlock(s, &pb.RpcBlockCreateWidgetRequest{
|
||||
ContextId: s.RootId(),
|
||||
WidgetLayout: model.BlockContentWidget_Link,
|
||||
Position: model.Block_InnerFirst,
|
||||
TargetId: s.RootId(),
|
||||
Block: &model.Block{
|
||||
Id: "welcome",
|
||||
Content: &model.BlockContentOfLink{Link: &model.BlockContentLink{
|
||||
TargetBlockId: welcomePageId,
|
||||
}},
|
||||
},
|
||||
}); err != nil {
|
||||
log.Errorf("failed to add welcome page widget: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, targetId := range widgetTargetsToCreate {
|
||||
if err := w.AddAutoWidget(s, targetId, "", addr.ObjectTypeAllViewId, model.BlockContentWidget_View, ""); err != nil {
|
||||
log.Errorf("failed to create widget block for type '%s': %v", targetId, err)
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue