From af6076187ffbb4c3047ee2bde5eafa92d4f50717 Mon Sep 17 00:00:00 2001 From: Umputun Date: Sun, 27 Jan 2019 15:08:39 -0600 Subject: [PATCH] set rss descriptions matching rss type --- backend/app/rest/api/admin_test.go | 1 + backend/app/rest/api/rss.go | 17 ++++++++++++----- backend/app/rest/api/rss_test.go | 8 ++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/backend/app/rest/api/admin_test.go b/backend/app/rest/api/admin_test.go index ad9da54e..c0684ccc 100644 --- a/backend/app/rest/api/admin_test.go +++ b/backend/app/rest/api/admin_test.go @@ -75,6 +75,7 @@ func TestAdmin_Delete(t *testing.T) { assert.Equal(t, "", cr.Text) assert.True(t, cr.Deleted) + time.Sleep(100 * time.Millisecond) // check last comments updated res, code = get(t, ts.URL+"/api/v1/last/2?site=radio-t") assert.Equal(t, 200, code) diff --git a/backend/app/rest/api/rss.go b/backend/app/rest/api/rss.go index 4450cc32..c46d4c74 100644 --- a/backend/app/rest/api/rss.go +++ b/backend/app/rest/api/rss.go @@ -42,7 +42,7 @@ func (s *Rest) rssPostCommentsCtrl(w http.ResponseWriter, r *http.Request) { return nil, e } comments = s.adminService.alterComments(comments, r) - rss, e := s.toRssFeed(locator.URL, comments) + rss, e := s.toRssFeed(locator.URL, comments, "post comments for "+r.URL.Query().Get("url")) if e != nil { return nil, e } @@ -75,7 +75,7 @@ func (s *Rest) rssSiteCommentsCtrl(w http.ResponseWriter, r *http.Request) { } comments = s.adminService.alterComments(comments, r) - rss, e := s.toRssFeed(r.URL.Query().Get("site"), comments) + rss, e := s.toRssFeed(r.URL.Query().Get("site"), comments, "site comment for "+siteID) if e != nil { return nil, e } @@ -100,6 +100,7 @@ func (s *Rest) rssRepliesCtrl(w http.ResponseWriter, r *http.Request) { siteID := r.URL.Query().Get("site") log.Printf("[DEBUG] get rss replies to user %s for site %s", userID, siteID) + userName := "" key := cache.NewKey(siteID).ID(URLKey(r)).Scopes(siteID, lastCommentsScope) data, err := s.Cache.Get(key, func() (res []byte, e error) { comments, e := s.DataService.Last(siteID, maxLastCommentsReply) @@ -112,6 +113,9 @@ func (s *Rest) rssRepliesCtrl(w http.ResponseWriter, r *http.Request) { if len(replies) > maxRssItems || c.Timestamp.Add(maxReplyDuration).Before(time.Now()) { break } + if c.User.ID != userID { + userName = c.User.Name + } if c.ParentID != "" && !c.Deleted && c.User.ID != userID { // not interested in replies to yourself var pc store.Comment if pc, e = s.DataService.Get(c.Locator, c.ParentID); e != nil { @@ -123,7 +127,7 @@ func (s *Rest) rssRepliesCtrl(w http.ResponseWriter, r *http.Request) { } } - rss, e := s.toRssFeed(siteID, replies) + rss, e := s.toRssFeed(siteID, replies, "replies to "+userName) if e != nil { return nil, e } @@ -142,8 +146,11 @@ func (s *Rest) rssRepliesCtrl(w http.ResponseWriter, r *http.Request) { } } -func (s *Rest) toRssFeed(url string, comments []store.Comment) (string, error) { +func (s *Rest) toRssFeed(url string, comments []store.Comment, description string) (string, error) { + if description == "" { + description = "comment updates" + } lastCommentTS := time.Unix(0, 0) if len(comments) > 0 { lastCommentTS = comments[0].Timestamp @@ -152,7 +159,7 @@ func (s *Rest) toRssFeed(url string, comments []store.Comment) (string, error) { feed := &feeds.Feed{ Title: "Remark42 comments", Link: &feeds.Link{Href: url}, - Description: "comment updates", + Description: description, Created: lastCommentTS, } diff --git a/backend/app/rest/api/rss_test.go b/backend/app/rest/api/rss_test.go index 519a829c..8f324e51 100644 --- a/backend/app/rest/api/rss_test.go +++ b/backend/app/rest/api/rss_test.go @@ -38,7 +38,7 @@ func TestServer_RssPost(t *testing.T) { Remark42 comments https://radio-t.com/blah1 - comment updates + post comments for https://radio-t.com/blah1 %s developer one @@ -93,7 +93,7 @@ func TestServer_RssSite(t *testing.T) { Remark42 comments radio-t - comment updates + site comment for radio-t %s developer one @@ -156,7 +156,7 @@ func TestServer_RssWithReply(t *testing.T) { Remark42 comments https://radio-t.com/blah10 - comment updates + post comments for https://radio-t.com/blah10 %s developer one > developer one @@ -242,7 +242,7 @@ func TestServer_RssReplies(t *testing.T) { Remark42 comments radio-t - comment updates + replies to user2 %s user3 > user1