Compare commits
3 Commits
master
...
publicname
Author | SHA1 | Date |
---|---|---|
Sarah Jamie Lewis | 8b01172eac | |
Sarah Jamie Lewis | 538c5e9acb | |
Sarah Jamie Lewis | db94a7d596 |
|
@ -372,3 +372,18 @@ const (
|
||||||
True = "true"
|
True = "true"
|
||||||
False = "false"
|
False = "false"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Define Default Attribute Keys
|
||||||
|
const (
|
||||||
|
SaveHistoryKey = "SavePeerHistory"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Define Default Attribute Values
|
||||||
|
const (
|
||||||
|
// Save History has 3 distinct states. By default we don't save history (DontSaveHistoryDefault), if the peer confirms this
|
||||||
|
// we change to DontSaveHistoryConfirmed, if they confirm they want to save then this becomes SaveHistoryConfirmed
|
||||||
|
// We use this distinction between default and confirmed to drive UI
|
||||||
|
DontSaveHistoryDefault = "DefaultDontSaveHistory"
|
||||||
|
SaveHistoryConfirmed = "SaveHistory"
|
||||||
|
DontSaveHistoryConfirmed = "DontSaveHistory"
|
||||||
|
)
|
||||||
|
|
|
@ -34,6 +34,7 @@ const (
|
||||||
// Separator for scope and the rest of path
|
// Separator for scope and the rest of path
|
||||||
const Separator = "."
|
const Separator = "."
|
||||||
|
|
||||||
|
|
||||||
// IntoScope converts a string to a Scope
|
// IntoScope converts a string to a Scope
|
||||||
func IntoScope(scope string) Scope {
|
func IntoScope(scope string) Scope {
|
||||||
switch scope {
|
switch scope {
|
||||||
|
@ -80,11 +81,19 @@ func (scope Scope) IsConversation() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLocalScope takes a path and attaches the local scope to it
|
// GetLocalScope takes a path and attaches the local scope to it
|
||||||
|
// Deprecated: Use ConstructScopedZonedPath
|
||||||
func GetLocalScope(path string) string {
|
func GetLocalScope(path string) string {
|
||||||
return string(LocalScope) + Separator + path
|
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
|
// GetPeerScope takes a path and attaches the peer scope to it
|
||||||
|
// Deprecated Use ConstructScopedZonedPath
|
||||||
func GetPeerScope(path string) string {
|
func GetPeerScope(path string) string {
|
||||||
return string(PeerScope) + Separator + path
|
return string(PeerScope) + Separator + path
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,19 +283,45 @@ func (cp *cwtchPeer) Init(eventBus event.Manager) {
|
||||||
// Upgrade the Cwtch Peer if necessary
|
// 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
|
// 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...
|
// rather than duplicating the logic to construct/reconstruct attributes in storage engine...
|
||||||
// TODO: Remove these checks after Cwtch ~1.5
|
// TODO: Remove these checks after Cwtch ~1.5 storage engine is implemented
|
||||||
// If local.profile.name does not exist then set it from deprecated GetAttribute
|
if _, exists := cp.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name); !exists {
|
||||||
if _, exists := cp.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name); !exists {
|
// If public.profile.name does not exist, and we have an existing public.name then:
|
||||||
if name, exists := cp.Profile.GetAttribute(attr.GetLocalScope(constants.Name)); exists {
|
// set public.profile.name from public.name
|
||||||
cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, name)
|
// set local.profile.name from public.name
|
||||||
} else if name, exists := cp.Profile.GetAttribute(constants.Name); exists {
|
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)
|
cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, name)
|
||||||
} else {
|
} else {
|
||||||
// Profile.Name is very deprecated at this point...
|
// Otherwise check if local.name exists and set it from that
|
||||||
cp.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Name, cp.Profile.Name)
|
// 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 local.profile.tag does not exist then set it from deprecated GetAttribute
|
||||||
if _, exists := cp.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag); !exists {
|
if _, exists := cp.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag); !exists {
|
||||||
if tag, exists := cp.Profile.GetAttribute(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)
|
val, exists := cp.GetScopedZonedAttribute(scope, zone, zpath)
|
||||||
|
|
||||||
// NOTE: Temporary Override because UI currently wipes names if it can't find them...
|
// 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 {
|
if !exists && zone == attr.UnknownZone && path == constants.Name {
|
||||||
val, exists = cp.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name)
|
val, exists = cp.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -419,24 +419,41 @@ func (ps *ProfileStoreV1) eventHandler() {
|
||||||
} else {
|
} else {
|
||||||
log.Errorf("error storing new group invite: %v (%v)", err, ev)
|
log.Errorf("error storing new group invite: %v (%v)", err, ev)
|
||||||
}
|
}
|
||||||
case event.SendMessageToPeer: // cache the message till an ack, then it's given to stream store.
|
|
||||||
// stream store doesn't support updates, so we don't want to commit it till ack'd
|
|
||||||
ps.profile.AddSentMessageToContactTimeline(ev.Data[event.RemotePeer], ev.Data[event.Data], time.Now(), ev.EventID)
|
|
||||||
case event.NewMessageFromPeer:
|
case event.NewMessageFromPeer:
|
||||||
ps.profile.AddMessageToContactTimeline(ev.Data[event.RemotePeer], ev.Data[event.Data], time.Now())
|
contact, exists := ps.profile.GetContact(ev.Data[event.RemotePeer])
|
||||||
ps.attemptSavePeerMessage(ev.Data[event.RemotePeer], ev.Data[event.Data], ev.Data[event.TimestampReceived], true)
|
if exists {
|
||||||
case event.PeerAcknowledgement:
|
val, ok := contact.GetAttribute(event.SaveHistoryKey)
|
||||||
onion := ev.Data[event.RemotePeer]
|
if !ok {
|
||||||
eventID := ev.Data[event.EventID]
|
contact.SetAttribute(event.SaveHistoryKey, event.DontSaveHistoryDefault)
|
||||||
contact, ok := ps.profile.Contacts[onion]
|
} else {
|
||||||
if ok {
|
switch val {
|
||||||
mIdx, ok := contact.UnacknowledgedMessages[eventID]
|
case event.SaveHistoryConfirmed:
|
||||||
if ok {
|
{
|
||||||
message := contact.Timeline.Messages[mIdx]
|
peerID := ev.Data[event.RemotePeer]
|
||||||
ps.attemptSavePeerMessage(onion, message.Message, message.Timestamp.Format(time.RFC3339Nano), false)
|
received, _ := time.Parse(time.RFC3339Nano, ev.Data[event.TimestampReceived])
|
||||||
|
message := model.Message{Received: received, Timestamp: received, Message: ev.Data[event.Data], PeerID: peerID, Signature: []byte{}, PreviousMessageSig: []byte{}}
|
||||||
|
ss, exists := ps.streamStores[peerID]
|
||||||
|
if exists {
|
||||||
|
ss.Write(message)
|
||||||
|
} else {
|
||||||
|
log.Errorf("error storing new peer message: %v stream store does not exist", ev)
|
||||||
|
ss := NewStreamStore(ps.directory, contact.LocalID, ps.key)
|
||||||
|
ps.streamStores[peerID] = ss
|
||||||
|
ss.Write(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case event.DontSaveHistoryDefault:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
case event.DontSaveHistoryConfirmed:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ps.save()
|
||||||
|
} else {
|
||||||
|
log.Errorf("error setting attribute on peer %v peer does not exist", ev)
|
||||||
}
|
}
|
||||||
ps.profile.AckSentMessageToPeer(ev.Data[event.RemotePeer], ev.Data[event.EventID])
|
|
||||||
case event.NewMessageFromGroup:
|
case event.NewMessageFromGroup:
|
||||||
groupid := ev.Data[event.GroupID]
|
groupid := ev.Data[event.GroupID]
|
||||||
received, _ := time.Parse(time.RFC3339Nano, ev.Data[event.TimestampReceived])
|
received, _ := time.Parse(time.RFC3339Nano, ev.Data[event.TimestampReceived])
|
||||||
|
|
Loading…
Reference in New Issue