diff --git a/cmd/eksterd/memory.go b/cmd/eksterd/memory.go index 9022d62..6a977ff 100644 --- a/cmd/eksterd/memory.go +++ b/cmd/eksterd/memory.go @@ -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 = µsub.Source{ + ID: header.URL, + URL: header.URL, + Name: header.Name, + Photo: header.Photo, + } + } else { + source = µsub.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) diff --git a/cmd/eksterd/micropub.go b/cmd/eksterd/micropub.go index a32c9cf..f73cb9e 100644 --- a/cmd/eksterd/micropub.go +++ b/cmd/eksterd/micropub.go @@ -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) diff --git a/pkg/microsub/protocol.go b/pkg/microsub/protocol.go index d03a5fb..d4024d9 100644 --- a/pkg/microsub/protocol.go +++ b/pkg/microsub/protocol.go @@ -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