From 72b547f6aa2b1ad4e1e52cafcf4cdabece26c9cb Mon Sep 17 00:00:00 2001 From: Alessio Date: Mon, 2 Sep 2024 16:25:54 -0700 Subject: [PATCH] Unread notifications count should be specific to a single user --- pkg/persistence/notification_queries.go | 4 ++-- pkg/persistence/notification_queries_test.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/persistence/notification_queries.go b/pkg/persistence/notification_queries.go index 2280104..554f86b 100644 --- a/pkg/persistence/notification_queries.go +++ b/pkg/persistence/notification_queries.go @@ -116,9 +116,9 @@ func (p Profile) CheckNotificationScrapesNeeded(trove TweetTrove) []Notification return ret } -func (p Profile) GetUnreadNotificationsCount(since_sort_index int64) int { +func (p Profile) GetUnreadNotificationsCount(u_id UserID, since_sort_index int64) int { var ret int - err := p.DB.Get(&ret, `select count(*) from notifications where sort_index > ?`, since_sort_index) + err := p.DB.Get(&ret, `select count(*) from notifications where sort_index > ? and user_id = ?`, since_sort_index, u_id) if err != nil { panic(err) } diff --git a/pkg/persistence/notification_queries_test.go b/pkg/persistence/notification_queries_test.go index 235a431..00e8f3a 100644 --- a/pkg/persistence/notification_queries_test.go +++ b/pkg/persistence/notification_queries_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/offline-twitter/twitter_offline_engine/pkg/persistence" + . "gitlab.com/offline-twitter/twitter_offline_engine/pkg/scraper" ) func TestSaveAndLoadNotification(t *testing.T) { @@ -32,6 +33,6 @@ func TestGetUnreadNotificationsCount(t *testing.T) { profile, err := persistence.LoadProfile("../../sample_data/profile") require.NoError(err) - unread_notifs_count := profile.GetUnreadNotificationsCount(1724372973735) + unread_notifs_count := profile.GetUnreadNotificationsCount(UserID(1488963321701171204), 1724372973735) assert.Equal(2, unread_notifs_count) }