Browse Source

Merge branch 'master' into publicname

publicname
Sarah Jamie Lewis 7 months ago
parent
commit
8b01172eac
  1. 15
      event/common.go
  2. 1
      model/attr/scope.go
  3. 47
      storage/v1/profile_store.go

15
event/common.go

@ -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"
)

1
model/attr/scope.go

@ -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 {

47
storage/v1/profile_store.go

@ -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)
}
}
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:
groupid := ev.Data[event.GroupID]
received, _ := time.Parse(time.RFC3339Nano, ev.Data[event.TimestampReceived])

Loading…
Cancel
Save