forked from cwtch.im/libcwtch-go
Extract getTimeline into PeerHandler
This commit is contained in:
parent
db1f31fa71
commit
bf193e6542
6
lib.go
6
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{}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue