Skip to content

Commit

Permalink
Merge pull request #1661 from anyproto/go-3941-filter-flow-links-by-s…
Browse files Browse the repository at this point in the history
…pace-id

GO-3941 Filter flow links by spaceId
  • Loading branch information
KirillSto authored Oct 10, 2024
2 parents 2a040a4 + 0d10d7f commit b2d64da
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions core/navigation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"context"
"fmt"

"github.com/anyproto/any-sync/app"

"github.com/anyproto/anytype-heart/core/block/object/idresolver"
"github.com/anyproto/anytype-heart/pb"
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
"github.com/anyproto/anytype-heart/pkg/lib/core/smartblock"
"github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore"
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
"github.com/anyproto/anytype-heart/space/spacecore/typeprovider"
"github.com/anyproto/anytype-heart/util/pbtypes"
)

func (mw *Middleware) NavigationListObjects(cctx context.Context, req *pb.RpcNavigationListObjectsRequest) *pb.RpcNavigationListObjectsResponse {
Expand All @@ -25,7 +25,7 @@ func (mw *Middleware) NavigationListObjects(cctx context.Context, req *pb.RpcNav
return response(pb.RpcNavigationListObjectsResponseError_UNKNOWN_ERROR, nil, fmt.Errorf("not implemented"))
}

func (mw *Middleware) NavigationGetObjectInfoWithLinks(cctx context.Context, req *pb.RpcNavigationGetObjectInfoWithLinksRequest) *pb.RpcNavigationGetObjectInfoWithLinksResponse {
func (mw *Middleware) NavigationGetObjectInfoWithLinks(_ context.Context, req *pb.RpcNavigationGetObjectInfoWithLinksRequest) *pb.RpcNavigationGetObjectInfoWithLinksResponse {
response := func(code pb.RpcNavigationGetObjectInfoWithLinksResponseErrorCode, object *model.ObjectInfoWithLinks, err error) *pb.RpcNavigationGetObjectInfoWithLinksResponse {
m := &pb.RpcNavigationGetObjectInfoWithLinksResponse{Error: &pb.RpcNavigationGetObjectInfoWithLinksResponseError{Code: code}, Object: object}
if err != nil {
Expand All @@ -40,28 +40,34 @@ func (mw *Middleware) NavigationGetObjectInfoWithLinks(cctx context.Context, req
}

resolver := getService[idresolver.Resolver](mw)
store := app.MustComponent[objectstore.ObjectStore](mw.applicationService.GetApp())
spaceID, err := resolver.ResolveSpaceID(req.ObjectId)
spaceId, err := resolver.ResolveSpaceID(req.ObjectId)
if err != nil {
return response(pb.RpcNavigationGetObjectInfoWithLinksResponseError_UNKNOWN_ERROR, nil, fmt.Errorf("resolve spaceID: %w", err))
return response(pb.RpcNavigationGetObjectInfoWithLinksResponseError_UNKNOWN_ERROR, nil, fmt.Errorf("resolve spaceId: %w", err))
}
page, err := store.SpaceIndex(spaceID).GetWithLinksInfoById(req.ObjectId)

store := getService[objectstore.ObjectStore](mw)
index := store.SpaceIndex(spaceId)
page, err := index.GetWithLinksInfoById(req.ObjectId)
if err != nil {
return response(pb.RpcNavigationGetObjectInfoWithLinksResponseError_UNKNOWN_ERROR, nil, err)
}

sbTypeProvider := getService[typeprovider.SmartBlockTypeProvider](mw)
filter := func(Objects []*model.ObjectInfo) []*model.ObjectInfo {
filter := func(objects []*model.ObjectInfo) []*model.ObjectInfo {
var filtered []*model.ObjectInfo
for _, obj := range Objects {
sbType, err := sbTypeProvider.Type(spaceID, obj.Id)
for _, obj := range objects {
sbType, err := sbTypeProvider.Type(spaceId, obj.Id)
if err != nil {
log.Error("get smartblock type: %v", err)
}
if sbType == smartblock.SmartBlockTypeArchive || sbType == smartblock.SmartBlockTypeFileObject || sbType == smartblock.SmartBlockTypeWidget {
continue
}

if pbtypes.GetString(obj.Details, bundle.RelationKeySpaceId.String()) != spaceId {
continue
}

filtered = append(filtered, obj)
}
return filtered
Expand Down

0 comments on commit b2d64da

Please sign in to comment.