Extract getTimeline into PeerHandler

This commit is contained in:
Sarah Jamie Lewis 2021-07-07 08:23:00 -07:00
parent db1f31fa71
commit bf193e6542
2 changed files with 15 additions and 5 deletions

6
lib.go
View File

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

View File

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