BugFix: Crash when sending a message to a Peer who is not a Contact #382
|
@ -28,7 +28,6 @@ type Timeline struct {
|
||||||
hashCache map[string][]int
|
hashCache map[string][]int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// LocallyIndexedMessage is a type wrapper around a Message and a TimeLine Index that is local to this
|
// LocallyIndexedMessage is a type wrapper around a Message and a TimeLine Index that is local to this
|
||||||
// instance of the timeline.
|
// instance of the timeline.
|
||||||
type LocallyIndexedMessage struct {
|
type LocallyIndexedMessage struct {
|
||||||
|
@ -112,7 +111,7 @@ func (t *Timeline) GetMessagesByHash(contentHash string) ([]LocallyIndexedMessag
|
||||||
t.init()
|
t.init()
|
||||||
if idxs, exists := t.hashCache[contentHash]; exists {
|
if idxs, exists := t.hashCache[contentHash]; exists {
|
||||||
var messages []LocallyIndexedMessage
|
var messages []LocallyIndexedMessage
|
||||||
for _,idx := range idxs {
|
for _, idx := range idxs {
|
||||||
messages = append(messages, LocallyIndexedMessage{LocalIndex: idx, Message: t.Messages[idx]})
|
messages = append(messages, LocallyIndexedMessage{LocalIndex: idx, Message: t.Messages[idx]})
|
||||||
}
|
}
|
||||||
return messages, nil
|
return messages, nil
|
||||||
|
|
|
@ -106,7 +106,7 @@ func TestTranscriptConsistency(t *testing.T) {
|
||||||
|
|
||||||
t.Logf("Looking up %v ", hash)
|
t.Logf("Looking up %v ", hash)
|
||||||
|
|
||||||
for key,msgs := range timeline.hashCache {
|
for key, msgs := range timeline.hashCache {
|
||||||
t.Logf("%v %v", key, msgs)
|
t.Logf("%v %v", key, msgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -524,16 +524,19 @@ func (cp *cwtchPeer) SendMessageToGroupTracked(groupid string, message string) (
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *cwtchPeer) SendMessageToPeer(onion string, message string) string {
|
func (cp *cwtchPeer) SendMessageToPeer(onion string, message string) string {
|
||||||
event := event.NewEvent(event.SendMessageToPeer, map[event.Field]string{event.RemotePeer: onion, event.Data: message})
|
|
||||||
|
|
||||||
cp.mutex.Lock()
|
cp.mutex.Lock()
|
||||||
contact, _ := cp.Profile.GetContact(onion)
|
defer cp.mutex.Unlock()
|
||||||
event.EventID = strconv.Itoa(contact.Timeline.Len())
|
event := event.NewEvent(event.SendMessageToPeer, map[event.Field]string{event.RemotePeer: onion, event.Data: message})
|
||||||
cp.Profile.AddSentMessageToContactTimeline(onion, message, time.Now(), event.EventID)
|
contact, exists := cp.Profile.GetContact(onion)
|
||||||
cp.mutex.Unlock()
|
|
||||||
|
|
||||||
|
// If the contact exists replace the event id wih the index of this message in the contacts timeline...
|
||||||
|
// Otherwise assume we don't log the message in the timeline...
|
||||||
|
if exists {
|
||||||
|
event.EventID = strconv.Itoa(contact.Timeline.Len())
|
||||||
|
cp.Profile.AddSentMessageToContactTimeline(onion, message, time.Now(), event.EventID)
|
||||||
|
}
|
||||||
|
// Regardless we publish the send message to peer event for the protocol engine to execute on...
|
||||||
cp.eventBus.Publish(event)
|
cp.eventBus.Publish(event)
|
||||||
|
|
||||||
return event.EventID
|
return event.EventID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue