From 538c5e9acbd05f1cf6f84a913e640588dc00aa42 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 26 Oct 2021 14:35:48 -0700 Subject: [PATCH] Prefer public.profile.name Deprecate old Get*Scope methods --- model/attr/scope.go | 8 ++++++++ peer/cwtch_peer.go | 44 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/model/attr/scope.go b/model/attr/scope.go index 00c3ee0..5130ca9 100644 --- a/model/attr/scope.go +++ b/model/attr/scope.go @@ -80,11 +80,19 @@ func (scope Scope) IsConversation() bool { } // GetLocalScope takes a path and attaches the local scope to it +// Deprecated: Use ConstructScopedZonedPath func GetLocalScope(path string) string { return string(LocalScope) + Separator + path } +// GetPublicScope takes a path and attaches the public scope to it +// Deprecated Use ConstructScopedZonedPath +func GetPublicScope(path string) string { + return string(PublicScope) + Separator + path +} + // GetPeerScope takes a path and attaches the peer scope to it +// Deprecated Use ConstructScopedZonedPath func GetPeerScope(path string) string { return string(PeerScope) + Separator + path } diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index e3d9de5..b080943 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -283,19 +283,45 @@ func (cp *cwtchPeer) Init(eventBus event.Manager) { // Upgrade the Cwtch Peer if necessary // It would be nice to do these checks in the storage engine itself, but it is easier to do them here // rather than duplicating the logic to construct/reconstruct attributes in storage engine... - // TODO: Remove these checks after Cwtch ~1.5 - // If local.profile.name does not exist then set it from deprecated GetAttribute - if _, exists := cp.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name); !exists { - if name, exists := cp.Profile.GetAttribute(attr.GetLocalScope(constants.Name)); exists { - cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, name) - } else if name, exists := cp.Profile.GetAttribute(constants.Name); exists { + // TODO: Remove these checks after Cwtch ~1.5 storage engine is implemented + if _, exists := cp.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name); !exists { + // If public.profile.name does not exist, and we have an existing public.name then: + // set public.profile.name from public.name + // set local.profile.name from public.name + if name, exists := cp.Profile.GetAttribute(attr.GetPublicScope(constants.Name)); exists { + cp.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, name) cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, name) } else { - // Profile.Name is very deprecated at this point... - cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, cp.Profile.Name) + // Otherwise check if local.name exists and set it from that + // If not, then check the very old unzoned, unscoped name. + // If not, then set directly from Profile.Name... + if name, exists := cp.Profile.GetAttribute(attr.GetLocalScope(constants.Name)); exists { + cp.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, name) + cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, name) + } else if name, exists := cp.Profile.GetAttribute(constants.Name); exists { + cp.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, name) + cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, name) + } else { + // Profile.Name is very deprecated at this point... + cp.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, cp.Profile.Name) + cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, cp.Profile.Name) + } } } + // At this point we can safely assume that public.profile.name exists + localName, _ := cp.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) + publicName, _ := cp.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + + if localName != publicName { + cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, publicName) + } + + // At this point we can safely assume that public.profile.name exists AND is consistent with + // local.profile.name - regardless of whatever Cwtch version we have upgraded from. This will + // be important after Cwtch 1.5 when we purge all previous references to local.profile.name and + // profile-> name - and remove all name processing code from libcwtch-go. + // If local.profile.tag does not exist then set it from deprecated GetAttribute if _, exists := cp.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag); !exists { if tag, exists := cp.Profile.GetAttribute(constants.Tag); exists { @@ -857,6 +883,8 @@ func (cp *cwtchPeer) eventHandler() { val, exists := cp.GetScopedZonedAttribute(scope, zone, zpath) // NOTE: Temporary Override because UI currently wipes names if it can't find them... + // And older Cwtch clients will attempt to fetch public.name without the correct profile + // zone. if !exists && zone == attr.UnknownZone && path == constants.Name { val, exists = cp.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) }