From 27caf4d5554696bd18c10ff98b510f9815bdd97b Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 14 Feb 2017 12:29:48 +0000 Subject: [PATCH] mark announcments before user signs up as read --- .../Announcements/AnnouncementsHandler.coffee | 7 +++++- .../AnnouncementsHandlerTests.coffee | 23 +++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/services/web/app/coffee/Features/Announcements/AnnouncementsHandler.coffee b/services/web/app/coffee/Features/Announcements/AnnouncementsHandler.coffee index 9934a8bf69..96bb7568ee 100644 --- a/services/web/app/coffee/Features/Announcements/AnnouncementsHandler.coffee +++ b/services/web/app/coffee/Features/Announcements/AnnouncementsHandler.coffee @@ -19,6 +19,9 @@ module.exports = AnnouncementsHandler = if !user? and !user._id? return callback("user not supplied") + timestamp = user._id.toString().substring(0,8) + userSignupDate = new Date( parseInt( timestamp, 16 ) * 1000 ) + async.parallel { lastEvent: (cb)-> AnalyticsManager.getLastOccurance user._id, "announcement-alert-dismissed", cb @@ -48,7 +51,9 @@ module.exports = AnnouncementsHandler = announcement.id == lastSeenBlogId announcements = _.map announcements, (announcement, index)-> - if announcementIndex == -1 + if announcement.date < userSignupDate + read = true + else if announcementIndex == -1 read = false else if index >= announcementIndex read = true diff --git a/services/web/test/UnitTests/coffee/Announcement/AnnouncementsHandlerTests.coffee b/services/web/test/UnitTests/coffee/Announcement/AnnouncementsHandlerTests.coffee index daa0da0531..ece2ddac46 100644 --- a/services/web/test/UnitTests/coffee/Announcement/AnnouncementsHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Announcement/AnnouncementsHandlerTests.coffee @@ -11,7 +11,7 @@ describe 'AnnouncementsHandler', -> beforeEach -> @user = - _id:"some_id" + _id:"3c6afe000000000000000000" #2002-02-14T00:00:00.000Z email: "someone@gmail.com" @AnalyticsManager = getLastOccurance: sinon.stub() @@ -36,10 +36,10 @@ describe 'AnnouncementsHandler', -> id: '/2013/08/02/thesis-series-pt1' }, { date: new Date(1108369600000), - id: '/2011/08/04/somethingelse' + id: '/2005/08/04/somethingelse' }, { date: new Date(1208369600000), - id: '/2014/04/12/title-date-irrelivant' + id: '/2008/04/12/title-date-irrelivant' } ] @BlogHandler.getLatestAnnouncements.callsArgWith(0, null, @stubbedAnnouncements) @@ -64,7 +64,7 @@ describe 'AnnouncementsHandler', -> done() it "should return older ones marked as read as well", (done)-> - @AnalyticsManager.getLastOccurance.callsArgWith(2, null, {segmentation:{blogPostId:"/2014/04/12/title-date-irrelivant"}}) + @AnalyticsManager.getLastOccurance.callsArgWith(2, null, {segmentation:{blogPostId:"/2008/04/12/title-date-irrelivant"}}) @handler.getUnreadAnnouncements @user, (err, announcements)=> announcements[0].id.should.equal @stubbedAnnouncements[0].id announcements[0].read.should.equal false @@ -89,6 +89,21 @@ describe 'AnnouncementsHandler', -> announcements[3].read.should.equal true done() + it "should return posts older than signup date as read", (done)-> + @stubbedAnnouncements.push({ + date: new Date(978836800000), + id: '/2001/04/12/title-date-irrelivant' + }) + @AnalyticsManager.getLastOccurance.callsArgWith(2, null, []) + @handler.getUnreadAnnouncements @user, (err, announcements)=> + announcements[0].read.should.equal false + announcements[1].read.should.equal false + announcements[2].read.should.equal false + announcements[3].read.should.equal false + announcements[4].read.should.equal true + announcements[4].id.should.equal '/2001/04/12/title-date-irrelivant' + done() + describe "with custom domain announcements", -> beforeEach ->