Merge branch 'master' into publicname
continuous-integration/drone/push Build is pending
Details
continuous-integration/drone/push Build is pending
Details
This commit is contained in:
commit
8b01172eac
|
@ -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 {
|
||||||
|
|
|
@ -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