Fill item source from FeadHeader
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Peter Stuifzand 2021-10-21 21:47:37 +02:00
parent c49afabaa8
commit 5eed538bd1
Signed by: peter
GPG Key ID: 374322D56E5209E8
3 changed files with 28 additions and 0 deletions

View File

@ -588,6 +588,22 @@ func (b *memoryBackend) Events() (chan sse.Message, error) {
func (b *memoryBackend) ProcessContent(channel, fetchURL, contentType string, body io.Reader) error {
cachingFetch := WithCaching(b.pool, Fetch2)
// When the source is available from the Header, we fill the Source of the item
var source *microsub.Source
if header, err := fetch.FeedHeader(cachingFetch, fetchURL, contentType, body); err == nil {
source = &microsub.Source{
ID: header.URL,
URL: header.URL,
Name: header.Name,
Photo: header.Photo,
}
} else {
source = &microsub.Source{
ID: fetchURL,
URL: fetchURL,
}
}
items, err := fetch.FeedItems(cachingFetch, fetchURL, contentType, body)
if err != nil {
return err
@ -595,6 +611,7 @@ func (b *memoryBackend) ProcessContent(channel, fetchURL, contentType string, bo
for _, item := range items {
item.Read = false
item.Source = source
err = b.channelAddItemWithMatcher(channel, item)
if err != nil {
log.Printf("ERROR: %s\n", err)

View File

@ -60,6 +60,7 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
// TODO: We could try to fill the Source of the Item with something, but what?
item, err := parseIncomingItem(r)
if err != nil {
http.Error(w, err.Error(), 400)
@ -78,6 +79,7 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Printf("could not add item to channel %s: %v", channel, err)
}
err = h.Backend.updateChannelUnreadCount(channel)
if err != nil {
log.Printf("could not update channel unread content %s: %v", channel, err)

View File

@ -82,6 +82,15 @@ type Item struct {
Refs map[string]Item `json:"refs,omitempty"`
ID string `json:"_id,omitempty"`
Read bool `json:"_is_read"`
Source *Source `json:"_source,omitempty"`
}
// Source is an Item source
type Source struct {
ID string `json:"_id"`
URL string `json:"url"`
Name string `json:"name"`
Photo string `json:"photo"`
}
// Pagination contains information about paging