diff --git a/model/sharing/files.go b/model/sharing/files.go index da6b3001a9e..33e49170f88 100644 --- a/model/sharing/files.go +++ b/model/sharing/files.go @@ -1404,7 +1404,10 @@ func fileToJSONDoc(file *vfs.FileDoc, instanceURL string) couchdb.JSONDoc { doc.M["restore_path"] = file.RestorePath } if len(file.Metadata) > 0 { - doc.M["metadata"] = file.Metadata.RemoveCertifiedMetadata() + meta := file.Metadata + meta = meta.RemoveCertifiedMetadata() + meta = meta.RemoveFavoriteMetadata() + doc.M["metadata"] = meta } fcm := file.CozyMetadata if fcm == nil { diff --git a/model/vfs/metadata.go b/model/vfs/metadata.go index b5c0ea8b8b9..9142a3c95eb 100644 --- a/model/vfs/metadata.go +++ b/model/vfs/metadata.go @@ -60,6 +60,23 @@ func MergeMetadata(doc *FileDoc, meta Metadata) { } } +// RemoveFavoriteMetadata returns a metadata map where the favorite key has been +// removed. It can be useful for sharing, as favorite metadata are only valid +// localy. +func (m Metadata) RemoveFavoriteMetadata() Metadata { + if len(m) == 0 { + return Metadata{} + } + result := make(Metadata, len(m)) + for k, v := range m { + if k == consts.FavoriteKey { + continue + } + result[k] = v + } + return result +} + // RemoveCertifiedMetadata returns a metadata map where the keys that are // certified have been removed. It can be useful for sharing, as certified // metadata are only valid localy. diff --git a/pkg/consts/file.go b/pkg/consts/file.go index e9a622949a6..4e309c080a9 100644 --- a/pkg/consts/file.go +++ b/pkg/consts/file.go @@ -35,6 +35,8 @@ const ( CarbonCopyKey = "carbonCopy" // ElectronicSafeKey is the metadata key for an electronic safe (certified) ElectronicSafeKey = "electronicSafe" + // FavoriteKey is the metadata key for a favorite. + FavoriteKey = "favorite" ) const (