Merge branch 'master' into publicname
continuous-integration/drone/push Build is pending Details

This commit is contained in:
Sarah Jamie Lewis 2021-10-26 14:44:05 -07:00
commit 8b01172eac
3 changed files with 48 additions and 15 deletions

View File

@ -372,3 +372,18 @@ const (
True = "true"
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"
)

View File

@ -34,6 +34,7 @@ const (
// Separator for scope and the rest of path
const Separator = "."
// IntoScope converts a string to a Scope
func IntoScope(scope string) Scope {
switch scope {

View File

@ -419,24 +419,41 @@ func (ps *ProfileStoreV1) eventHandler() {
} else {
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:
ps.profile.AddMessageToContactTimeline(ev.Data[event.RemotePeer], ev.Data[event.Data], time.Now())
ps.attemptSavePeerMessage(ev.Data[event.RemotePeer], ev.Data[event.Data], ev.Data[event.TimestampReceived], true)
case event.PeerAcknowledgement:
onion := ev.Data[event.RemotePeer]
eventID := ev.Data[event.EventID]
contact, ok := ps.profile.Contacts[onion]
if ok {
mIdx, ok := contact.UnacknowledgedMessages[eventID]
if ok {
message := contact.Timeline.Messages[mIdx]
ps.attemptSavePeerMessage(onion, message.Message, message.Timestamp.Format(time.RFC3339Nano), false)
contact, exists := ps.profile.GetContact(ev.Data[event.RemotePeer])
if exists {
val, ok := contact.GetAttribute(event.SaveHistoryKey)
if !ok {
contact.SetAttribute(event.SaveHistoryKey, event.DontSaveHistoryDefault)
} else {
switch val {
case event.SaveHistoryConfirmed:
{
peerID := ev.Data[event.RemotePeer]
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)
}
}
ps.profile.AckSentMessageToPeer(ev.Data[event.RemotePeer], ev.Data[event.EventID])
case event.DontSaveHistoryDefault:
{
}
case event.DontSaveHistoryConfirmed:
{
}
}
}
ps.save()
} else {
log.Errorf("error setting attribute on peer %v peer does not exist", ev)
}
case event.NewMessageFromGroup:
groupid := ev.Data[event.GroupID]
received, _ := time.Parse(time.RFC3339Nano, ev.Data[event.TimestampReceived])