diff --git a/app/rest/api/rss.go b/app/rest/api/rss.go index f9439838..e7533b87 100644 --- a/app/rest/api/rss.go +++ b/app/rest/api/rss.go @@ -1,6 +1,7 @@ package api import ( + "fmt" "log" "net/http" "time" @@ -113,6 +114,15 @@ func (s *Rest) toRssFeed(url string, comments []store.Comment) (string, error) { Created: c.Timestamp, Author: &feeds.Author{Name: c.User.Name}, } + if c.ParentID != "" { + // add indication to parent comment + parentComment, err := s.DataService.Get(c.Locator, c.ParentID) + if err == nil { + f.Title = fmt.Sprintf("%s > %s", c.User.Name, parentComment.User.Name) + } else { + log.Printf("[WARN] failed to get info about parent comment, %s", err) + } + } feed.Items = append(feed.Items, &f) if i > maxRssItems { break diff --git a/app/rest/api/rss_test.go b/app/rest/api/rss_test.go index a3ff7c70..6adddd2a 100644 --- a/app/rest/api/rss_test.go +++ b/app/rest/api/rss_test.go @@ -100,6 +100,58 @@ func TestServer_RssSite(t *testing.T) { assert.Equal(t, expected, res) } +func TestServer_RssWithReply(t *testing.T) { + srv, ts := prep(t) + assert.NotNil(t, srv) + defer cleanup(ts) + + waitOnMinChange() + + pubDate := time.Now().Format(time.RFC1123Z) + + c1 := store.Comment{ + Text: "test 123", + Locator: store.Locator{URL: "https://radio-t.com/blah10", SiteID: "radio-t"}, + } + c2 := store.Comment{ + Text: "xyz test", + Locator: store.Locator{URL: "https://radio-t.com/blah10", SiteID: "radio-t"}, + } + id1 := addComment(t, c1, ts) + c2.ParentID = id1 + id2 := addComment(t, c2, ts) + + res, code := get(t, ts.URL+"/api/v1/rss/post?site=radio-t&url=https://radio-t.com/blah10") + assert.Equal(t, 200, code) + t.Log(res) + + expected := fmt.Sprintf(` + + Remark42 comments + https://radio-t.com/blah10 + comment updates + %s + + developer one > developer one + https://radio-t.com/blah10#remark42__comment-%s + <p>xyz test</p> + developer one + %s + + + developer one + https://radio-t.com/blah10#remark42__comment-%s + <p>test 123</p> + developer one + %s + + + `, pubDate, id2, pubDate, id1, pubDate) + + expected, res = cleanRssFormatting(expected, res) + assert.Equal(t, expected, res) +} + func waitOnMinChange() { if time.Now().Second() == 59 { time.Sleep(1001 * time.Millisecond)