From e53d91b09eff74b1b97ef97a2f9ab7767f7e83d0 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 16 Sep 2021 13:27:12 -0700 Subject: [PATCH] Handle Contact not Found in GetTimeline --- lib.go | 9 ++++++--- utils/manager.go | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib.go b/lib.go index cd20494..eac8970 100644 --- a/lib.go +++ b/lib.go @@ -596,9 +596,12 @@ func GetMessagesByContentHash(profileOnion, handle string, contentHash string) s profile := application.GetPeer(profileOnion) ph := utils.NewPeerHelper(profile) var err error - indexedMessages, err = ph.GetTimeline(handle).GetMessagesByHash(contentHash) - if err != nil { - indexedMessages = []model.LocallyIndexedMessage{} + timeline := ph.GetTimeline(handle) + if timeline != nil { + indexedMessages, err = timeline.GetMessagesByHash(contentHash) + if err != nil { + indexedMessages = []model.LocallyIndexedMessage{} + } } } bytes, _ := json.Marshal(indexedMessages) diff --git a/utils/manager.go b/utils/manager.go index ea6528f..d4168b5 100644 --- a/utils/manager.go +++ b/utils/manager.go @@ -36,7 +36,8 @@ func (p *PeerHelper) IsServer(id string) bool { return ok } -// GetTimeline returns a pointer to the timeline associated with the conversation handle +// GetTimeline returns a pointer to the timeline associated with the conversation handle or nil if the handle +// does not exist (this can happen if the conversation has been deleted) func (p *PeerHelper) GetTimeline(handle string) *model.Timeline { if p.IsServer(handle) { // This should *never* happen @@ -45,9 +46,17 @@ func (p *PeerHelper) GetTimeline(handle string) *model.Timeline { } // We return a pointer to the timeline to avoid copying, accessing Timeline is thread-safe if p.IsGroup(handle) { - return &p.peer.GetGroup(handle).Timeline + group := p.peer.GetGroup(handle) + if group == nil { + return nil + } + return &group.Timeline } - return &p.peer.GetContact(handle).Timeline + contact := p.peer.GetContact(handle) + if contact == nil { + return nil + } + return &contact.Timeline } /*