diff --git a/lib.go b/lib.go index 421bdb9..744db47 100644 --- a/lib.go +++ b/lib.go @@ -566,11 +566,7 @@ func GetMessagesByContentHash(profileOnion, handle string, contentHash string) s profile := application.GetPeer(profileOnion) ph := utils.NewPeerHelper(profile) var err error - if ph.IsGroup(handle) { - indexedMessages,err = profile.GetGroup(handle).Timeline.GetMessagesByHash(contentHash) - } else { - indexedMessages,err = profile.GetContact(handle).Timeline.GetMessagesByHash(contentHash) - } + indexedMessages, err = ph.GetTimeline(handle).GetMessagesByHash(contentHash) if err != nil { indexedMessages = []model.LocallyIndexedMessage{} } diff --git a/utils/manager.go b/utils/manager.go index 8e13ef1..c704596 100644 --- a/utils/manager.go +++ b/utils/manager.go @@ -36,6 +36,20 @@ func (p *PeerHelper) IsServer(id string) bool { return ok } +// GetTimeline returns a pointer to the timeline associated with the conversation handle +func (p *PeerHelper) GetTimeline(handle string) *model.Timeline { + if p.IsServer(handle) { + // This should *never* happen + log.Errorf("server accessed as contact when getting timeline...") + return &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 + } + return &p.peer.GetContact(handle).Timeline +} + /* func getOrDefault(id, key string, defaultVal string) string { var val string